一、使用create table as select * from table_name;
缺点:无法把默认值,索引等一同迁移过来。
SQL> select t.owner,t.index_name,t.index_type,t.table_owner,t.uniqueness,t.tablespace_name from dba_indexes t where t.owner='SCOTT' and t.table_name='EMP';
OWNER INDEX_NAME INDEX_TYPE TABLE_OWNER UNIQUENESS TABLESPACE_NAME
-------------------- ------------------------------ ------------------------------ -------------------- ------------------------------ ------------------------------
SCOTT PK_EMP NORMAL SCOTT UNIQUE USERS
QL> create table scott.emp_copy as select * from scott.emp;
.
Table created.
SQL> select t.owner,t.index_name,t.index_type,t.table_owner,t.uniqueness,t.tablespace_name from dba_indexes t where t.owner='SCOTT' and t.table_name='EMP_COPY';
no rows selected
二、使用HINT,并且表为nologging模式
SQL> set timing on;
SQL> INSERT /*+Append*/ INTO scott.emp_copy SELECT * FROM scott.emp;
14 rows created.
Elapsed: 00:00:00.03
SQL> commit;
Commit complete.
缺点:
1.insert /*+ append */ 时会对表加锁(排它锁),会阻塞表上的除了select以外所有DML语句;传统的DML在TM enqueue上使用模式3(row exclusive),其允许其他DML在相同的模式上获得TM enqueue。但是直接路径加载在TM enqueue使用模式6(exclusive),这使其他DML在直接路径加载期间将被阻塞。
2.因为insert /*+ append */ 从HWM的位置开始插入,也许会造成空间浪费。
3.insert /*+ append */ 在表处于logging同样会产生日志,可能不会有实质性的提高。
测试:
SQL> create or replace view redo_size
2 as
3 select value
4 from v$mystat, v$statname
5 where v$mystat.statistic# = v$statname.statistic#
6 and v$statname.name = 'redo size';
View created.
2.1使用LOGGING表,默认是启用。
SQL> create table testlogging as select * from dba_objects where 1=0;
Table created.
SQL> select * from redo_size;
VALUE
----------
213260764
SQL> INSERT INTO testlogging SELECT * FROM dba_objects;
72718 rows created.
SQL> commit;
Commit complete.
SQL> select * from redo_size;
VALUE
----------
221792892
SQL> INSERT /*+Append*/ INTO testlogging SELECT * FROM dba_objects;
72718 rows created.
SQL> commit;
Commit complete.
SQL> select * from redo_size;
VALUE
----------
230362872
SQL> select (221792892-213260764) redo_normal,(230362872-221792892)redo_append from dual;
REDO_NORMAL REDO_APPEND
----------- -----------
8532128 8569980
上面可以看到两种方式产生的REDO差不多,因此效率上没有实质提高 。
2.2使用hint和nologging表
SQL> create table testnologging nologging as select * from dba_objects where 1=0;
Table created.
SQL>
SQL> select * from redo_size;
VALUE
----------
195985096
SQL> INSERT INTO testnologging SELECT * FROM dba_objects;
72718 rows created.
SQL> commit;
Commit complete.
SQL> select * from redo_size;
VALUE
----------
204551384
SQL> INSERT /*+Append*/ INTO testnologging SELECT * FROM dba_objects;
72718 rows created.
SQL> select * from redo_size;
VALUE
----------
204570368
SQL> select (204551384-195985096) redo_normal,(204570368 - 204551384) redo_append from dual;
REDO_NORMAL REDO_APPEND
----------- -----------
8566288 18984
可以看出使用的HINT和NOLOGGING后,产生的REDO很少,因此插入效率会提高。
三、用EXP/IMP,略。
阅读(2180) | 评论(0) | 转发(0) |