0
嘿家伙我有一个关于sql性能的快速问题。我有一个非常非常大的表,它永远运行下面的查询,请注意,有一个与时间戳列mysql tunning时间戳性能?
select name,emails,
count(*) as cnt
from table
where date(timestamp) between '2016-01-20' and '2016-02-3'
and name is not null
group by 1,2;
所以,我的朋友建议使用下面这个查询:
select name,emails,
count(*) as cnt
from table
where timestamp between date_sub(curdate(), interval 14 day)
and date_add(curdate(), interval 1 day)
and name is not null
group by 1,2;
而且这需要更少的时间来运行。为什么?这两个时间函数有什么区别? 还有另一种更快的运行方式吗?像索引?有人可以向我解释mysql如何运行?非常感谢!
在我的文章中也包含了对这两个查询的解释以及对于这些问题的创建表语句 – Shadow
检查原因... –