简体   繁体   English

您将如何优化此mysql查询?

[英]How would you optimize this mysql query?

Can anybody help me in optimizing this query: 任何人都可以帮助我优化此查询:

SELECT DISTINCT
A.X1,      
A.X2   
FROM TABLEAA A
JOIN TABLEBB B ON A.Y = B.Y AND B.Z1='SELECTED1' AND B.W NOT LIKE 'SLECTED3'
JOIN TABLECC C ON A.Y = C.Y AND C.Z2='SELECTED2'
AND A.W NOT LIKE 'SLECTED3'

WHEREAS 鉴于

TABLEAA : 1 million entries TABLEBB : 17 million entries TABLECC : 1.2 million entries TABLEAA:100万个条目TABLEBB:1700万个条目TABLECC:120万个条目

It works but it takes almost 8 to 10 seconds. 它可以工作,但几乎需要8到10秒。

Is there any other way to write this? 还有其他写方法吗?

edit: primary index on TableBB is combination of B.Z1 and BY primary index on TableCC is combination of C.Z2 and CY primary index on TableAA is AY 编辑:TableBB的主要索引是B.Z1和BY的组合,TableCC的主要索引是C.Z2和CY的组合,TableAA的主要索引是AY

I hope this's better. 我希望这会更好。

SELECT DISTINCT A.X1, A.X2   
FROM TABLEAA AS A
INNER JOIN(TABLEBB AS B)
   ON(A.Y = B.Y)
INNER JOIN(TABLECC AS C)
   ON(A.Y = C.Y)
WHERE B.Z1 = 'SELECTED1' AND
      B.W NOT LIKE '%SLECTED3%' AND
      C.Z2='SELECTED2' AND
      A.W NOT LIKE '%SLECTED3%'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM