基于事务的全局临时表:create global temporary table t_temp_transaction as select * from user_objects where 4=2;
普通表:create table t_temp_transaction as select * from user_objects where 4=2;
全局临时表和普通表在插入数据方面的耗能差异实践:
SQL> select SID ,ms.STATISTIC#,value "当前日志量" from v$mystat ms,v$statname sn where ms.STATISTIC#
= sn.statistic# and name = 'redo size';
SID STATISTIC# 当前日志量
---------- ---------- ----------
70 169 1744
SQL> insert into t_temp_transaction
2 select * from user_objects;
已创建20行。
SQL> select SID ,ms.STATISTIC#,value "当前日志量" from v$mystat ms,v$statname sn where ms.STATISTIC#
= sn.statistic# and name = 'redo size';
SID STATISTIC# 当前日志量
---------- ---------- ----------
70 169 2072
SQL> insert into t_normal
2 select * from user_objects;
已创建20行。
SQL> select SID ,ms.STATISTIC#,value "当前日志量" from v$mystat ms,v$statname sn where ms.STATISTIC#
= sn.statistic# and name = 'redo size';
SID STATISTIC# 当前日志量
---------- ---------- ----------
70 169 10740
由(2072-1744)和(10740-2072)的差异,可以看出全局临时表和普通表再insert方面的性能差异实在悬殊!
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
全局临时表两种删除数据方式的耗能差异实践:
全局临时表的delete操作产生的日志:
SQL> select SID ,ms.STATISTIC#,value "当前日志量" from v$mystat ms,v$statname sn where ms.STATISTIC#
=sn.statistic# and name = 'redo size';
SID STATISTIC# 当前日志量
---------- ---------- ----------
10 169 105868
SQL> delete from t_temp_transaction;
已删除20480行。
SQL> select SID ,ms.STATISTIC#,value "当前日志量" from v$mystat ms,v$statname sn where ms.STATISTIC#
=sn.statistic# and name = 'redo size';
SID STATISTIC# 当前日志量
---------- ---------- ----------
10 169 5978580
可以看出:两次日志量的差异是: 5978580-105868=5872712
全局临时表的commit操作产生的日志:
SQL> select SID ,ms.STATISTIC#,value "当前日志量" from v$mystat ms,v$statname sn where ms.STATISTIC#
=sn.statistic# and name = 'redo size';
SID STATISTIC# 当前日志量
---------- ---------- ----------
10 169 6293972
SQL> commit;
提交完成。
SQL> select count(*) from t_temp_transaction;
COUNT(*)
----------
0
SQL> select SID ,ms.STATISTIC#,value "当前日志量" from v$mystat ms,v$statname sn where ms.STATISTIC#
=sn.statistic# and name = 'redo size';
SID STATISTIC# 当前日志量
---------- ---------- ----------
10 169 6294096
可以看出:两次日志量的差异是:6294096-6293972=124
5872712和124相差多大,你们都看得见!!
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29900383/viewspace-1279572/
,如需转载,请注明出处,否则将追究法律责任。