我在 MU wordpress 网站上工作,我在查询中遇到问题,需要花费太多时间来执行。
SELECT wp_posts.* FROM wp_posts
INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
INNER JOIN wp_term_taxonomy ON (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id)
INNER JOIN wp_terms ON (wp_term_taxonomy.term_id = wp_terms.term_id)
WHERE 1=1 AND wp_posts.blog_id = '1'
AND wp_term_taxonomy.taxonomy = 'post_tag'
AND wp_terms.slug IN ('rate')
AND wp_posts.post_type = 'post'
AND (wp_posts.post_status = 'publish')
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC
LIMIT 0, 20
这个由wordpress执行的查询,执行需要30-40秒,这太多了。
- wp_posts : 4,00,000 行
- wp_terms : 2,50,000 行
- wp_term_relationship : 2,30,000 行
- wp_term_taxonomy : 2,60,000 行
我已经索引了列(使用的)。