今天听DBA说如果从一个表批量查询出一批数据之后批量插入另外一张表的优化方案:
1)不写归档日志;
2)采用独占
关于insert /*+ append */我们需要注意以下三点:
a、非归档模式下,只需append就能大量减少redo的产生;归档模式下,只有append+nologging才能大量减少redo。
b、insert /*+ append */时会对表加锁(排它锁),会阻塞表上的除了select以外所有DML语句;
1 --不写日志设置 2 ALTER TABLE my_flosta_all_571 NOLOGGING; 3 4 insert /*+APPEND */ into my_flosta_all_571(OID,P_DAY,CITY,BUILDINGID,BUILDINGNAME,HASINDOOR) 5 select OID,to_date('20180103','yyyyMMdd') as P_DAY,CITY,BUILDINGID,BUILDINGNAME,HASINDOOR 6 from my_flosta_all_571 where p_day=to_date('20171231','yyyyMMdd'); 7 commit; 8 9 insert /*+APPEND */ into my_flosta_all_571(OID,P_DAY,CITY,BUILDINGID,BUILDINGNAME,HASINDOOR) 10 select OID,to_date('20180104','yyyyMMdd') as P_DAY,CITY,BUILDINGID,BUILDINGNAME,HASINDOOR 11 from my_flosta_all_571 where p_day=to_date('20171231','yyyyMMdd'); 12 commit;