Performance Issue when Updating Table from Another Table

▼魔方 西西 提交于 2019-12-13 18:46:33

问题


I'm trying to update old customers data with new data, so basically I'm updating firstname and lastname of old_customer_source table with firstname and lastname of new_customer_source table.

I indexed custid of new_customer_source but I don't have privileges to index old_customer_source's custid.

Total records to updated is ~50k and they query is taking over 30 mins to run!

Do you have any suggestions on how to improve the given Oracle query below?

update old_customer_source t1
   set   (t1.firstname, t1.lastname) = 
   (
    select  t2.firstname, t2.lastname
    from    new_customer_source t2
    where   t1.custid = t2.custid
   )
   where exists ( select 'x'
                from  new_customer_source t3
                where  t1.custid = t3.custid
              )

回答1:


Try to use merge.

merge into old_customer_source t1
using (select t2.custid, t2.firstname, t2.lastname
         from  new_customer_source t2
      ) t2
 on (t1.custid = t2.custid)
when matched then
update set t1.firstname = t2.firstname, 
           t1.lastname = t2.lastname
;


来源:https://stackoverflow.com/questions/26040593/performance-issue-when-updating-table-from-another-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!