如何提高此查询的性能?这需要超过一分钟?

时间:2016-08-04 14:52:25

标签: sql sql-server sql-server-2008

我有以下查询: 这花了一分多钟......我需要提高性能并将其降低到不到10秒。

感谢您的回复。

SELECT  
DISTINCT 
RP.RegionPerilID 
,RP.RegionName + ' ' + RP.ShortName AS RegionPerilName 
,LossLevelID
,LL.LossLvlName AS LossLevelName
FROM Axis_Accumulation.dbo.AIREventSet ES 
       JOIN Axis_Accumulation.dbo.vw_RegionPerils RP ON RP.RegionPerilId = ES.RegionPerilId 
       JOIN ART.LA.ELT_Blend ELT WITH (NOLOCK) ON ES.EventNum = ELT.EventNum AND ELT.Versionid = @versionId 
       JOIN dbo.LA_LossLevel LL ON ELT.LossLevelID = LL.LossLvlID AND LL.LosstypeId = 3 -- Line of Business
       ORDER By RegionPerilName

1 个答案:

答案 0 :(得分:1)

您应该尝试创建这些索引(如果它们尚不存在):

CREATE NONCLUSTERED INDEX IX_AIREventSet ON Axis_Accumulation.dbo.AIREventSet
(
    RegionPerilID
)
INCLUDE
(
    EventNum
)

CREATE NONCLUSTERED INDEX IX_AIREventSet_EvenNum ON Axis_Accumulation.dbo.AIREventSet
(
    EventNum
)


CREATE NONCLUSTERED INDEX IX_vw_RegionPerils ON Axis_Accumulation.dbo.vw_RegionPerils
(
    RegionPerilID
)
INCLUDE
(
    RegionName,
    ShortName
)


CREATE NONCLUSTERED INDEX IX_ELT_Blend ON ART.LA.ELT_Blend
(
    EventNum,
    Versionid,
)
INCLUDE
(
    LossLevelID
)

CREATE NONCLUSTERED INDEX IX_ELT_Blend_LossLevelID ON ART.LA.ELT_Blend
(
    LossLevelID
)



CREATE NONCLUSTERED INDEX IX_LA_LossLevel ON dbo.LA_LossLevel
(
    LossLvlID,
    LosstypeId
)
INCLUDE
(
    LossLvlName
)

如果在下面的列表中,字段是唯一的,请在索引定义中添加UNIQUE子句。 INCLUDE语句很重要,因为它通过查找一个索引来获取所有数据。 逐个添加索引并检查执行计划是否已使用。如果没有,你可以删除它。

这最后一个索引应该有助于对数据进行排序!

CREATE CLUSTERED UNIQUE INDEX IX_AIREventSet_Clustered ON Axis_Accumulation.dbo.AIREventSet
(
    RegionName,
    ShortName,
    RegionPerilID,
    [YourTableId]
)