ITPub博客

首页 > Linux操作系统 > Linux操作系统 > insert 比较

insert 比较

原创 Linux操作系统 作者:frog-qs 时间:2010-05-11 15:24:41 0 删除 编辑

今天做了个测试测试insert速度

比较了insert 在logging,nologging,/*+APPEND*/ nologging下的速度

 

 

建立一个上千万行的表

SQL> select count(*) from (select * from frog);

 

  COUNT(*)

----------

12735232

 

 

以logging方式向表插入数据,用时4分50秒

SQL> insert into t3 select * from t1;

 

12735232 rows created.

 

 

以nologging方式建立一个上千万的表,建立该表用时2分15秒

SQL> create table t1 nologging tablespace frog as select * from frog;

 

Table created.

 

SQL> select count(*) from (select * from t1);

 

  COUNT(*)

----------

  12735232

 

建立表,并将表设置为nologging模式,插入数据,用时1分13秒

SQL> create table t2 tablespace frog as select * from dba_objects where 1=2;

 

Table created.

 

SQL> select * from t2;

 

no rows selected

 

SQL> alter table t2 nologging;

 

Table altered.

 

SQL> insert /*+APPEND*/ into t2 select * from t1;

 

12735232 rows created.

 

 

 

insert append需要注意的一个小问题

用insert append可以实现直接路径加载,速度比常规加载方式快。但有一点需要注意: insert append时在表上加“6”类型的锁,会阻塞表上的所有DML语句。因此在有业务运行的情况下要慎重使用。若同时执行多个insert append对同一个表并行加载数据,并不一定会提高速度。因为每一时刻只能有一个进程在加载(排它锁造成)。

1. append方式添加记录对insert into ... values语句不起作用。
2.
以append方式批量插入的记录,其存储位置在hwm 之上,即使hwm之下存在空闲块也不能使用。
3.
以append方式插入记录后,要执行commit,才能对表进行查询。否则会出现错误:
ORA-12838:
无法在并行模式下修改之后读/修改对象
4.
在归档模式下,要把表设置为nologging,然后以append方式批量添加记录,才会显著减少redo数量。在非归档模式下,不必设置表的 nologging属性,即可减少redo数量。如果表上有索引,则append方式批量添加记录,不会减少索引上产生的redo数量,索引上的redo 数量可能比表的redo数量还要大
5.
同 nologging 配合会更快的,使用新的BLOCK 而不使用FREELIST中的块 增加插入速度,使用这个hint可以将数据使用直接路径插入到表的高水线之后,由于是连续的没有使用的空间,所以插入速度快。就是说直接插入,减少了搜索块的时间.


会在一定程度上造成空间浪费

请看oracle文挡中的描述:
APPEND
The APPEND hint lets you enable direct-path INSERT if your database is runningin serial mode. Your database is in serial mode if you are not using EnterpriseEdition. Conventional INSERT is the default in serial mode, and direct-pathINSERT is the default in parallel mode.
In direct-path INSERT, data is appended tothe end of the table, rather than using existing space currently allocated tothe table. As a result, direct-path INSERT can be considerably faster than conventionalINSERT.

SQL
语句中的优化提示
APPEND : Only valid for INSERT .. SELECT. Allows INSERT to work like directload or to perform parallel insert.

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22779291/viewspace-662438/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: DBA职业规划
请登录后发表评论 登录
全部评论

注册时间:2009-10-27

  • 博文量
    132
  • 访问量
    273852