我有一个查询,需要11秒钟来提取记录,因为数据库很大,如150mb。 (编辑:抱歉,这并不大,人们让我意识到了我:D)
如何优化此查询?
select id, post_title,featured, location, application_deadline, post_name, post_content, post_date as d, logo FROM wp_posts
LEFT JOIN wp_term_relationships ON wp_posts.id = wp_term_relationships.object_id
LEFT JOIN wp_term_taxonomy ON wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id
LEFT JOIN wp_terms ON wp_term_taxonomy.term_id = wp_terms.term_id
WHERE wp_posts.post_status='publish'
AND wp_posts.post_type='post'
AND wp_term_taxonomy.taxonomy = 'category'
AND wp_terms.post_type='news'
order by post_date desc limit 0, 9
答案 0 :(得分:1)
首先150 mb不大。我建议使用SSMS中的执行计划来确定查询在何处执行。
您可以使用估算计划和实际计划。
如果您对执行计划一无所知,请阅读以下好文章:
https://www.red-gate.com/simple-talk/sql/performance/execution-plan-basics/
答案 1 :(得分:0)
我解决了这个问题。