Oracle数据库插入性能测试

发表于:2010-3-09 13:28

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:MKing(CSDNBlog)    来源:51Testing软件测试网采编

分享:

  采用服务器PL/SQL 方式插入10万条记录的测试结果如下:

  注:t_e1与t_employee同样的表结构

执行方式

说明

运行时间(单位:秒)

pl/sql insert(脚本1

普通insert

3.203

pl/sql forall insert(脚本2)

从一个表BULK COLLECT INTO到目标表

0.578

insert into select *(脚本3

使用insert into select方式插入

0.156

insert /*+ append*/  into select *(脚本4

append hint的插入

0.234

  从测试结果分析,采用insert into select 的方式最快,只要0.156s,根据数据量统计,平均每行大小为134字节,总共插入数据量为134*100000=12.78MB,可得每秒约插入81MB的数据,基本上达到了硬盘的上限。

  而采用append hint插入反而更慢,从同事讨论结果得到,采用append的insert会采用direct-path插入,因此数据会直接写入数据文件,所以消耗的时间更多。

--------------------------------------------脚本1--------------

declare
  i integer;
begin
  for i in 1 .. 100000 loop
    insert into t_employee
      (id,
       name,
       birthday,
       address,
       email,
       mobilephone,
       telephone,
       identity_card,
       weight,
       height)
    values
      (
      seq_t_employee_id.nextval,
       '张三' || i,
       sysdate - i,
       '上海市南京东路11号203室' || i,
       'abcd' || i || '@gmail.com',
       '138' || trim(to_char(i, '00000000')),
       '021-' || trim(to_char(i, '00000000')),
       '3504561980' || trim(to_char(i, '00000000')),
       64,
       1.72);
  end loop;
  commit;
end;

--------------------------------------------脚本2--------------

DECLARE
  TYPE table_t_employee IS TABLE OF t_employee%ROWTYPE;
  v_table table_t_employee;
BEGIN
  SELECT * BULK COLLECT INTO v_table FROM t_employee;
  FORALL idx IN 1 .. v_table.COUNT
    INSERT INTO t_e1 VALUES v_table (idx);
  COMMIT;
END;

--------------------------------------------脚本3--------------

insert into t_e1  select * from t_employee

--------------------------------------------脚本4--------------

insert /*+ append*/  into t_e1  select * from t_employee

33/3<123
100家互联网大公司java笔试题汇总,填问卷领取~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2023
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号