数据库中如何实现大量数据快速插入方法
这篇文章将为大家详细讲解有关数据库中如何实现大量数据快速插入方法,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
1环境搭建构建一个千万级别的源表,向一个空表insert操作。
参考指标:insert动作完成的实际时间。
SQL>droptabletest_empcascadeconstraintspurge;Tabledropped.SQL>createtabletest_empasselect*fromemp;Tablecreated.SQL>begin2foriin1..10loop3insertintotest_empselect*fromtest_emp;--批量dml,建议forall4endloop;5end;6/PL/SQLproceduresuccessfullycompleted.SQL>selectcount(*)fromtest_emp;COUNT(*)----------14336SQL>begin2foriin1..10loop3insertintotest_empselect*fromtest_emp;4endloop5;6end;7/PL/SQLproceduresuccessfullycompleted.SQL>selectcount(*)fromtest_emp;COUNT(*)----------14680064--1.5千万级别2only append
SQL>settimingonSQL>showtimingtimingONSQL>insert/*+append*/intotest_goalselect*fromtest_emp;14680064rowscreated.
Elapsed: 00:00:20.72
没有关闭日志,所以时间是最长的。
3append+nologgingSQL>truncatetabletest_goal;Tabletruncated.Elapsed:00:00:00.11SQL>insert/*+append*/intotest_goalselect*fromtest_empnologging;14680064rowscreated.
Elapsed: 00:00:04.82
发现日志对插入的影响很大,加nologging时间明显大幅缩短;当然这个表没有索引、约束等,这里暂不考究。
4append+nologging+parallelSQL>truncatetabletest_goal;Tabletruncated.Elapsed:00:00:00.09SQL>insert/*+parallel(2)append*/intotest_goalselect*fromtest_empnologging;14680064rowscreated.
Elapsed: 00:00:02.86
这里在3的基础上加上并行,性能基本达到极限,1.5千万数据插入时间控制在3S左右。并行在服务器性能支持的情况下,可以加大并行参数。
关于“数据库中如何实现大量数据快速插入方法”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。