Opened 17 years ago
Closed 16 years ago
#6702 closed defect (bug) (fixed)
Raise in the Wordpress number of queries in nested pages
Reported by: | tiosolid | Owned by: | ryan |
---|---|---|---|
Milestone: | 2.6 | Priority: | high |
Severity: | major | Version: | 2.5 |
Component: | Optimization | Keywords: | has-patch needs-testing |
Focuses: | Cc: |
Description
Hi, a lot of people are complaining in the forums that since they updated from Wordpress 2.3.1 to 2.5 they pages started to use a huge ammount of queries and cpu time to be shown. This problems is happening mainly with nested pages (at least for me).
While using the debug-queries plugin, I get the following report:
4.29153442383E-05 SELECT post_parent FROM wp_posts WHERE ID= '286' LIMIT 1
4.19616699219E-05 SELECT post_parent FROM wp_posts WHERE ID= '286' LIMIT 1
4.6968460083E-05 SELECT post_parent FROM wp_posts WHERE ID= '286' LIMIT 1
4.19616699219E-05 SELECT post_parent FROM wp_posts WHERE ID= '287' LIMIT 1
4.19616699219E-05 SELECT post_parent FROM wp_posts WHERE ID= '286' LIMIT 1
4.41074371338E-05 SELECT post_parent FROM wp_posts WHERE ID= '287' LIMIT 1
4.29153442383E-05 SELECT post_parent FROM wp_posts WHERE ID= '286' LIMIT 1
4.2200088501E-05 SELECT post_parent FROM wp_posts WHERE ID= '286' LIMIT 1
(... repeated like 2000~3000 times)
querying my database I found that the posts with the 286 and 287 IDs are exaclty the pages above the problematic one. Like:
www.mysite.com/tutorials/psp/somepagehere where: tutorials: ID 286 PSP: ID 287 somepagehere: The page where the high queries usage is shown
I alread tried disabling all my plugins, but the problem still persists, so Im pretty sure its some kind of Wordpress bug. I Marked this ticket as highest priority because some people are losing their blogs because of High CPU usage account termination! If needed, you can check this post where many users are complaining about this:
Attachments (3)
Change History (25)
#2
@
17 years ago
Im using the web-2.0 theme, but it happens even with my old theme (that worked fine before with 2.3).
Here's the widgets loaded in my sidebar:
5 text widgets;
Recent posts;
the TLA network widget (removing it or disabling it in the plugins page doesnt fix the problem);
Archives;
Links
And 2 more text widgets in the end;
Btw, I cant see your attached plugin, where is it? Afeter downloading it I can make a new reply here with the results. Thank You
#3
@
17 years ago
Btw, I cant see your attached plugin
Sorry, Forgot to attach it :), Should be there now.
#4
follow-up:
↓ 5
@
17 years ago
Thanks for the plugin. According to the plugin's dump (I took out the "normal" queries and started the dump from the strange ones):
[20] => Array ( [0] => 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 ( t.term_id <> 58 ) ORDER BY t.name ASC [1] => 9.10758972168E-05 [2] => get_terms ) [21] => Array ( [0] => SELECT `post_parent` FROM wp_posts WHERE ID= '286' LIMIT 1 [1] => 7.89165496826E-05 [2] => _get_post_ancestors ) [22] => Array ( [0] => SELECT * FROM wp_posts WHERE (post_type = 'page' AND post_status = 'publish') ORDER BY menu_order, post_title ASC [1] => 0.00259494781494 [2] => get_pages ) [23] => Array ( [0] => SELECT `post_parent` FROM wp_posts WHERE ID= '286' LIMIT 1 [1] => 0.000121831893921 [2] => _get_post_ancestors ) [24] => Array ( [0] => SELECT `post_parent` FROM wp_posts WHERE ID= '287' LIMIT 1 [1] => 4.79221343994E-05 [2] => _get_post_ancestors ) [25] => Array ( [0] => SELECT `post_parent` FROM wp_posts WHERE ID= '286' LIMIT 1 [1] => 4.10079956055E-05 [2] => _get_post_ancestors ) [26] => Array ( [0] => SELECT `post_parent` FROM wp_posts WHERE ID= '287' LIMIT 1 [1] => 4.10079956055E-05 [2] => _get_post_ancestors ) [27] => Array ( [0] => SELECT `post_parent` FROM wp_posts WHERE ID= '286' LIMIT 1 [1] => 4.10079956055E-05 [2] => _get_post_ancestors ) [28] => Array ( [0] => SELECT `post_parent` FROM wp_posts WHERE ID= '286' LIMIT 1 [1] => 4.2200088501E-05 [2] => _get_post_ancestors ) [29] => Array ( [0] => SELECT `post_parent` FROM wp_posts WHERE ID= '286' LIMIT 1 [1] => 4.81605529785E-05 [2] => _get_post_ancestors ) [30] => Array ( [0] => SELECT `post_parent` FROM wp_posts WHERE ID= '287' LIMIT 1 [1] => 4.29153442383E-05 [2] => _get_post_ancestors ) [the same for all the others queries]
On the other pages where the error occours the problematic function is the same (_get_post_ancestors)
#5
in reply to:
↑ 4
@
17 years ago
- Keywords has-patch needs-testing added
- Milestone changed from 2.7 to 2.6
Replying to tiosolid:
On the other pages where the error occours the problematic function is the same (_get_post_ancestors)
To me it looks like theres a logic error:
http://trac.wordpress.org/browser/trunk/wp-includes/post.php#L2968
if ( !isset($_post->ancestors) ) return;
While that seems to say do not load ancestors if none are allready set to me, However, I'm not sure if thats quite correct in general.
Eitherway, The attached patch prevents those multiple queries for me, It limits it to finding the ancestors once per page request, I thought of wrapping it in a wp_cache_get/set however, this seems to do the job.
#7
@
17 years ago
Hi, i tried to change the (!isset) to (isset) but still the queries problem appeared. The unique way to solve my high mysql usage was to comment out the While statment from the get_post_ancestors function. Since this is probably going to break something somewhere, is there any other way to fix this?
#10
@
17 years ago
[7601] looks like it is related.
That looks like its reversed the logic to me..
Not Empty = return if items are loaded
Not Isset = return if there are no items loaded
Idealy, I guess some caching needs to be added to the function to cache page ancestors maybe?
#14
@
17 years ago
- Milestone changed from 2.6 to 2.5.1
That adds ancestors to the post cache and fixes cache clean so that all ancestors are cleaned. I don't know if that will be enough though. We might have to remove the _get_post_ancestors() call from get_post() and lose the feature that needs the ancestors in wp_list_pages().
What theme are you using?
What widgets do you have loaded?
I just tried with /about-me/sub-about-me/sub-sub-about-me/ and i have 5 page-related queries:
(I'm not sure why both get_post() and get_posts() are making pretty similar queries
It'd be helpful to know where the queries are coming from. As you can see in that example, mine mainly come from 'get_page_by_path()'
while there's probably another plugin out there which probably allready does this, i'll attach a plugin which dumps the queries made into the footer of the page as a HTML comment, so you'll need to view the HTML source to get at them, Hopefully that'll include the source of the queries (I'm not too sure what the plugin you used is/does)
You'll also need to add
to your wp-config.php file.