gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 11:13:25 25 4
gpt4 key购买 nike

我有一个查询并在 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 未在查询中使用。为什么这是输出列表中唯一包含的列?

最佳答案

需要 PK 列来查看聚簇索引(假设 PK)以获取列 c10 和 c11。这称为“ key 查找”

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

试试这个

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

Some background reading from Simple Talke via Google

关于sql-server - MS SQL 执行计划中未使用的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39223805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com