日期:2014-05-17  浏览次数:20407 次

!!!!!!各位大侠,SQL语句优化问题!!!!!!!!!!!!
SQL code

select  rel.fin_mainid,rel.fin_childid  
from fin_relationship rel with(index(index_relitemall,ix_dp,ix_ismain))
where
exists(select accounttempid 
from accounttemp with(index(ix_datafrom))
where accounttemp.accounttempid = rel.fin_mainid and accounttemp.datafrom is null)
and rel.fin_dataprocess=1
and rel.fin_ismain =1
and rel.fin_relationshipitem=1


如上的查询语句 fin_relationship这个表大概有1千万数据accounttemp有700万数据 如何优化这个语句呢
其中fin_dataprocess、fin_ismain、fin_relationshipitem均有非聚集索引accounttemp的datafrom建立了非聚集索引,谢谢。

------解决方案--------------------
1、不要使用WITH index,让优化器自己处理。
2、fin_relationship ,accounttemp如果列不多,麻烦把结构和索引弄来看看,我怀疑你是一列一个索引。
3、先看索引,有必要把exists放到最后再执行。
------解决方案--------------------
accounttemp.accounttempid = rel.fin_mainid
这两个关联的执行计划是什么?
这两个id上面有索引吗?主键+非聚集?