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.

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(94)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2019-05-31 WCF Error Handling
2019-05-31 Jira中的Tempo查看component以及issue的工作量汇总
2019-05-31 “The creator of this fault did not specify a Reason” Exception
2019-05-31 Fault Contract
2019-05-31 redirect thread aborted
2019-05-31 How-To-Ask-Questions-The-Smart-Way提问的技巧 提问的智慧
2018-05-31 NSubstitute
点击右上角即可分享
微信分享提示