当前位置: 代码迷 >> Sql Server >> !各位大侠,SQL语句优化有关问题!
  详细解决方案

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

热度:10   发布时间:2016-04-27 10:50:55.0
!!!!!!各位大侠,SQL语句优化问题!!!!!!!!!!!!
SQL code
select  rel.fin_mainid,rel.fin_childid  from fin_relationship rel with(index(index_relitemall,ix_dp,ix_ismain))whereexists(select accounttempid from accounttemp with(index(ix_datafrom))where accounttemp.accounttempid = rel.fin_mainid and accounttemp.datafrom is null)and rel.fin_dataprocess=1and rel.fin_ismain =1and 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上面有索引吗?主键+非聚集?
  相关解决方案