Reputation: 365
This query execute in 8 s.:
SELECT segment,
[segstart]
FROM dbo.CmsCallHistory WITH (INDEX(CmsCallHistory_SGSTRT))
WHERE segstart between '2015-09-20' and '2015-09-30'
But this query ~3 minutes
SELECT segment,
[segstart]
FROM dbo.CmsCallHistory
WHERE segstart between '2015-09-20' and '2015-09-30'
Data rows count ~120k
In second query execution plan I can't see index, but only Table Scan cost 98%:
In first query execution plan I see that segstart index is used:
Columns total: ~20
Rows total: 40296998
So what's wrong ?
Upvotes: 1
Views: 884
Reputation: 906
Based on second execution plan I would suggest to create a Covered Index. This will get rid of KeyLookUpID from the execution plan and it should resolve the issue. Also refer this for covered index
CREATE NONCLUSTERED INDEX IX_Name
ON dbo.CmsCallHistory (segstart)
INCLUDE (segment.. include your other columns from select statement);
GO
Upvotes: 1
Reputation: 121922
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'
Upvotes: 1