update i_tableName t
        set t.staffid = (select ci.custommgrid from T_ESL_HIGHCUSTOM ci where ci.acceptphone = t.acceptphone)
        ,t.EXTRACTSEQ = 'N' where t.updatesequence = :updateSequence
        and exists(select cii.ACCEPTPHONE from T_ESL_HIGHCUSTOM cii where cii.acceptphone = t.acceptphone);SQL如一所示,i_tableName这个表中大概有10W条数据,T_ESL_HIGHCUSTOM这个表400W数据,此条SQL中所用到的条件都带有索引,现在做性能测试时发现这个SQL的CPU利用率太高,想优化一下这个SQL,请各位大侠帮忙看一下,不胜感激。

解决方案 »

  1.   

    merge into i_tableName t 
    using T_ESL_HIGHCUSTOM ci
    on (
        ci.acceptphone = t.acceptphone
        and t.updatesequence = :updateSequence
    )when matched then 
       update set t.staffid = ci.custommgrid,t.EXTRACTSEQ = 'N'
      

  2.   

    分别执行ANALYZE TABLE T_ESL_HIGHCUSTOM COMPUTE STATISTICS与
    NALYZE TABLE i_tableName COMPUTE STATISTICS分析这两张表
      

  3.   

    update i_tableName t 
            set t.staffid = (select ci.custommgrid from T_ESL_HIGHCUSTOM ci where ci.acceptphone = t.acceptphone) 
            ,t.EXTRACTSEQ = 'N' where t.updatesequence = :updateSequence 
            and 1=(select count(*) from T_ESL_HIGHCUSTOM cii where cii.acceptphone = t.acceptphone and rownum<2); 
    (确定索引都正常的情况下.
    试一试这一个
      

  4.   


    贴个statspack reoprt上来看看。
      

  5.   

    可以把select ci.custommgrid ,ci.acceptphone from T_ESL_HIGHCUSTOM ci,i_tableName t  where ci.acceptphone = t.acceptphone AND t.updatesequence = :updateSequence 
    查询出来的值放到临时表中,然后再根据这个临时表(根据上述查询跳出来的,数据量肯定是小于10万的),来更新表i_tableName。  这样性能至少能提高一倍以上。