tb_e_zw_nrllb_temp 量700225
gsm_user 量109398337
--优化前 两种update
--说明:gsm_user是视图存在GSM_USER_ID索引,tb_e_zw_nrllb_temp有user_id索引,使用以下两种方法都更新时间超5h+导致不能更新成功
--1
update tb_e_zw_nrllb_temp t
set t.msisdn = (select msisdn from from gsm_user a
where to_char(a.GSM_USER_ID) = b.user_id
and b.settle_month = p_month_id))
where .settle_month = p_month_id;
--2
merge into tb_e_zw_nrllb_temp t
using gsm_user a
on (to_char(a.GSM_USER_ID) = t.user_id )
when matched then
update set
t.msisdn = a.MSISDN
where t.settle_month = p_month_id;
commit;
--优化后
--优化后时间耗费主要在insert上,insert的select查询比较快,因此又想办法优化insert,大致如下
--修改insert表为nologging,使用 hint append,使用parallel,原本insert执行时间为25分钟,优化后执行时间为12分钟
execute immediate 'truncate table TB_E_ZW_NRLLB_TEMP_msisdn';
insert /*+ append*/ into TB_E_ZW_NRLLB_TEMP_msisdn
select a.GSM_USER_ID,a.MSISDN from gsm_user a
where exists (select 1 from tb_e_zw_nrllb_temp b
where to_char(a.GSM_USER_ID) = b.user_id
and b.settle_month = p_month_id) ;
commit;
sp_write_infolog('sp_sp_rep_sptc', '0', 'MSISDN临时表插入完成');
--update耗时不超一分钟
merge into tb_e_zw_nrllb_temp t
using (select distinct a.user_id,a.msisdn from TB_E_ZW_NRLLB_TEMP_msisdn a ) b
on (b.user_id = t.user_id )
when matched then
update set
t.msisdn = b.MSISDN
where t.settle_month = p_month_id;
commit;