[英]how can I optimise below mysql query (I am new to optimisation)
如何優化此 MySQL 查詢?
下面也提到了執行計划。
Select
tlk.id, um.store_users_id
from
user_modules um
inner join
module_chapters mc on um.modules_id = mc.modules_id
and mc.comment_status = 1
and um.modules_id = 3697
and mc.chapters_id = 4083
inner join
context con on con.module_id = mc.modules_id
and con.chapter_id = mc.chapters_id
inner join
user_talks tlk on tlk.contextId = con.id
and tlk.context_scope = 1
left join
talk_associated_users tau on tau.talk_id = tlk.id
and tau.target_store_user_id = um.store_users_id
where
tau.target_store_user_id is null
[![上述查詢的計划][1]][1]
運行EXPLAIN SELECT ...
並提供結果。
and mc.comment_status = 1
and um.modules_id = 3697
and mc.chapters_id = 4083
這些聞起來像是屬於WHERE
子句的東西,而不是JOIN...ON
。
在mc
,這可能是最佳的:
INDEX(chapters_id, comment_status)
在um
,這可能是最佳的:
INDEX(modules_id)
EXPLAIN
,特別是在添加這些索引之后,可能會導致更好的索引。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.