我遇到了一些問題,這個查詢及時運行,我的'LineItemsMap'表增長到大約一百萬行。任何建議我可以創建索引或更好的邏輯與查詢將不勝感激。與SQL查詢性能下降
select
Id,
[Description],
SUM(CASE WHEN t1.compliant = 1 THEN 1 ELSE 0 END) as Compliant,
SUM(CASE WHEN t1.compliant = 0 THEN 1 ELSE 0 END) as NonCompliant,
LastChecked
from lineitems as t0
left outer join lineitemsmap as t1 on t0.id = t1.lineitemid
left outer join art_blob as t2 on t2.art_blob_id = t1.blobid
left outer join art_asset as t3 on t3.art_asset_id = t2.art_asset_id
left outer join lineitemexceptions as t4 on t4.assetid = t3.art_asset_id and t4.lineitemid = t1.lineitemid
where t0.active = 1 and t4.assetid is null
group by t0.id, t0.[description], t0.lastchecked
這裏是保存在XML的執行計劃的鏈接:http://codepaste.net/5xcpcw 這裏是表結構的鏈接:http://codepaste.net/pnqx6e
你有什麼樣的索引?這些表所涉及的結構是什麼? –
@marc_s大多隻是默認索引。我包含了一個鏈接到表結構腳本。 –
http://codereview.stackexchange.com/ – cadrell0