说明:test_target表中的数据是3000多条,test_target表中的是2500万条.怎么优化下面语句,让执行效率变的更高.update test_target t1
set (t1.togetvalues,t1.algetvalues,t1.nogetvalue) = 
    (select t2.togetvalues,t2.algetvalues,t2.nogetvalue
     from test_source t2,test_target t3
     where  t2.company_id = 6070000
     and t2.company_id = t3.company_id
     and t2.id = t3.id 
     and t2.check_date_id = t3.check_date_id
     and t2.relationid = t3.relationid
     and t2.dept_id = t3.dept_id
     and t2.sub_id = t3.sub_id
     and t3.pay_detail_id = t1.pay_detail_id) 
where t1.pay_detail_id =
(select t5.pay_detail_id
     from test_source t4,test_target t5
     where t4.company_id = 6070000
     and t4.company_id = t5.company_id
     and t4.id = t5.id 
     and t4.check_date_id = t5.check_date_id
     and t4.relationid = t5.relationid
     and t4.dept_id = t5.dept_id
     and t4.sub_id = t5.sub_id
     and t5.pay_detail_id = t1.pay_detail_id)

解决方案 »

  1.   

    这句话有点问题:
    test_target表中的数据是3000多条,test_target表中的是2500万条试一下:
    ....
    where t1.pay_detail_id in  --变更
    (select t5.pay_detail_id 
         from test_source t4,test_target t5 
         where t4.company_id = 6070000 
         and t4.company_id = t5.company_id 
         and t4.id = t5.id  
         and t4.check_date_id = t5.check_date_id 
         and t4.relationid = t5.relationid 
         and t4.dept_id = t5.dept_id 
         and t4.sub_id = t5.sub_id 
         --and t5.pay_detail_id = t1.pay_detail_id --删除
     )
      

  2.   

    谢谢楼上提醒,弄错了,应该是test_source表中的数据是3000多条,test_target表中的是2500万条
      

  3.   


    update test_target t1 
    set (t1.togetvalues,t1.algetvalues,t1.nogetvalue) =  
        (select t2.togetvalues,t2.algetvalues,t2.nogetvalue 
         from test_source t2 
         where  t2.company_id = 6070000 
         and t2.company_id = t1.company_id 
         and t2.id = t1.id  
         and t2.check_date_id = t1.check_date_id 
         and t2.relationid = t1.relationid 
         and t2.dept_id = t1.dept_id 
         and t2.sub_id = t1.sub_id 
         and t2.pay_detail_id = t1.pay_detail_id)  
    where exists 
        (select 1 
         from test_source t2 
         where  t2.company_id = 6070000 
         and t2.company_id = t1.company_id 
         and t2.id = t1.id  
         and t2.check_date_id = t1.check_date_id 
         and t2.relationid = t1.relationid 
         and t2.dept_id = t1.dept_id 
         and t2.sub_id = t1.sub_id 
         and t2.pay_detail_id = t1.pay_detail_id)