insert /*+append*/为什么会提高性能

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

 

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');

视图已创建。

SQL> create table t (x  int);

表已创建。

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

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

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

已创建1000000行。

已用时间:  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

posted @ 2017-11-24 20:24  jack_ou  阅读(3946)  评论(0编辑  收藏  举报