Help On Execution Plan Status

  • 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.

  • 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.[/url]

    "Million-to-one chances crop up nine times out of ten." ― Terry Pratchett, Mort

  • 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

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • 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

  • 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) A socialist is someone who will give you the shirt off *someone else's* back.

  • 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
  • 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