[wp-trac] [WordPress Trac] #6748: wp_list_pages can cause huge numbers of SQL queries

WordPress Trac wp-trac at lists.automattic.com
Wed Apr 16 14:34:13 GMT 2008


#6748: wp_list_pages can cause huge numbers of SQL queries
-----------------------------+----------------------------------------------
 Reporter:  Otto42           |       Owner:  anonymous
     Type:  defect           |      Status:  new      
 Priority:  highest omg bbq  |   Milestone:  2.5.1    
Component:  Optimization     |     Version:  2.5      
 Severity:  critical         |    Keywords:           
-----------------------------+----------------------------------------------
 Report here:
 http://wordpress.org/support/topic/167000?replies=18#post-732526

 Summary: wp_list_pages makes use of the Walker_Page class. Walker_Page
 calls get_page() which calls get_post() which calls _get_post_ancestors()
 which is not cached.

 On a large set of pages, the _get_post_ancestors() function being called
 this often can result in a huge amount of queries to the database, all
 taking this form:
 SELECT post_parent FROM wp_posts WHERE ID= 'page_id' LIMIT 1

 When you have nested pages in a large hierarchy, this rapidly grows
 obscene in terms of the number of queries performed, since it must execute
 one query to track each page back to the root of the hierarchy.

 Example:
 /pageroot/
 /pageroot/1/
 /pageroot/1/2/
 /pageroot/1/3/
 /pageroot/1/4/

 Doing a wp_list_pages on the above set of pages results in 12 separate
 queries to the database, just to get post_parents. Adding just one more
 subpage, like /pageroot/1/2/5/ will add 4 more queries.

 Problems reported in the support forum have gotten up to 2000+ queries
 from one call to wp_list_pages.

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


More information about the wp-trac mailing list