我尝试使用新数据更新旧客户数据,所以基本上我使用new_customer_source表的firstname和lastname更新old_customer_source表的firstname和lastname。
我索引了new_customer_source的custid,但我没有权限索引old_customer_source的custid。
要更新的总记录大约为50k,他们查询的时间超过30分钟!
您对如何改进下面给定的Oracle查询有任何建议吗?
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
)
答案 0 :(得分:2)
尝试使用合并。
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
;