0

I have two WP Query are very similar. one is fast and another is very very slow. I have already test two query via mysql directly.

the fast one: SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND ( wp_posts.post_date >= '2019-09-04 21:45:00' ) AND ( ( ( wp_postmeta.meta_key = 'wpcm_home_club' AND wp_postmeta.meta_value = '37358' ) OR ( wp_postmeta.meta_key = 'wpcm_away_club' AND wp_postmeta.meta_value = '37358' ) ) ) AND wp_posts.post_type = 'wpcm_match' AND ((wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date ASC LIMIT 0, 500

and the slow one below:

SELECT 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_date < '2019-09-04 21:45:00' ) AND ( ( ( wp_postmeta.meta_key = 'wpcm_home_club' AND wp_postmeta.meta_value = '37358' ) OR ( wp_postmeta.meta_key = 'wpcm_away_club' AND wp_postmeta.meta_value = '37358' ) ) ) AND wp_posts.post_type = 'wpcm_match' AND ((wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 1

I'm curious that why another is so slow?

0

It is likely there are very few rows WHERE AND ( wp_posts.post_date >= '2019-09-04 21:45:00' ) there are likely many thousands of rows WHERE AND ( wp_posts.post_date < '2019-09-04 21:45:00' ) and a table scan is required. EXPLAIN SELECT SQL_NO_CACHE remainder of query for each and examine results carefully. Post the TEXT RESULTS of EACH EXPLAIN SELECT SQL_NO_CACHE remainder of your query for our assistance in understanding what is going on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.