zoukankan      html  css  js  c++  java
  • What “Clustered Index Scan (Clustered)” means on SQL Server execution plan?

    What “Clustered Index Scan (Clustered)” means on SQL Server execution plan?

    I would appreciate any explanations to "Clustered Index Scan (Clustered)"

    I will try to put in the easiest manner, for better understanding you need to understand both index seek and scan.

    SO lets build the table

    use tempdb GO
    
    
    create table scanseek  (id  int , name varchar(50) default ('some random names')  )
    
    create clustered index IX_ID_scanseek on scanseek(ID)
    
    
    declare @i int
    SET @i = 0
    while (@i <5000)
    begin 
    insert into scanseek
    select @i, 'Name' + convert( varchar(5) ,@i)
    set @i =@i+1
    END
    

    An index seek is where SQL server uses the b-tree structure of the index to seek directly to matching records

     you can check your table root and leaf nodes using the DMV below

    -- check index level 
    SELECT 
    index_level
    ,record_count
    ,page_count
    
    ,avg_record_size_in_bytes
    FROM sys.dm_db_index_physical_stats(DB_ID('tempdb'),OBJECT_ID('scanseek'),NULL,NULL,'DETAILED')
    GO

    Now here we have clustered index on column "ID"

    lets look for some direct matching records

    select * from scanseek where id =340
    

    and look at the Execution plan

    you've requested rows directly in the query that's why you got a clustered index SEEK .

    Clustered index scan: When Sql server reads through for the Row(s) from top to bottom in the clustered index. for example searching data in non key column. In our table NAME is non key column so if we will search some data in the name column we will see clustered index scan because all the rows are in clustered index leaf level.

    Example 

    select * from scanseek where name = 'Name340'
    

     please note: I made this answer short for better understanding only, if you have any question or suggestion please comment below.

  • 相关阅读:
    hdu--2852--树状数组
    hdu--2848--未解决
    二进制与十进制之间蛮好的转换方式
    hdu--2846--字典树<怪我思维不够跳跃>
    hdu--2845--dp
    hdu--2844--多重背包
    hdu--1789--贪心||优先队列
    hdu--1978--记忆化深度搜索||递推
    hdu--2830--任意交换列的矩阵
    hdu--1506--矩阵求和<stack>
  • 原文地址:https://www.cnblogs.com/chucklu/p/14831091.html
Copyright © 2011-2022 走看看