Designer? Programmer? Enthusiast? Join Open Designs Now!

Open Designs Forum » Water Cooler

CMS: Number of MySQL Queries: How many is too much?

(7 posts)
  • Started 2 years ago by uberlemurguy
  • Latest reply from fernbap
  1. uberlemurguy
    Moderator

    I am actively working on my CMS and I am optimizing the number of queries from the database. When the page is viewed, six mysql select queries are run. Is that too much?

    Posted 2 years ago #
  2. Sean
    Founding Member

    I don't think 6 queries are too much. Obviously you want the queries low, so if your CMS will only do the 6, you're doing pretty good I would say. Just my two cents.

    Posted 2 years ago #
  3. uberlemurguy
    Moderator

    Okay good to know. If anyone cares here is my query list:

    Ran Query #1 (Line 70 of core.functions.class.php) (Time 0.0007): SELECT * FROM asdf_settings_site
    Ran Query #2 (Line 18 of core.theme.manger.class.php) (Time 0.0004): SELECT * FROM asdf_content_template WHERE template = 'Contaiminated' ORDER by id
    Ran Query #3 (Line 32 of core.functions.class.php) (Time 0.0004): SELECT * FROM asdf_plugins
    Ran Query #4 (Line 67 of core.init.class.php) (Time 0.0004): SELECT * FROM asdf_content_pages WHERE id ='1'
    Ran Query #5 (Line 40 of core.theme.manger.class.php) (Time 0.0011): SELECT parent_id, menutitle, id FROM asdf_content_pages WHERE NOT secondary = 'yes' ORDER by orderingid
    Ran Query #6 (Line 66 of core.theme.manger.class.php) (Time 0.0009): SELECT parent_id, menutitle, id FROM asdf_content_pages WHERE secondary = 'yes' ORDER by orderingid
    Posted 2 years ago #
  4. greg
    Member

    you should be able to merge query #5 and #6 if you really want to keep queries as low as possible.

    Posted 2 years ago #
  5. Rob
    Member

    What are you using to report back on those? I always have my own query function and build up an array of the queries through that and then echo it at the end, but i've never gone to the effort of adding line numbers etc to it.

    Posted 2 years ago #
  6. uberlemurguy
    Moderator

    The function I use just appends a string to a global:

    public function db_query($sql) {
    		$queryStart = round(microtime(), 4);
    
    		$result = mysql_query($sql);
    
    		$GLOBALS['MYSQL_NUM_QUERIES']++;
    
    		$queryEnd = round(microtime(), 4);
    
    		$queryTime = $queryEnd - $queryStart;		
    
    		$GLOBALS['MYSQL_QUERY_TIME'] += $queryTime;
    
    		$call_info = array_shift( debug_backtrace() );
    		$code_line = $call_info['line'];
    		$file = array_pop( explode('/', $call_info['file']));
    		$GLOBALS['mysql_debug'] .= '<strong>Ran Query #'.$GLOBALS['MYSQL_NUM_QUERIES'].&quot; (Line $code_line of &quot;.basename($file).&quot;) (Time $queryTime): </strong>$sql<br />&quot;;
    
    		return $result;
    	}

    Any better suggestions on how to do this?

    Posted 2 years ago #
  7. fernbap
    Member

    A sugestion:

    Forget about all your mysql stats, it will only waste time. ;)
    If you are debugging, THEN insert the lines used for debugging. Why would the normal script include them?

    Posted 2 years ago #

RSS feed for this topic

Reply

You must log in to post.