Select Page

Understanding what WordPress is doing under the hood can be tough – especially when it comes to the raw SQL queries.  As is usually typical with WordPress, somebody has written a plugin for it – in this case, it is called debug-bar.  To get it going, do the following:

  1. Download and install the plugin from here: http://wordpress.org/plugins/debug-bar/.
  2. Go into your wp-config file and add this line: define(‘SAVEQUERIES’, true);
  3. Ensure that you admin bar is displaying (be logged in as an Administrator) and refresh the site page that you want metrics.
  4. Click on the new “Debug” option on the right-side of the admin bar.  Voila!

In my case, I wanted a baseline, so I ran it on a barebones theme – no plugins (other than debug-bar), no templates (other than header, index, and footer), and no custom function code.  Here is what I got – the formatting looks different than what you get in debug-bar, but the data is still there:

 

Total Queries:9

Total query time:23.8 ms

 

  1. SELECT option_name, option_value FROM wp_options WHERE autoload = ‘yes’
    require(‘D:\wamp\www\8bitcool\wp-blog-header.php’), require_once(‘D:\wamp\www\8bitcool\wp-load.php’), require_once(‘D:\wamp\www\8bitcool\wp-config.php’), require_once(‘D:\wamp\www\8bitcool\wp-settings.php’), wp_not_installed, is_blog_installed, wp_load_alloptions #1 (2.6ms)
  2. SELECT * FROM wp_users WHERE user_login = ‘suleski’
    require(‘D:\wamp\www\8bitcool\wp-blog-header.php’), require_once(‘D:\wamp\www\8bitcool\wp-load.php’), require_once(‘D:\wamp\www\8bitcool\wp-config.php’), require_once(‘D:\wamp\www\8bitcool\wp-settings.php’), WP->init, wp_get_current_user, get_currentuserinfo, wp_validate_auth_cookie, get_user_by, WP_User::get_data_by #2 (0.5ms)
  3. SELECT user_id, meta_key, meta_value FROM wp_usermeta WHERE user_id IN (1) ORDER BY umeta_id ASC
    require(‘D:\wamp\www\8bitcool\wp-blog-header.php’), require_once(‘D:\wamp\www\8bitcool\wp-load.php’), require_once(‘D:\wamp\www\8bitcool\wp-config.php’), require_once(‘D:\wamp\www\8bitcool\wp-settings.php’), WP->init, wp_get_current_user, get_currentuserinfo, wp_validate_auth_cookie, get_user_by, WP_User->init, WP_User->for_blog, WP_User->_init_caps, get_user_meta, get_metadata, update_meta_cache #3 (9.5ms)
  4. SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = ‘post’ AND (wp_posts.post_status = ‘publish’ OR wp_posts.post_status = ‘private’) ORDER BY wp_posts.post_date DESC LIMIT 0, 10
    require(‘D:\wamp\www\8bitcool\wp-blog-header.php’), wp, WP->main, WP->query_posts, WP_Query->query, WP_Query->get_posts #4 (0.7ms)
  5. SELECT FOUND_ROWS()
    require(‘D:\wamp\www\8bitcool\wp-blog-header.php’), wp, WP->main, WP->query_posts, WP_Query->query, WP_Query->get_posts, WP_Query->set_found_posts #5 (0.1ms)
  6. SELECT wp_posts.* FROM wp_posts WHERE ID IN (5191,1220,807)
    require(‘D:\wamp\www\8bitcool\wp-blog-header.php’), wp, WP->main, WP->query_posts, WP_Query->query, WP_Query->get_posts, _prime_post_caches #6 (0.5ms)
  7. SELECT t.*, tt.*, tr.object_id FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN (‘category’, ‘post_tag’, ‘post_format’) AND tr.object_id IN (807, 1220, 5191) ORDER BY t.name ASC
    require(‘D:\wamp\www\8bitcool\wp-blog-header.php’), wp, WP->main, WP->query_posts, WP_Query->query, WP_Query->get_posts, _prime_post_caches, update_post_caches, update_object_term_cache, wp_get_object_terms #7 (8.0ms)
  8. SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN (807,1220,5191) ORDER BY meta_id ASC
    require(‘D:\wamp\www\8bitcool\wp-blog-header.php’), wp, WP->main, WP->query_posts, WP_Query->query, WP_Query->get_posts, _prime_post_caches, update_post_caches, update_postmeta_cache, update_meta_cache #8 (1.4ms)
  9. SELECT comment_approved, COUNT( * ) AS num_comments FROM wp_comments GROUP BY comment_approved
    require(‘D:\wamp\www\8bitcool\wp-blog-header.php’), require_once(‘D:\wamp\www\8bitcool\wp-includes\template-loader.php’), include(‘D:\wamp\www\8bitcool\wp-content\themes\eightbit\index.php’), get_footer, locate_template, load_template, require_once(‘D:\wamp\www\8bitcool\wp-content\themes\eightbit\footer.php’), wp_footer, do_action(‘wp_footer’), call_user_func_array, wp_admin_bar_render, do_action_ref_array, call_user_func_array, wp_admin_bar_comments_menu, wp_count_comments #9 (0.4ms)