此查询在8秒执行:
SELECT segment,
[segstart]
FROM dbo.CmsCallHistory WITH (INDEX(CmsCallHistory_SGSTRT))
WHERE segstart between '2015-09-20' and '2015-09-30'
但这个查询~3分钟
SELECT segment,
[segstart]
FROM dbo.CmsCallHistory
WHERE segstart between '2015-09-20' and '2015-09-30'
数据行数约为120k
在第二个查询执行计划中,我看不到索引,但只有表扫描成本为98%:
列总数:~20
总行数:40296998
那有什么不对?
答案 0 :(得分:1)
DROP INDEX CmsCallHistory_SGSTRT ON dbo.CmsCallHistory
GO
CREATE CLUSTERED INDEX CmsCallHistory_SGSTRT ON dbo.CmsCallHistory (segstart)
GO
--DBCC FREEPROCCACHE
--GO
SELECT segment, [segstart]
FROM dbo.CmsCallHistory
WHERE segstart BETWEEN '2015-09-20' AND '2015-09-30'
答案 1 :(得分:1)
基于第二个执行计划,我建议创建一个涵盖指数。这将从执行计划中删除KeyLookUpID,它应该解决问题。 对覆盖的索引
也referCREATE NONCLUSTERED INDEX IX_Name
ON dbo.CmsCallHistory (segstart)
INCLUDE (segment.. include your other columns from select statement);
GO