我有两个WP查询都很相似。一个很快,另一个很慢。我已经通过mysql直接测试了两个查询。
最快的一个: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
下面的慢一点:
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
我很好奇为什么另一个这么慢?