我正在爲插入更新操作執行下面的MERGE語句。具有超過200萬條記錄的Oracle合併語句的性能問題
它可以正常工作1到2百萬條記錄,但對於超過4到50億條記錄,需要6到7小時才能完成。
任何人都可以建議MERGE語句一些替代性或性能提示
merge into employee_payment ep
using (
select
p.pay_id vista_payroll_id,
p.pay_date pay_dte,
c.client_id client_id,
c.company_id company_id,
case p.uni_ni when 0 then null else u.unit_id end unit_id,
p.pad_seq pay_dist_seq_nbr,
ph.payroll_header_id payroll_header_id,
p.pad_id vista_paydist_id,
p.pad_beg_payperiod pay_prd_beg_dt,
p.pad_end_payperiod pay_prd_end_d
from
stg_paydist p
inner join company c on c.vista_company_id = p.emp_ni
inner join payroll_header ph on ph.vista_payroll_id = p.pay_id
left outer join unit u on u.vista_unit_id = p.uni_ni
where ph.deleted = '0'
) ps
on (ps.vista_paydist_id = ep.vista_paydist_id)
when matched then
update
set ep.vista_payroll_id = ps.vista_payroll_id,
ep.pay_dte = ps.pay_dte,
ep.client_id = ps.client_id,
ep.company_id = ps.company_id,
ep.unit_id = ps.unit_id,
ep.pay_dist_seq_nbr = ps.pay_dist_seq_nbr,
ep.payroll_header_id = ps.payroll_header_id
when not matched then
insert (
ep.employee_payment_id,
ep.vista_payroll_id,
ep.pay_dte,
ep.client_id,
ep.company_id,
ep.unit_id,
ep.pay_dist_seq_nbr,
ep.payroll_header_id,
ep.vista_paydist_id
) values (
seq_employee_payments.nextval,
ps.vista_payroll_id,
ps.pay_dte,
ps.client_id,
ps.company_id,
ps.unit_id,
ps.pay_dist_seq_nbr,
ps.payroll_header_id,
ps.vista_paydist_id
) log errors into errorlog (v_batch || 'EMPLOYEE_PAYMENT') reject limit unlimited;
4至5 _billions_非常高,您無法將其與1或2 _million_進行比較。 –
首先,該查詢中有五個表格 - 每個表格有多少行?其次,USING子句中查詢的性能如何? –
謝謝大衛,這是正確的,比較1-2百萬記錄不好,有4-5百萬。我期待的是我可以找到替代MERGE的5-7百萬條記錄的任何方式。目前與公司記錄 - 30K,單位-1235038和payroll_header = 12,95,65,175和真正沉重的SQL與這樣的音量 – user2819874