【问题标题】:Unused column in MS SQL execution planMS SQL 执行计划中未使用的列
【发布时间】:2016-08-30 09:32:21
【问题描述】:

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

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

表 a 上的索引:

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。为什么这是输出列表中包含的唯一列?

【问题讨论】:

    标签: sql-server select sql-execution-plan


    【解决方案1】:

    需要 PK 列来查看聚集索引(假定为 PK)以获取列 c10 和 c11。这称为“密钥查找”

    您可以通过创建或更改非聚集索引来删除它,使其“覆盖”

    试试这个

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

    Some background reading from Simple Talke via Google

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-20
      • 1970-01-01
      • 2020-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-22
      • 2012-02-18
      相关资源
      最近更新 更多