你有什麼想法,我怎麼能加快下面的查詢?我怎樣才能加速這一MySQL查詢(計數明顯與加盟)
select count(distinct t1.var1)
from table_a t1
join table_b t2 on t1.var2 = t2.var1
and t2.date between '2016-11-05 00:00:00' and '2016-11-10 23:59:59'
and t2.var3 = 3;
我已經試過這樣:
select count(*)
from (select distinct t1.var1 from table_a t1
join table_b t2 on t1.var2 = t2.var1
and t2.date between ('2016-11-05 00:00:00') and ('2016-11-10 23:59:59')
and t2.var3 = 3) as temp
,但它並不比前一個
什麼'EXPLAIN'之前應用fiters說? – Barmar
見http://meta.stackoverflow.com/questions/333952/why-should-i-provide-an-mcve-for-what-seems-to-me-to-be-a-very-simple-sql-查詢。另外,關於查詢的性能問題,總是有一個EXPLAIN – Strawberry
這就是說,在3分T2列覆蓋索引似乎是一個不錯的主意 – Strawberry