insert /*+append*/为何会提升性能

    在上一篇的blog中 作了下使用,在归档和非归档下,作数据插入http://blog.csdn.net/guogang83/article/details/9219479。结论是在非归档模式下表设置为nologging用insert /*+append*/速度最快。那为何快呢,原理是什么?下面咱们来一块儿作一个实验:c#

 

SQL> create or replace view m_undo_redo as
    select  v$statname.name,value
    from v$mystat, v$statname
    where v$mystat.statistic# =v$statname.statistic#
       and (v$statname.name ='redo size'
      or v$statname.name = 'undo change vector size');app

视图已建立。spa

SQL> create table t (x  int);.net

表已建立。blog

SQL> set timing on
SQL> select * from m_undo_redo;ci

NAME                                                                  VALUE
---------------------------------------------------------------- ----------
redo size                                                             22644
undo change vector size                                                7484get

SQL> insert into t select rownum from dual connect by level <=1000000;it

已建立1000000行。table

已用时间:  00: 00: 01.03
SQL> commit;原理

提交完成。

SQL> select * from m_undo_redo;

NAME                                                                  VALUE
---------------------------------------------------------------- ----------
redo size                                                          15722456
undo change vector size                                 2380000

SQL> select (2380000-7484) undo,(15722456-22644) redo from dual;

      UNDO       REDO
---------- ----------
   2372516   15699812

SQL> truncate table t;

表被截断。

SQL> select * from m_undo_redo;

NAME                                                                  VALUE
---------------------------------------------------------------- ----------
redo size                                                          15781532
undo change vector size                                 2396672

SQL> insert /*+append*/ into t select rownum from dual connect by level <=1000000;

已建立1000000行。

已用时间:  00: 00: 00.96
SQL> commit;

提交完成。

SQL> select * from m_undo_redo;

NAME                                                                  VALUE
---------------------------------------------------------------- ----------
redo size                                                          15871640
undo change vector size                                 2419196

SQL> select (2419196-2396672) undo,(15871640-15781532) redo from dual;

      UNDO       REDO
---------- ----------
     22524      90108

两次的对比:

 

      模式

生成undo 

生成redo

普通insert  2372516  15699812
insert /*+append*/ 22524 90108

 

       分析结论:两次对比的结果表示用insert /*+append*/后,数据的undo和redo没有生成。由于HWM 在移动的过程当中,这些block是不能被其余process使用的,那么意味着,只要记录下该次direct insert所涉及到的空间的redo 和 undo  ,在失败回滚的时候,只须要把这些空间修改成原来的状态就能够,而不用逐个记录去delete。

 

来源:http://blog.csdn.net/stevendbaguo/article/details/9241481

相关文章
相关标签/搜索