One of two similar WP Query is very slow

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?

Read more here:: One of two similar WP Query is very slow

Leave a Reply

Your email address will not be published. Required fields are marked *