2017-01-24 75 views
0

我試圖運行這個SELECT語句,但我需要數小時才能執行。我也在這些表上創建了索引。SELECT語句需要幾小時才能執行

SELECT DISTINCT 
    j.Name AS State, 
    l.DisplayName AS ServiceCenter, 
    l.JurisdictionID, 
    e.LocationID, 
    ConvictionStateID AS RegionId, 
    FeeGroupID, 
    e.VehicleID , 
    ServiceDate, 
    evd.EventlogID, 
    v.ClientID, 
    e.EventLogServiceID, 
    evd.EventlogDetailID, 
    EvtDT AS EventDate, 
    EvtVal AS EventValue, 
    evd.EventLogCodeID, 
    UPPER(SerialNumber) AS SerialNumber, 
    UPPER(RelayNum) AS RelayNumber, 
    edp.FileName, 
    GPSLatitude 
FROM 
    [MM\PLUSREPORT5].lsa_plus_jur_nico.dbo.EventLogDetail evd 
INNER JOIN 
    [MM\PLUSREPORT5].lsa_plus_jur_nico.dbo.EventLog e ON evd.EventlogID = e.EventlogID 
INNER JOIN 
    [MM\PLUSREPORT5].lsa_plus_jur_nico.dbo.Vehicle v ON e.VehicleID = v.VehicleID 
INNER JOIN 
    [MM\PLUSREPORT5].lsa_plus_jur_nico.dbo.Client c ON v.ClientID = c.ClientID 
INNER JOIN 
    [MM\PLUSREPORT5].lsa_plus_base.dbo.Location l ON e.LocationID = l.LocationID 
INNER JOIN 
    [MM\PLUSREPORT5].lsa_plus_base.dbo.Jurisdiction j ON l.JurisdictionID = j.JurisdictionID 
LEFT JOIN 
    [MM\PLUSREPORT5].lsa_plus_jur_nico.dbo.EventLogDetailPhoto edp ON evd.EventLogDetailId = edp.EventLogDetailId 

Excution plan,也嵌入在下面。

Excution plan

+1

請張貼**表結構**和**索引創建腳本** –

+0

我加入七個表一起如何張貼表結構 – ALE

+0

請你可以幫助重寫查詢,以避免哈希匹配成像我有所有關鍵列索引 – ALE

回答

-1

你沒有得到任何並行和排序被彈起。

檢查您的索引是否配置爲DESC順序。

向後掃描索引的限制是它們不能並行。

如果可能,也嘗試並刪除DISTINCT,這可以添加相同的限制。

+0

爲什麼投票? – pacreely