[wp-trac] [WordPress Trac] #11292: get_page_by_path() recursively makes unnecessary database calls for a hierarchical structure
WordPress Trac
wp-trac at lists.automattic.com
Tue Dec 1 04:27:19 UTC 2009
#11292: get_page_by_path() recursively makes unnecessary database calls for a
hierarchical structure
-------------------------+--------------------------------------------------
Reporter: aheadzen | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Unassigned
Component: Performance | Version: 2.8.5
Severity: normal | Keywords: database, page, performance
-------------------------+--------------------------------------------------
I'm using WordPress as a CMS for around 600 static pages websites.
Please note - All plugins are disabled and using simple html for
templates. So no plugin or theme problem.
Website page structure is like this -
/first/second/cancer/
/first/third/cancer/
/first/fourth/cancer/
.........
........
........
/newfirst/cancer/
For such structure, get_page_by_path() recursively checks for page's
parent and makes too many unnecessary database calls. More than 35 to be
precise. I have checked through php xdebug and WP-Tune plugin and here's a
sample query set -
{{{
5 13.367 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 139 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
7 2.137 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 11 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
28 1.509 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 442 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
16 1.498 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 3727 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
6 1.417 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 125 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
29 1.390 SELECT * FROM ask_posts WHERE ID = 450 LIMIT 1
[wp-includes\post.php(227): wpdb->get_row()]
18 1.265 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 3701 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
22 1.228 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 369 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
24 1.140 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 370 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
10 1.050 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 125 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
20 1.009 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 3753 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
9 0.952 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 140 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
12 0.947 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 126 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
30 0.947 SELECT `post_parent` FROM ask_posts WHERE ID = 442 LIMIT 1
[wp-includes\post.php(3392): wpdb->get_var()]
34 0.923 SELECT * FROM ask_posts WHERE ID = 442 LIMIT 1
[wp-includes\post.php(227): wpdb->get_row()]
26 0.855 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 371 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
27 0.778 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 125 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
23 0.584 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 125 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
17 0.556 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 125 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
32 0.556 SELECT `post_parent` FROM ask_posts WHERE ID = 442 LIMIT 1
[wp-includes\post.php(3392): wpdb->get_var()]
25 0.539 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 125 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
21 0.505 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 125 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
15 0.484 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 125 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
11 0.481 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 125 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
8 0.476 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 125 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
13 0.475 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 125 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
19 0.474 SELECT ID, post_name, post_parent FROM ask_posts WHERE ID
= 125 and post_type='page'
[wp-includes\post.php(2107): wpdb->get_row()]
}}}
So when wordpress makes this DB call -
{{{
SELECT ID, post_name, post_parent
FROM ask_posts
WHERE post_name = 'cancer'
AND (
post_type = 'page'
OR post_type = 'attachment'
)
LIMIT 0 , 30
}}}
I get a result like this -
{{{
ID post_name post_parent
18 cancer 0
40 cancer 139
41 cancer 11
42 cancer 140
253 cancer 125
129 cancer 126
282 cancer 3779
295 cancer 3727
303 cancer 3701
315 cancer 3753
326 cancer 369
335 cancer 370
344 cancer 371
450 cancer 442
}}}
And then get_page_by_path() makes calls for each and every post_parent.
That's okay but why repeat same calls again and again. One heavily
repeated query is this -
{{{
SELECT ID, post_name, post_parent FROM ask_posts WHERE ID = 125 and
post_type='page'
}}}
I hope resolution of this bug will make WordPress more efficient.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/11292>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list