SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Help On Execution Plan Status


Help On Execution Plan Status

Author
Message
Shadab Shah
Shadab Shah
SSC-Addicted
SSC-Addicted (443 reputation)SSC-Addicted (443 reputation)SSC-Addicted (443 reputation)SSC-Addicted (443 reputation)SSC-Addicted (443 reputation)SSC-Addicted (443 reputation)SSC-Addicted (443 reputation)SSC-Addicted (443 reputation)

Group: General Forum Members
Points: 443 Visits: 798
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.
Dennis Post
Dennis Post
Old Hand
Old Hand (397 reputation)Old Hand (397 reputation)Old Hand (397 reputation)Old Hand (397 reputation)Old Hand (397 reputation)Old Hand (397 reputation)Old Hand (397 reputation)Old Hand (397 reputation)

Group: General Forum Members
Points: 397 Visits: 547
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/



For better, quicker answers on T-SQL questions, read Jeff Moden's suggestions.

"Million-to-one chances crop up nine times out of ten." ― Terry Pratchett, Mort
GilaMonster
GilaMonster
SSC Guru
SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)

Group: General Forum Members
Points: 88739 Visits: 45284
Seek when there's a SARGable predicate (<column> <comparison operator> <expression>Wink 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

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Grant Fritchey
Grant Fritchey
SSC-Forever
SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)

Group: General Forum Members
Points: 40773 Visits: 32666
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

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
ScottPletcher
ScottPletcher
SSCrazy Eights
SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)SSCrazy Eights (8K reputation)

Group: General Forum Members
Points: 8020 Visits: 7163
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)[size=2]Prosecutor James Blackburn, in closing argument in the Fatal Vision murders trial: If in the future, you should cry a tear, cry one for them [the murder victims]. If in the future, you should say a prayer, say one for them. And if in the future, you should light a candle, light one for them.[/size]
GilaMonster
GilaMonster
SSC Guru
SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)

Group: General Forum Members
Points: 88739 Visits: 45284
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

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Paul White
Paul White
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16036 Visits: 11355
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.



Paul White
SQLPerformance.com
SQLblog.com
@SQL_Kiwi
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search