首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

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

2012-10-17 
!!!!!!各位大侠,SQL语句优化问题!!!!!!!!!!!!SQL codeselectrel.fin_mainid,rel.fin_childidfrom fin_rela

!!!!!!各位大侠,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上面有索引吗?主键+非聚集?

热点排行