ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 临时表的undo生成

临时表的undo生成

原创 Linux操作系统 作者:yangtingkun 时间:2010-11-13 23:55:21 0 删除 编辑

临时表的redo生成要比普通表少的多,但是undo的产生并不比普通表少。

 

 

通过一个简单的例子说明:

SQL> create global temporary table t_temp
  2  (id number, name varchar2(30))
  3  on commit preserve rows;

表已创建。

SQL> create table t_normal
  2  (id number, name varchar2(30));

表已创建。

SQL> select sid
  2  from v$mystat
  3  where rownum = 1;

       SID
----------
       133

SQL> select value
  2  from v$statname a, v$sesstat b
  3  where a.statistic# = b.statistic#
  4  and a.name = 'undo change vector size '
  5  and b.sid = 133;

未选定行

SQL> select value
  2  from v$statname a, v$sesstat b
  3  where a.statistic# = b.statistic#
  4  and a.name = 'undo change vector size'
  5  and b.sid = 133;

     VALUE
----------
      3988

SQL> insert into t_normal
  2  select rownum, object_name
  3  from dba_objects;

已创建49081行。

SQL> commit;

提交完成。

SQL> select value
  2  from v$statname a, v$sesstat b
  3  where a.statistic# = b.statistic#
  4  and a.name = 'undo change vector size'
  5  and b.sid = 133;

     VALUE
----------
    135232

SQL> insert into t_temp
  2  select rownum, object_name
  3  from dba_objects;

已创建49081行。

SQL> commit;

提交完成。

SQL> select value
  2  from v$statname a, v$sesstat b
  3  where a.statistic# = b.statistic#
  4  and a.name = 'undo change vector size'
  5  and b.sid = 133;

     VALUE
----------
    254240

SQL> select 254240 - 135232 temp_table, 135232 - 3988 normal_table from dual;

TEMP_TABLE NORMAL_TABLE
---------- ------------
    119008       131244

可以看到,临时表和普通表产生的undo数据没有太多的差别,而实际上临时表的插入产生的redo信息也是undo信息对应的redo。

SQL> insert /*+ append */ into t_temp
  2  select *
  3  from t_temp;

已创建49081行。

SQL> commit;

提交完成。

SQL> select value
  2  from v$statname a, v$sesstat b
  3  where a.statistic# = b.statistic#
  4  and a.name = 'undo change vector size'
  5  and b.sid = 133;

     VALUE
----------
    254408

SQL> insert /*+ append */ into t_normal
  2  select *
  3  from t_normal;

已创建49081行。

SQL> commit;

提交完成。

SQL> select value
  2  from v$statname a, v$sesstat b
  3  where a.statistic# = b.statistic#
  4  and a.name = 'undo change vector size'
  5  and b.sid = 133;

     VALUE
----------
    256468

SQL> select 254408 - 254240 temp_table, 256468 - 254408 normal_table from dual;

TEMP_TABLE NORMAL_TABLE
---------- ------------
       168         2060

对于append方式插入,普通表和临时表都会产生少量的undo,而临时表相对会更少一些。

 

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

请登录后发表评论 登录
全部评论
暂无介绍

注册时间:2007-12-29

  • 博文量
    1964
  • 访问量
    11085795