[英]What "Clustered Index Scan (Clustered)" means on SQL Server execution plan?
[英]Why the differences in execution plan between nonclustered and clustered index in SQL Server?
请解释为什么非聚集索引和聚集索引之间存在以下差异。 首先,我正在运行以下两个选择语句。
select *
from [dbo].[index_test2]
where id = 1 -- Nonclustered index on id column
select *
from [dbo].[index_test1]
where id = 1 -- Clustered index on id column
执行计划显示第一个查询的“表扫描”和第二个查询的“聚集索引查找(聚集)”。
然后我在两个语句下运行。
select id
from [dbo].[index_test2]
where id = 1 -- Nonclustered index on id column
select id
from [dbo].[index_test1]
where id = 1 -- Clustered index on id column
执行计划显示第一个查询的“索引查找(非集群)”和第二个查询的“集群索引查找(集群)”。
从以上两种情况可以看出,当使用聚集索引时,它会进行“索引查找”,但对于非聚集索引,它显示“表扫描”(用 * 执行)并显示“索引查找(非聚集)”(使用索引应用的 column-id 执行)。
任何人都可以澄清为什么 NonClustered 索引对两种情况的反应不同?
聚集索引定义了数据在表中物理存储的顺序,但非聚集索引不对表内部的物理数据进行排序。实际上,非聚集索引存储在一个地方,而存储表数据在另一个地方。
如果您使用Non-Clustered Index
则在调用属性时它会在Index seek (NonClustered)
Non-Clustered Index
Index seek (NonClustered)
模式下工作,但是如果您将where
置于Non-Clustered Index
模式中,但调用select
更多不是覆盖索引更改模式的表达式到Table scan
包含列的索引在覆盖查询时提供最大的好处。 这意味着索引包括查询引用的所有列,因为您可以添加数据类型、数量或大小不允许作为索引键列的列
但是在Clustered Index
,由于实际排序是由它完成的,因此您可以在Clustered index seek (clustered)
模式下进行这两种操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.