我在及时运行此查询时遇到了一些问题,我的“LineItemsMap”表增长到大约一百万行。任何关于我可以创建的索引或更好的查询逻辑的建议将不胜感激。
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