执行计划SQL写法差异改变之insert all

/*
  性能上来看,insert all不一定会有优势,但是如果分开写和合并写不等价的时候,分开写要很麻烦,比如锁表,
  比如中间表,这样性能就要比insert all差多了!
  insert all 的执行计划有其关键字:
MULTI-TABLE INSERT
 
*/
      
drop table t1 purge;
create table t1 as select  * from dba_objects where 1=2;


drop table  t2 purge;
create  table t2 as select * from dba_objects where 1=2;


drop table t purge;
create  table t as select * from dba_objects;


set linesize 1000
set pagesize 2000
set autotrace off
ALTER SESSION SET statistics_level = all;
insert  into  t1 select * from t;
SELECT * FROM table(dbms_xplan.display_cursor(null,null,'allstats last'));   


PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------
SQL_ID  d4y6zf9bsqk1b, child number 0
-------------------------------------
insert  into  t1 select * from t
Plan hash value: 1601196873
-------------------------------------------------------------------------------------------
| Id  | Operation                | Name | Starts | E-Rows | A-Rows |   A-Time   | Buffers |
-------------------------------------------------------------------------------------------
|   0 | INSERT STATEMENT         |      |      1 |        |      0 |00:00:00.15 |   10935 |
|   1 |  LOAD TABLE CONVENTIONAL |      |      1 |        |      0 |00:00:00.15 |   10935 |
|   2 |   TABLE ACCESS FULL      | T    |      1 |  74811 |  73107 |00:00:00.02 |    1047 |
-------------------------------------------------------------------------------------------
Note
-----
   - dynamic sampling used for this statement (level=2)
      


set linesize 1000
set pagesize 2000
set autotrace off
ALTER SESSION SET statistics_level = all;            
insert  into  t2 select * from t;
SELECT * FROM table(dbms_xplan.display_cursor(null,null,'allstats last'));   


PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------
SQL_ID  0gp802wd8kvj6, child number 0
-------------------------------------
insert  into  t2 select * from t


Plan hash value: 1601196873
-------------------------------------------------------------------------------------------
| Id  | Operation                | Name | Starts | E-Rows | A-Rows |   A-Time   | Buffers |
-------------------------------------------------------------------------------------------
|   0 | INSERT STATEMENT         |      |      1 |        |      0 |00:00:00.17 |   10935 |
|   1 |  LOAD TABLE CONVENTIONAL |      |      1 |        |      0 |00:00:00.17 |   10935 |
|   2 |   TABLE ACCESS FULL      | T    |      1 |  74811 |  73107 |00:00:00.02 |    1047 |
-------------------------------------------------------------------------------------------
Note
-----
   - dynamic sampling used for this statement (level=2)
   

---假如T表的数据不会变化,看如下语句(如果T表数据会变化,那上述语句合并成如下是不等价的)   


set linesize 1000
set pagesize 2000
set autotrace off
ALTER SESSION SET statistics_level = all;
rollabck;
insert all 
   into  t1
   into  t2
select * from t;


SELECT * FROM table(dbms_xplan.display_cursor(null,null,'allstats last'));   
SQL> SELECT * FROM table(dbms_xplan.display_cursor(null,null,'allstats last'));


PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------
SQL_ID  795gsytaz3bkt, child number 0
-------------------------------------
insert all    into  t1    into  t2 select * from t


Plan hash value: 1563282152
-----------------------------------------------------------------------------------------------
| Id  | Operation           | Name | Starts | E-Rows | A-Rows |   A-Time   | Buffers | Reads  |
-----------------------------------------------------------------------------------------------
|   0 | INSERT STATEMENT    |      |      1 |        |      0 |00:00:00.42 |   25858 |    734 |
|   1 |  MULTI-TABLE INSERT |      |      1 |        |      0 |00:00:00.42 |   25858 |    734 |
|   2 |   TABLE ACCESS FULL | T    |      1 |  74811 |  73107 |00:00:00.16 |    1047 |    734 |
-----------------------------------------------------------------------------------------------
Note
-----
   - dynamic sampling used for this statement (level=2)
已选择18行。
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值