有没有一种方法可以提高此查询的性能(聚合)

时间:2019-08-21 18:18:34

标签: sql-server performance sql-server-2016

以下是查询:

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

1 个答案:

答案 0 :(得分:0)

检查

  1. 表FactSupplyDataDetail的索引从PeriodID开始
  2. 表DimSupply的索引从SupplyID开始
  3. 表DimPLProvider的索引从PLProviderID开始

表TABLE的索引从COLUMN列开始,这意味着您已将索引(idx_xxx_)定义为:

在TABLE上创建索引idx_xxx(列,其他一些列或空列表);