最近优化过的一个SQL语句

--优化前:

SQL执行需要11秒+
select b.biz_title_
from V_HZ_HAS_TODO_TASKLIST w
join t_jzwf_biz_info b
on w.WORKID = b.work_id_ where w.flowid = 'ZBLC'
and (w.auth_id = '3a0d5619e34c4cf09028566ff9fc2381'
or w.AGENT_ID = '3a0d5619e34c4cf09028566ff9fc2381');    

 

其中V_HZ_HAS_TODO_TASKLIST是一个视图,

select b.biz_title_
from V_HZ_HAS_TODO_TASKLIST w
 where w.flowid = 'ZBLC'
and (w.auth_id = '3a0d5619e34c4cf09028566ff9fc2381'
or w.AGENT_ID = '3a0d5619e34c4cf09028566ff9fc2381');  

还是比非常快的,但是加上t_jzwf_biz_info就慢了,SQL计划很长,看起来也费劲。

 

优化1:

改写SQL,但是失败了。

SQL执行需要11秒+

select b.biz_title_
from
join t_jzwf_biz_info b,(select w.workid V_HZ_HAS_TODO_TASKLIST w where w.flowid = 'ZBLC'
and (w.auth_id = '3a0d5619e34c4cf09028566ff9fc2381'
or w.AGENT_ID = '3a0d5619e34c4cf09028566ff9fc2381'))a
where  a.WORKID = b.work_id_ ;    

优化2:

改写SQL,性能已经到了70毫秒左右.  
select b.biz_title_ from t_jzwf_biz_info b
where b.work_id_ in(select w.workid
from V_HZ_HAS_TODO_TASKLIST w
where w.flowid = 'ZBLC'
and (w.auth_id = '3a0d5619e34c4cf09028566ff9fc2381'
or w.AGENT_ID = '3a0d5619e34c4cf09028566ff9fc2381'));

你可能感兴趣的:(informix技术,数据库)