Slow SQL query after update to 6.9.4
-
Hi. I recently updated a wordpress site from v6.6.1 to v6.9.4 and noticed some of the queries are running with a very slow plan.
For example, the following query:
SELECT wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND (wp_term_relationships.term_taxonomy_id IN (<id list here>)) AND wp_posts.post_type = 'post' AND ((wp_posts.post_status = 'publish')) ORDER BY wp_posts.post_date DESC LIMIT 0, 10Executes with an optimized plan in the older version and returns in 0.01 seconds:
-> Limit: 10 row(s) (cost=452486 rows=10) (actual time=0.0938..0.298 rows=10 loops=1)
-> Nested loop inner join (cost=452486 rows=318651) (actual time=0.0927..0.297 rows=10 loops=1)
-> Covering index lookup on wp_posts using type_status_date (post_type='post', post_status='publish') (reverse) (cost=52123 rows=443933) (actual time=0.0404..0.055 rows=38 loops=1)
-> Filter: (wp_term_relationships.term_taxonomy_id in (43,89,114,200,462,521,536,609,856,434561)) (cost=0.255 rows=0.718) (actual time=0.00556..0.00618 rows=0.263 loops=38)
-> Covering index lookup on wp_term_relationships using PRIMARY (object_id=wp_posts.ID) (cost=0.255 rows=6.47) (actual time=0.00279..0.00532 rows=10.7 loops=38)But it executes with a much slower query plan in the new version and returns in 1.20 seconds:
-> Limit: 10 row(s) (actual time=1630..1630 rows=10 loops=1)
-> Sort: wp_posts.post_date DESC, limit input to 10 row(s) per chunk (actual time=1630..1630 rows=10 loops=1)
-> Stream results (cost=297461 rows=152622) (actual time=1.52..1586 rows=196591 loops=1)
-> Nested loop inner join (cost=297461 rows=152622) (actual time=1.52..1551 rows=196591 loops=1)
-> Filter: ((wp_term_relationships.term_taxonomy_id in (43,89,114,200,462,521,536,609,856,434561)) and (wp_term_relationships.object_id is not null)) (cost=61760 rows=305245) (actual time=1.48..132 rows=196836 loops=1)
-> Covering index range scan on wp_term_relationships using term_taxonomy_id over (term_taxonomy_id = 43) OR (term_taxonomy_id = 89) OR (8 more) (cost=61760 rows=305245) (actual time=1.47..95.7 rows=196836 loops=1)
-> Filter: ((wp_posts.post_type = 'post') and (wp_posts.post_status = 'publish')) (cost=0.672 rows=0.5) (actual time=0.00691..0.00702 rows=0.999 loops=196836)
-> Single-row index lookup on wp_posts using PRIMARY (ID=wp_term_relationships.object_id) (cost=0.672 rows=1) (actual time=0.00647..0.0065 rows=1 loops=196836)The difference is negligible in isolation, but this query is executed on every load of the home page and causes considerable strain on the MySQL server during heavy traffic.
I’ve already tried running ANALYZE and OPTIMIZE on the wp_posts and wp_term_relationships table.
I assume other similar queries are also executing with a slow plan in the latest version.
Is there any workaround or fix for the slow queries?
Regards,
Trinopoty Biswas
You must be logged in to reply to this topic.