以下是查询:
SELECT sdd.CompanyID
,sdd.ClassID
,sdd.PeriodID, SUM(sdd.Volume) AS VolumeTotal, SUM(sdd.Dollars) AS DollasTotal
,COUNT(LogID) as LogIDCount
FROM (SELECT dp.CompanyID
,ds.ClassID
,fs.PeriodID, fs.LogID, sum(fs.Volume) AS Volume,sum(fs.Dollars) AS Dollars
FROM DW.FactSupplyDataDetail fs WITH (NOLOCK)
JOIN DW.DimPLProvider dp WITH (NOLOCK)
ON fs.PLProviderID = dp.PLProviderID
JOIN DW.DimSupply ds WITH (NOLOCK)
ON fs.SupplyID = ds.SupplyID
WHERE fs.PeriodID between 201901 and 201907
GROUP BY dp.CompanyID
,ds.ClassID
,fs.PeriodID,fs.LogID) sdd
GROUP BY sdd.CompanyID
,sdd.ClassID
,sdd.PeriodID
这是查询的执行计划:
https://www.brentozar.com/pastetheplan/?id=rkoxSEjEH
DW.FactSupplyDataDetail has 10590237 records
DW.DimPLProvider has 5071 records
DW.DimSupply has 81001 records
result of a query is 1992094
答案 0 :(得分:0)
检查
表TABLE的索引从COLUMN列开始,这意味着您已将索引(idx_xxx_)定义为:
在TABLE上创建索引idx_xxx(列,其他一些列或空列表);