[wp-trac] [WordPress Trac] #15396: Queries not being cached

WordPress Trac wp-trac at lists.automattic.com
Thu Nov 11 23:13:08 UTC 2010


#15396: Queries not being cached
--------------------------+-------------------------------------------------
 Reporter:  sivel         |       Owner:     
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  3.1
Component:  Cache         |     Version:  3.1
 Severity:  normal        |    Keywords:     
--------------------------+-------------------------------------------------
 I was recently playing with porting over an object cache to XCache, and
 after finishing the code I decided to log all mysql queries to check that
 it was working properly.  What I found was a number of queries including
 post-tag and post-format queries that were being fired and not cached.

 I have since tried Mark Jaquith's APC and Ryan Boren's Memcached object
 caches, as well as getting a list of queries run with an object cache not
 enabled.

 I briefly talked to Nacin who looked at the list of queries running with
 the object cache enabled, who said they shouldn't be running, and that
 there must be something broken in trunk.

 The set up is a brand new trunk install, without plugins, modifications of
 any type and running twenty ten.

 Here is the list of queries that are running without the object cache:

 {{{
 80 Query        SELECT option_name, option_value FROM wp_options WHERE
 autoload = 'yes'
 80 Query        SELECT option_value FROM wp_options WHERE option_name =
 'rewrite_rules' LIMIT 1
 80 Query        SELECT SQL_CALC_FOUND_ROWS  wp_posts.* FROM wp_posts
 WHERE 1=1  AND wp_posts.post_type = 'post' AND (wp_posts.post_status =
 'publish')  ORDER BY wp_posts.post_date DESC LIMIT 0, 10
 80 Query        SELECT FOUND_ROWS()
 80 Query        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 (1) ORDER BY t.name ASC
 80 Query        SELECT post_id, meta_key, meta_value FROM wp_postmeta
 WHERE post_id IN (1)
 80 Query        SELECT option_value FROM wp_options WHERE option_name =
 'theme_mods_twentyten' LIMIT 1
 80 Query        SELECT option_value FROM wp_options WHERE option_name =
 'mods_Twenty Ten' LIMIT 1
 80 Query        SELECT * FROM wp_posts  WHERE (post_type = 'page' AND
 post_status = 'publish')     ORDER BY menu_order, post_title ASC
 80 Query        SELECT * FROM wp_users WHERE ID = 1 LIMIT 1
 80 Query        SELECT user_id, meta_key, meta_value FROM wp_usermeta
 WHERE user_id IN (1)
 80 Query        SELECT t.name 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 ('post_format') AND tr.object_id IN (1)
 80 Query        SELECT t.name 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 ('post_format') AND tr.object_id IN (1)
 80 Query        SELECT t.name 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 ('post_format') AND tr.object_id IN (1)
 80 Query        SELECT SQL_CALC_FOUND_ROWS  wp_posts.* FROM wp_posts
 WHERE 1=1  AND wp_posts.post_type = 'post' AND (wp_posts.post_status =
 'publish')  ORDER BY wp_posts.post_date DESC LIMIT 0, 5
 80 Query        SELECT FOUND_ROWS()
 80 Query        SELECT * FROM wp_comments  WHERE comment_approved = '1'
 ORDER BY comment_date_gmt DESC LIMIT 5
 80 Query        SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS
 `month`, count(ID) as posts FROM wp_posts  WHERE post_type = 'post' AND
 post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER
 BY post_date DESC
 80 Query        SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN
 wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN
 ('category') AND tt.count > 0 ORDER BY t.name ASC
 }}}

 Here is a list of queries that continue to run with the object cache
 enabled:

 {{{
 81 Query        SELECT SQL_CALC_FOUND_ROWS  wp_posts.* FROM wp_posts
 WHERE 1=1  AND wp_posts.post_type = 'post' AND (wp_posts.post_status =
 'publish')  ORDER BY wp_posts.post_date DESC LIMIT 0, 10
 81 Query        SELECT FOUND_ROWS()
 81 Query        SELECT t.name 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 ('post_format') AND tr.object_id IN (1)
 81 Query        SELECT t.name 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 ('post_format') AND tr.object_id IN (1)
 81 Query        SELECT t.name 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 ('post_format') AND tr.object_id IN (1)
 81 Query        SELECT t.*, tt.* 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 ('post_tag') AND tr.object_id IN (1) ORDER BY t.name
 ASC
 81 Query        SELECT t.*, tt.* 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 ('post_tag') AND tr.object_id IN (1) ORDER BY t.name
 ASC
 }}}

 I haven't had the time to test on 3.0.1 and not sure if that is really
 even needed.  If it is let me know and I can run these tests there as
 well.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/15396>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list