温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

数据库中如何实现大量数据快速插入方法

发布时间:2021-11-11 09:55:02 来源:亿速云 阅读:900 作者:小新 栏目:数据库

这篇文章将为大家详细讲解有关数据库中如何实现大量数据快速插入方法,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

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(*)
----------
    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千万级别

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

没有关闭日志,所以时间是最长的。

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

发现日志对插入的影响很大,加nologging时间明显大幅缩短;当然这个表没有索引、约束等,这里暂不考究。

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的基础上加上并行,性能基本达到极限,1.5千万数据插入时间控制在3S左右。并行在服务器性能支持的情况下,可以加大并行参数。

关于“数据库中如何实现大量数据快速插入方法”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI