大表全量update时采用表替换方式

刚开始时写的程序全表update,2张表数据都超过千万,速度超慢。
declare i int ;
begin
for i IN 0 .. 10
  loop
update (SELECT  /*+ BYPASS_UJVC */a.rowid, a.user_id , a.eparchy_code , b.user_id bbbb, b.eparchy_code cccc
  FROM  tf_b_tdiall a,crm_tf_f_user3 b
WHERE a.msisdn = b.serial_number and a.user_id is null
   AND b.remove_tag = '0' ) c
   set c.user_id = bbbb ,c.eparchy_code = cccc
   where rownum <100000;
commit;
end loop;
end ;

后来查了些资料,数据库在update时会记录大量的redo日志,造成极大的空间和时间上的浪费,解决方法可新建相同结构的一张表,然后采用insert和rename将表替换掉,整个过程1个小时以内就可以解决,而如果用上面的update,只怕几天都难以达到目的。
alter table TF_B_TDIALL_NEW nologging;

insert /*+ append */into TF_B_TDIALL_NEW
select a.TRADEID,a.MSISDN,a.IMEI,a.COMPANYNAME,a.TERMINALMODEL,a.SOFTWAREOS,
a.ISWCDMA,a.ISUMTS,a.ISHSDPA,a.ISHSUPA,a.ISGPRS,a.ISEDGE,a.ISWAP1,a.ISWAP2,a.ISMMS,
a.ISSTREAMING,a.ISSOUNDAAC,a.ISVIDEOAAC,a.ISMP3,a.FILE_NAME,a.INDB_TIME,a.MONTH,
a.IS_3G,b.USER_ID,b.EPARCHY_CODE,a.PARAM_VALUE4,a.PARAM_VALUE5 
from TF_B_TDIALL a,crm_tf_f_user1 b
where a.msisdn = b.serial_number and a.user_id is null
AND b.remove_tag = '0' ;

猜你喜欢

转载自mai511960247.iteye.com/blog/1523529