關於全域性臨時表DML特性案例體現

eBusinessMan發表於2014-09-24
基於事務的全域性臨時表: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部落格 ” ,連結:http://blog.itpub.net/29900383/viewspace-1279572/,如需轉載,請註明出處,否則將追究法律責任。

相關文章