CTAS VS create table and then insert
生活随笔
收集整理的這篇文章主要介紹了
CTAS VS create table and then insert
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
很多情況下我們都會需要復制源表數據以達到冗余數據的目的,那么到底是使用CREATE TABLE AS SELECT的CTAS方式,還是先建好表的結構然后再插入數據好呢? 我們來看看這2種方式的不同表現: SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for Linux: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - ProductionSQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 1
Next log sequence to archive 2
Current log sequence 2/* 數據庫處于歸檔模式下 */SQL> select ss.name,ms.value from v$mystat ms,v$sysstat ss2 where3 ms.statistic#=ss.statistic#4 and ss.name in ('undo change vector size','redo size');
NAME VALUE
---------------------------------------------------------------- ----------
redo size 0
undo change vector size 0SQL> create table YOUYUS as select * from dba_objects;
Table created.SQL> select ss.name,ms.value from v$mystat ms,v$sysstat ss2 where3 ms.statistic#=ss.statistic#4 and ss.name in ('undo change vector size','redo size');
NAME VALUE
---------------------------------------------------------------- ----------
redo size 5783384
undo change vector size 15408
/* CTAS方式產生了少量的undo,可以猜想其使用直接路徑方式插入,Oracle僅產生維護數據字典的undo */SQL> drop table YOUYUS;
Table dropped.SQL> conn / as sysdba
Connected./* 清理現場 */SQL> create table YOUYUS as select * from dba_objects where 0=1;
Table created.SQL> select ss.name,ms.value from v$mystat ms,v$sysstat ss2 where3 ms.statistic#=ss.statistic#4 and ss.name in ('undo change vector size','redo size');NAME VALUE
---------------------------------------------------------------- ----------
redo size 19492
undo change vector size 5680/* 建立空表YOUYUS,同樣需要維護數據字典 */SQL> insert into YOUYUS select * from dba_objects;50729 rows created.SQL> commit;Commit complete.SQL> select ss.name,ms.value from v$mystat ms,v$sysstat ss2 where3 ms.statistic#=ss.statistic#4 and ss.name in ('undo change vector size','redo size');NAME VALUE
---------------------------------------------------------------- ----------
redo size 5743540
undo change vector size 203904/* 普通insert操作產生了遠大于CTAS的undo */SQL> drop table YOUYUS;
Table dropped.SQL> conn / as sysdba
Connected.SQL> select ss.name,ms.value from v$mystat ms,v$sysstat ss2 where3 ms.statistic#=ss.statistic#4 and ss.name in ('undo change vector size','redo size');NAME VALUE
---------------------------------------------------------------- ----------
redo size 0
undo change vector size 0SQL> create table YOUYUS as select * from dba_objects where 0=1;
Table created.SQL> insert /*+ append */ into YOUYUS select * from dba_objects;
50729 rows created.SQL> commit;Commit complete.SQL> select ss.name,ms.value from v$mystat ms,v$sysstat ss2 where3 ms.statistic#=ss.statistic#4 and ss.name in ('undo change vector size','redo size');
NAME VALUE
---------------------------------------------------------------- ----------
redo size 5781712
undo change vector size 14808/* 建表后直接路徑插入方式與CTAS產生的redo和undo數量大致相仿 */
從資源消耗的角度講CTAS或直接路徑插入方式有一定優勢,如果啟用nologging選項的話這種優勢會更加顯著。
轉載于:https://www.cnblogs.com/macleanoracle/archive/2010/09/07/2967529.html
總結
以上是生活随笔為你收集整理的CTAS VS create table and then insert的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: WSS 扩展文件夹的属性--如何给文件夹
- 下一篇: 《ASCE1885的源码分析》の基于完成