LS@LEO> set autotrace trace stat;
LS@LEO> insert /*+ append */ into leo_t5 select * from leo_t6; 直接加载,但表上没有索引
10340 rows created.
Statistics 统计信息
----------------------------------------------------------
111 recursive calls
175 db block gets
81 consistent gets
15 physical reads
36816 redo size 36816 redo量
664 bytes sent via SQL*Net to client
585 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
2 sorts (memory)
0 sorts (disk)
10340 rows processed
LS@LEO> create index leo_t5_index on leo_t5(object_id); 给表创建索引
Index created.
LS@LEO> rollback; 回滚
Rollback complete.
LS@LEO> insert /*+ append */ into leo_t5 select * from leo_t6; 直接加载,但表上有索引
10340 rows created.
Statistics 统计信息
----------------------------------------------------------
120 recursive calls
193 db block gets
85 consistent gets
22 physical reads
37344 redo size 37344 redo量
664 bytes sent via SQL*Net to client
585 bytes received via SQL*Net from client
4 SQL*Net roundtrips to/from client
3 sorts (memory)
0 sorts (disk)
10340 rows processed
小结:因为有了索引,直接加载redo量比没有索引时有一定的提升,可能是我的测试数据少所以这种提升并不明显,如果在实际生产库上发生了大量的redo,建议先将索引drop,加载数据后,在重建rebuild索引
(11)直接加载和并行
直接加载和并行是可以一起使用的,以此大幅度提高sql执行效率
LS@LEO> alter session enable parallel dml; 设置会话并行度
Session altered.
LS@LEO> alter session set events '10046 trace name context forever,level 12'; 使用trace文件跟踪sql性能指标
Session altered.
LS@LEO> insert /*+ append parallel(leo_t5,2) */ into leo_t5 select * from leo_t6; 直接加载+并行插入
10340 rows created.
LS@LEO> rollback;
Rollback complete.
LS@LEO> insert /*+ parallel(leo_t5,2) */ into leo_t5 select * from leo_t6; 并行插入
10340 rows created.
LS@LEO> rollback;
Rollback complete.
LS@LEO> insert /*+ append */ into leo_t5 select * from leo_t6; 直接加载
10340 rows created.
LS@LEO> rollback;
Rollback complete.
LS@LEO> insert into leo_t5 select * from leo_t6; 什么特性也没有用
10340 rows created.
LS@LEO> commit; 提交
Commit complete.
[Oracle@secdb1 udump]$ tkprof leo_ora_20558.trc leo.txt sys=no 格式化trace文件
TKPROF: Release 10.2.0.1.0 - Production on Sun Aug 5 22:13:38 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
insert /*+ append parallel(leo_t5,2) */ into leo_t5 select * from leo_t6
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.01 0 1 0 0
Execute 1 0.03 2.51 8 46 67 10340
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.04 2.53 8 47 67 10340
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 27
Rows Row Source Operation
------- ---------------------------------------------------
2 PX COORDINATOR (cr=46 pr=0 pw=0 time=2201632 us)
0 PX SEND QC (RANDOM) :TQ10001 (cr=0 pr=0 pw=0 time=0 us)
0 LOAD AS SELECT (cr=0 pr=0 pw=0 time=0 us)
0 BUFFER SORT (cr=0 pr=0 pw=0 time=0 us)
0 PX RECEIVE (cr=0 pr=0 pw=0 time=0 us)
0 PX SEND ROUND-ROBIN :TQ10000 (cr=0 pr=0 pw=0 time=0 us)
10340 TABLE ACCESS FULL LEO_T6 (cr=42 pr=0 pw=0 time=1356361 us)
insert /*+ parallel(leo_t5,2) */ into leo_t5 select * from leo_t6
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.01 0 1 0 0
Execute 1 0.02 1.66 7 44 64 10340
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.02 1.67 7 45 64 10340
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 27
Rows Row Source Operation
------- ---------------------------------------------------
2 PX COORDINATOR (cr=44 pr=0 pw=0 time=1209712 us)
0 PX SEND QC (RANDOM) :TQ10001 (cr=0 pr=0 pw=0 time=0 us)
0 LOAD AS SELECT (cr=0 pr=0 pw=0 time=0 us)
0 BUFFER SORT (cr=0 pr=0 pw=0 time=0 us)
0 PX RECEIVE (cr=0 pr=0 pw=0 time=0 us)
0 PX SEND ROUND-ROBIN :TQ10000 (cr=0 pr=0 pw=0 time=0 us)
10340 TABLE ACCESS FULL LEO_T6 (cr=42 pr=0 pw=0 time=186185 us)
insert /*+ append */ into leo_t5 select * from leo_t6
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 1 0 0
Execute 1 0.06 0.24 62 113 373 10340
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.06 0.24 62 114 373 10340
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 27
Rows Row Source Operation
------- ---------------------------------------------------
1 LOAD AS SELECT (cr=113 pr=62 pw=39 time=241775 us)
10340 TABLE ACCESS FULL LEO_T6 (cr=42 pr=0 pw=0 time=62104 us) 没有使用并行操作
insert into leo_t5 select * from leo_t6
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.00 0.00 0 43 0 0
Execute 1 0.14 0.54 100 101 1022 10340
Fetch 0 0.00 0.00 0 0 0 0
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 2 0.15 0.55 100 144 1022 10340
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 27
Rows Row Source Operation
------- ---------------------------------------------------
10340 TABLE ACCESS FULL LEO_T6 (cr=42 pr=0 pw=0 time=744520 us) 只有全表扫描
小结:insert /*+ append parallel(leo_t5,2) */ into leo_t5 select * from leo_t6和insert /*+ parallel(leo_t5,2) */ into leo_t5 select * from leo_t6执行计划是一样的,因为当使用parallel并行插入时,oracle默认使用直接加载方式来加载数据,因此append关键字可忽略了。
注:如果执行alter session disable parallel dml; oracle就会禁用DML并行操作,就算有hint提示也不会起作用,那么insert /*+ append parallel(leo_t5,2) */和insert /*+ append */的执行计划都应该是一样的了,都是只有直接加载,没有并行效果了
