MS SQL 执行计划中未使用的列

Unused column in MS SQL execution plan

我有一个查询并在 SQL Management Studio 中检查了执行计划。一些非聚集索引扫描步骤 return table 的 PK 列而不是索引和连接列。示例:

select a.c10, b.c20
from a inner join b on a.c11 = b.c21
where a.c12 = 23

table 上的索引:

create unique nonclustered index ix_a_1 on a (a.c12 asc) include ( a.c13, a.c14)

查询计划显示:

index seek, nonclustered, ix_a_1 , output list: a.primary_key_col

查询中未使用列 a.primary_key_col。为什么这是输出列表中唯一包含的列?

需要 PK 列来查看聚簇索引(假定 PK)以获取列 c10 和 c11。这被称为 "key lookup"

您可以通过创建或更改非聚集索引来删除它,使其成为 "covering"

试试这个

create nonclustered index ix_a_gbn on a (c12, c11) include (c10, c13, c14)

Some background reading from Simple Talke via Google