November 30, 2012 at 7:52 am
Hi All,
I am a newbie in SQL Server and like exploring it. Currently i was working with some complex queries and happen to see there Execution Plan. I saw that there were some Clustered index which were 'ClusteredIndexSeek' and Some Clustered Index as 'ClusteredIndexScan'.
So my basic question is, how does the query analyzer decide when to used ClusteredIndexScan and when to used ClusteredIndexSeek.
November 30, 2012 at 8:04 am
Paul White's blog series will pretty much any question you could ever think of on this.
http://www.sqlservercentral.com/articles/SQL+Server+2008/71019/
November 30, 2012 at 8:12 am
Seek when there's a SARGable predicate (<column> <comparison operator> <expression>) on the index key columns. Scan if there isn't. Very, very simplified, but that's the basics.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
November 30, 2012 at 9:22 am
And the indexes have to be selective enough to be useful for a seek or you'll get scans. Same things apply to non-clustered indexes too.
For lots more detail on query tuning and execution plans, take a look at my books (listed below).
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
November 30, 2012 at 12:28 pm
Grant Fritchey (11/30/2012)
And the indexes have to be selective enough to be useful for a seek or you'll get scans. Same things apply to non-clustered indexes too.For lots more detail on query tuning and execution plans, take a look at my books (listed below).
Not for clustered indexes. SQL can do a seek on a clustered index even if you're SELECTing 99% of the rows.
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
November 30, 2012 at 12:49 pm
ScottPletcher (11/30/2012)
Grant Fritchey (11/30/2012)
And the indexes have to be selective enough to be useful for a seek or you'll get scans. Same things apply to non-clustered indexes too.For lots more detail on query tuning and execution plans, take a look at my books (listed below).
Not for clustered indexes. SQL can do a seek on a clustered index even if you're SELECTing 99% of the rows.
More correctly, not for any index that covers the query. A covering nonclustered index can and will be used for a seek up to 100% of the rows.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
December 1, 2012 at 10:38 pm
Shadab Shah (11/30/2012)
So my basic question is, how does the query analyzer decide when to used ClusteredIndexScan and when to used ClusteredIndexSeek.
It will often consider both alternatives. It estimates the cost of each and chooses the one that appears cheapest (according to the model it uses). There are a number of detailed factors that affect the cost calculation, and overall plan selection, but that's a basic answer to your basic question.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply