您的位置:首页 > 数据库 > Oracle

Oracle技术之临时表的undo生成

2013-06-19 10:22 211 查看
临时表的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,而临时表相对会更少一些。

oracle视频教程请关注:http://u.youku.com/user_video/id_UMzAzMjkxMjE2.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息