实验环境:
SYS@aaron> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for Linux: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
实验步骤:
1 首先创建一个原始表test01, 大小为504M
SEGMENT_NAME SEGMENT_TYPE TABLESPACE_NAME BLOCKS EXTENTS BYTES/1024/1024
-------------------- ------------------ ------------------------------ ---------- ---------- ---------------
TEST01 TABLE EXAMPLE 64512 134 504
2 使用create table test02 as select * from test01 创建表test02并观察执行时间 与产生的日志量
SYS@aaron> set timing on
SYS@aaron> create table test02 tablespace example as select * from test01;
Table created.
Elapsed: 00:00:14.70
SYS@aaron> alter system switch logfile
产生归档日志如下:
-rw-r----- 1 oracle oinstall963KDec 24 19:12 1_128_864773796.dbf
3 使用insert into table test02 as select * from test01, 观察效率与产生的日志量
SYS@aaron> drop table test02;
Table dropped.
SYS@aaron> create table test02 as select * from test01 where 0=1;
Table created.
SYS@aaron> alter system switch logfile;
System altered.
SYS@aaron> insert into test02 select * from test01;
4523648 rows created.
Elapsed: 00:02:12.30
产生的日志量为:
-rw-r----- 1 oracle oinstall 49M Dec 24 19:16 1_130_864773796.dbf
-rw-r----- 1 oracle oinstall 44M Dec 24 19:16 1_131_864773796.dbf
-rw-r----- 1 oracle oinstall 49M Dec 24 19:16 1_132_864773796.dbf
-rw-r----- 1 oracle oinstall 49M Dec 24 19:17 1_133_864773796.dbf
-rw-r----- 1 oracle oinstall 49M Dec 24 19:17 1_134_864773796.dbf
-rw-r----- 1 oracle oinstall 49M Dec 24 19:17 1_135_864773796.dbf
-rw-r----- 1 oracle oinstall 47M Dec 24 19:17 1_136_864773796.dbf
-rw-r----- 1 oracle oinstall 49M Dec 24 19:18 1_137_864773796.dbf
-rw-r----- 1 oracle oinstall 49M Dec 24 19:18 1_138_864773796.dbf
-rw-r----- 1 oracle oinstall 49M Dec 24 19:18 1_139_864773796.dbf
-rw-r----- 1 oracle oinstall 45M Dec 24 19:18 1_140_864773796.dbf
-rw-r----- 1 oracle oinstall 12K Dec 24 19:19 1_141_864773796.dbf
总结:使用create table as select *的方式更有效率 并且几乎不会产生归档日志。