WP generated SQL for orderby meta is super slow on very large DBs
-
tl;dr: How do people with hundreds of of thousands of posts deal with very slow queries?
I’m converting a very old and large Phorum installation to BBPress, some queries are extremely slow.
It seems that when a query orders by meta value, this SQL is generated by WordPress:
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND wp_posts.post_parent = 9 AND wp_posts.post_type = 'topic' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'closed' OR wp_posts.post_status = 'private' OR wp_posts.post_status = 'hidden') AND (wp_postmeta.meta_key = '_bbp_last_active_time' ) GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value DESC LIMIT 0, 15
This query takes 20 seconds on my 750k post wp_posts table, with a powerful AWS DB instance. I’ve already tried DB optimization, and server optimization techniques, and while they have an impact, the query is still taking well over 15 seconds in a best case scenario.
These orderby meta queries are pretty fundamental to BBPress, and I’m not sure it’s something I can code out without hacking BBPress core, or WordPress core.
It seems that this is a common problem, and the offered solution is to remove the SQL_CALC_FOUND_ROWS part and achieve pagination in some other way. However, I’ve tried that, and no dice, it’s still slow. I think it’s the JOIN that’s causing the lag.
I know that this is something that can be dealt with in one way or another, since I see BBPress installations with more posts than mine.
Any solutions?
Thanks.
- The topic ‘WP generated SQL for orderby meta is super slow on very large DBs’ is closed to new replies.