[wp-trac] [WordPress Trac] #10964: Improving query_posts performance

WordPress Trac wp-trac at lists.automattic.com
Fri Oct 16 16:45:42 UTC 2009


#10964: Improving query_posts performance
-------------------------+--------------------------------------------------
 Reporter:  buch0090     |       Owner:                          
     Type:  enhancement  |      Status:  new                     
 Priority:  normal       |   Milestone:  2.9                     
Component:  Performance  |     Version:  2.8.4                   
 Severity:  normal       |    Keywords:  query_posts, performance
-------------------------+--------------------------------------------------

Comment(by buch0090):

 Ryan,
 My bad, it does break the part for displaying the page links...IE. 1 2 3
 ...100 101. I will look into this, perhaps it was premature for me to post
 this, was just excited to contribute, thanks.

 Scribu,
 The main reason is eliminating the giant table scans where it returns all
 fields in posts table for all rows.

 SELECT SQL_CALC_FOUND_ROWS wp_1_posts.* FROM wp_1_posts WHERE 1=1 AND
 wp_1_posts.post_type = 'post' AND (wp_1_posts.post_status = 'publish')
 ORDER BY wp_1_posts.post_date DESC LIMIT 0, 10;

 Becomes...

 SELECT SQL_CALC_FOUND_ROWS wp_1_posts.ID FROM wp_1_posts WHERE 1=1 AND
 wp_1_posts.post_type = 'post' AND (wp_1_posts.post_status = 'publish')
 ORDER BY wp_1_posts.post_date DESC LIMIT 0, 10;

 then..

 SELECT SQL_CALC_FOUND_ROWS wp_1_posts.* FROM wp_1_posts WHERE
 wp_1_posts.id IN ( [LIST OF IDS FROM PREV QUERY]) ORDER BY
 wp_1_posts.post_date DESC LIMIT 0, 10;

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/10964#comment:4>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list