update dt_allotapply_detaildb 
set dt_allotapply_detaildb.userlock = '0000008050' 
where (dt_allotapply_detaildb.userlock is null)
and exists(select 'A' from dt_allotapply_headerdb
where (dt_allotapply_detaildb.allotapplyno = dt_allotapply_headerdb.allotapplyno) 
and (dt_allotapply_headerdb.billdateint >= 38836)
and (dt_allotapply_headerdb.billdateint <= 38854) 
and (dt_allotapply_headerdb.companyid = '0000000013') 
and (dt_allotapply_headerdb.deptid = '0000008689')) 
and (dt_allotapply_detaildb.allotno is null or dt_allotapply_detaildb.allotno = '') 
and exists(select 'A' from dt_product_cntldb a  
where (dt_allotapply_detaildb.productid = a.productid) 
and (a.companyid = '0000009121')
and (a.ctrlcompanyid = '0000000013'))其中dt_allotapply_detaildb是明细表,dt_allotapply_headerdb是主表,明细表越180万条记录,个人感觉是第一个exists语句造成的性能问题,不知各位高手有什么解决办法,很着急,谢谢!

解决方案 »

  1.   

    1。写个存储过程,在游标中根据条件来进行update
    2。字符串比较相对于数值比较慢,那几个带前置0的字段为何不to_number后再和数值比较呢?
      

  2.   

    可以看一下执行计划,如果是exists造成的可以在表 dt_allotapply_headerdb的allotapplyno字段上加一索引
      

  3.   

    如果没办法优化,可尝试简化查询sql,部分筛选逻辑在代码中实现,对结果集中进行处理。只要返回你想要的结果就OK。
      

  4.   

    看过执行计划了,其中有一个对detail表的全表扫描,应该是update的时候造成的
      

  5.   

    将符合productid 条件的创建一个临时表temp;
    然后关联临时表进行updateupdate dt_allotapply_detaildb a
    set a.userlock = '0000008050' 
    where exists (select 1 from temp b where a.productid =b.productid )
    这样服务器压力就小多了,也不需要运算那么多次,update本身就是很慢的操作再关联那么多条件当然很慢了。
      

  6.   

    既然是对detail表进行了full table scan, 可以根据条件在此表上建索引