標籤:append parallel nologging
大量資料快速插入方法探究
快速插入千萬層級的資料,無非就是nologging+parallel+append。
1 環境搭建
構建一個千萬層級的源表,向一個空表insert操作。
參考指標:insert動作完成的實際時間。
SQL> drop table test_emp cascadeconstraints purge;Table dropped.SQL> create table test_emp as select *from emp;Table created.SQL> begin 2 for i in 1..10 loop 3 insert into test_emp select *from test_emp; --批量dml,建議forall 4 end loop; 5 end; 6 /PL/SQL procedure successfully completed.SQL> select count(*) from test_emp; COUNT(*)---------- 14336SQL> begin 2 for i in 1..10 loop 3 insert into test_emp select *from test_emp; 4 end loop 5 ; 6 end; 7 /PL/SQL procedure successfully completed.SQL> select count(*) from test_emp; COUNT(*)---------- 14680064 --1.5千萬層級
2 only append
SQL> set timing onSQL> show timingtiming ONSQL> insert /*+ append */ into test_goalselect * from test_emp;14680064 rows created.
Elapsed: 00:00:20.72
沒有關閉日誌,所以時間是最長的。
3 append+nologging
SQL> truncate table test_goal;Table truncated.Elapsed: 00:00:00.11SQL> insert /*+ append */ into test_goalselect * from test_emp nologging;14680064 rows created.
Elapsed: 00:00:04.82
發現日誌對插入的影響很大,加nologging時間明顯大幅縮短;當然這個表沒有索引、約束等,這裡暫不考究。
4 append+nologging+parallel
SQL> truncate table test_goal;Table truncated. Elapsed: 00:00:00.09SQL> insert /*+ parallel(2) append */into test_goal select * from test_emp nologging;14680064 rows created.
Elapsed: 00:00:02.86
這裡在3的基礎上加上並行,效能基本達到極限,1.5千萬資料插入時間控制在3S左右。並行在伺服器效能支援的情況下,可以加大並行參數。
本文出自 “90SirDB” 部落格,請務必保留此出處http://90sirdb.blog.51cto.com/8713279/1794367
大量資料快速插入方法探究[nologging+parallel+append]