关于大数据量查询
当在一个400w条以上数据的表中运行查询时,如果where中使用索引列和值比较作为筛选条件就比较快,和变量比较作为筛选条件就比较慢,为什么,如何解决?
例:
其中actiontime建立索引了
DECLARE @TheDate datetime
SELECT @TheDate = getdate()
SELECT actiontime,UserID
from flog
WHERE
--(ActionTime between dateadd(day,-1,getdate()) and getdate()) --***slow***
ActionTime between '2004-9-23' and '2004-9-24' --***fast***