Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Why is CAST using an Index Seek??

$
0
0
I’m a new member on a team and came across the following query (which I’ve obfuscated) in a stored procedure and immediately thought I would be able to add value by explaining that casting a column used in the criteria would be a performance problem. I took the original query and my re-worked version and got the estimated execution plan. Much to my dismay, both queries are doing an index seek! I have nothing to back up my suggestion now. Why on earth is it doing a seek on what I thought was the poorly written query? The table itself is very small since it’s a dev environment – approximately 800 rows. There is a nonclustered index on CreatedDate.[code="sql"]-- What is being usedSELECT SomeID, CreatedDateFROM SomeHistoryWHERE CAST(CreatedDate AS DATE) BETWEEN '2/1/2016' AND '2/8/2016'ORDER BY CreatedDate desc-- What I want to suggestSELECT SomeID, CreatedDateFROM SomeHitoryWHERE CreatedDate BETWEEN '2/1/2016' AND '2/9/2016'ORDER BY CreatedDate desc[/code]I'm also attaching images of the execution plans as well as the properties of the Index Seek items from the plan.Thank you!

Viewing all articles
Browse latest Browse all 3145

Trending Articles