我有一个巨大的数据库,有超过250000篇帖子。我已经进行了所有可能的优化,并在互联网上搜索了所有可能的解决方案。
假设我有一个查询,我想从其中获取类别中的最后4篇帖子:
$recent = new WP_Query(array( \'cat\' => \'8\', \'posts_per_page\' => \'4\'));
哪个查询监视器转换为:
SELECT SQL_CALC_FOUND_ROWS 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 (8,9,10,11,12,13,14,15) )
AND wp_posts.post_type = \'post\'
AND (wp_posts.post_status = \'publish\'
OR wp_posts.post_status = \'private\')
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC
LIMIT 0, 4
And it takes 1,4628 seconds.
我的问题是,如果我在phpmyadmin中放置相同的查询并更改此行,为什么会这样:
AND ( wp_term_relationships.term_taxonomy_id IN (8,9,10,11,12,13,14,15) )
进入
AND ( wp_term_relationships.term_taxonomy_id IN (8) )
The query becomes TWICE as fast (0.5077 seconds). 为什么它只搜索“8”-类别id,却搜索其他分类id?欢迎提供任何建议。
非常感谢。