问题
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