小编L. *_*ler的帖子

为什么选择此查询的所有结果列比选择我关心的一列更快?

我有一个查询,其中使用select *不仅读取少得多,而且使用的 CPU 时间也比使用select c.Foo.

这是查询:

select top 1000 c.ID
from ATable a
    join BTable b on b.OrderKey = a.OrderKey and b.ClientId = a.ClientId
    join CTable c on c.OrderId = b.OrderId and c.ShipKey = a.ShipKey
where (a.NextAnalysisDate is null or a.NextAnalysisDate < @dateCutOff)
    and b.IsVoided = 0
    and c.ComplianceStatus in (3, 5)
    and c.ShipmentStatus in (1, 5, 6)
order by a.LastAnalyzedDate
Run Code Online (Sandbox Code Playgroud)

这以 2,473,658 次逻辑读取结束,大部分在表 B 中。它使用了 26,562 个 CPU,持续时间为 7,965。

这是生成的查询计划:

从选择单个列的值进行计划 关于 PasteThePlan:https ://www.brentozar.com/pastetheplan/ ? …

performance sql-server execution-plan sql-server-2014 query-performance

13
推荐指数
1
解决办法
2051
查看次数