Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#6748 closed defect (bug) (duplicate)

wp_list_pages can cause huge numbers of SQL queries

Reported by: Otto42 Owned by:
Milestone: Priority: highest omg bbq
Severity: critical Version: 2.5
Component: Optimization Keywords:
Focuses: Cc:


Report here:

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.


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.

Change History (1)

#1 @ionfish
8 years ago

  • Milestone 2.5.1 deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #6702.

Note: See TracTickets for help on using tickets.