我遇到了一些问题,这个查询及时运行,我的'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
答案 0 :(得分:3)
我没有看到任何其他人。用于连接的任何字段都应始终编入索引。从where子句获得字段索引也可以提供很多帮助,但是你应该对过多的索引保持谨慎。