溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

數(shù)據(jù)庫(kù)中如何實(shí)現(xiàn)大量數(shù)據(jù)快速插入方法

發(fā)布時(shí)間:2021-11-11 09:55:02 來(lái)源:億速云 閱讀:905 作者:小新 欄目:數(shù)據(jù)庫(kù)

這篇文章將為大家詳細(xì)講解有關(guān)數(shù)據(jù)庫(kù)中如何實(shí)現(xiàn)大量數(shù)據(jù)快速插入方法,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

1     環(huán)境搭建

構(gòu)建一個(gè)千萬(wàn)級(jí)別的源表,向一個(gè)空表insert操作。

參考指標(biāo):insert動(dòng)作完成的實(shí)際時(shí)間。

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(*)
----------
    14336
SQL> 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千萬(wàn)級(jí)別

2     only append

SQL> set timing on
SQL> show timing
timing ON
SQL> insert /*+ append */ into test_goalselect * from test_emp;
14680064 rows created.

Elapsed: 00:00:20.72

沒(méi)有關(guān)閉日志,所以時(shí)間是最長(zhǎng)的。

3     append+nologging

SQL> truncate table test_goal;
Table truncated.
Elapsed: 00:00:00.11
SQL> insert /*+ append */ into test_goalselect * from test_emp nologging;
14680064 rows created.

Elapsed: 00:00:04.82

發(fā)現(xiàn)日志對(duì)插入的影響很大,加nologging時(shí)間明顯大幅縮短;當(dāng)然這個(gè)表沒(méi)有索引、約束等,這里暫不考究。

4     append+nologging+parallel

SQL> truncate table test_goal;
Table truncated.
 
Elapsed: 00:00:00.09
SQL> insert /*+ parallel(2) append */into test_goal select * from test_emp nologging;
14680064 rows created.

Elapsed: 00:00:02.86

這里在3的基礎(chǔ)上加上并行,性能基本達(dá)到極限,1.5千萬(wàn)數(shù)據(jù)插入時(shí)間控制在3S左右。并行在服務(wù)器性能支持的情況下,可以加大并行參數(shù)。

關(guān)于“數(shù)據(jù)庫(kù)中如何實(shí)現(xiàn)大量數(shù)據(jù)快速插入方法”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI