如何让insert /*+ append */ 采用并行
展开全部
SQL> explain plan for insert /*+ append parallel(my 2) */ into my select * from ac01;
已解释。
已用时间: 00: 00: 00.16
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------------------
--------
Plan hash value: 2164050840
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------
| 0 | INSERT STATEMENT | | 1902K| 335M| 14813 (20)| 00:02:58 |
| 1 | LOAD AS SELECT | MY | | | | |
| 2 | TABLE ACCESS FULL| AC01 | 1902K| 335M| 14813 (20)| 00:02:58 |
---------------------------------------------------------------------------
已选择9行。
已用时间: 00: 00: 01.77
貌似insert部分,不能使用并行。select 部分是可以并行的。
SQL> explain plan for insert /*+ append */ into my select /*+ parallel(ac01 2) */ * from ac01;
已解释。
已用时间: 00: 00: 00.11
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
-----------------------------------------------------------------------------------------------------------------
--------
Plan hash value: 2135288090
---------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
---------------------------------------------------------------------------------------------------------------
| 0 | INSERT STATEMENT | | 1902K| 335M| 8068 (18)| 00:01:37 | | | |
| 1 | LOAD AS SELECT | MY | | | | | | | |
| 2 | PX COORDINATOR | | | | | | | | |
| 3 | PX SEND QC (RANDOM)| :TQ10000 | 1902K| 335M| 8068 (18)| 00:01:37 | Q1,00 | P->S | QC (RAND) |
| 4 | PX BLOCK ITERATOR | | 1902K| 335M| 8068 (18)| 00:01:37 | Q1,00 | PCWC | |
| 5 | TABLE ACCESS FULL| AC01 | 1902K| 335M| 8068 (18)| 00:01:37 | Q1,00 | PCWP | |
---------------------------------------------------------------------------------------------------------------
已选择12行。
已用时间: 00: 00: 00.64
和书里(Troubleshooting Oracle Performance)所说的不一样:
Execute the SQL statement in parallel. Note that in this case, both the INSERT and the
SELECT can be parallelized independently. To take advantage of direct-path inserts, at
least the INSERT part must be parallelized.
书里说,insert 和select都是可以并行的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1.append和并行同时使用时注意:
alter session enable parallel DML;
ALTER SESSION SET db_file_multiblock_read_count=128;
INSERT /+append parallel(b 2)/
并行:两个并行包括三个进程,有一个进程是负责调度的。
2.并行度
并行度与CPU和当前的负载有关
—cmd下执行
SQL> set autot trace
—-开并行的时候,Oracle会分配一组或两组Slave Set
–并行度4指的是Slave Set中的从属进程的数量。
SQL> select /+ parallel(t1,4) / * from t1 order by 1;
并行度是4,很有可能开八个进程。一组用来生产数据(select),一组用来消费数据(order by)
测试结果:
SQL> select * from v$pq_slave;
SLAVE_NAME STATUS SESSIONS IDLE_TIME_CUR BUSY_TIME_CUR CPU_SECS_CUR MSGS_SENT_CUR MSGS_RCVD_CUR IDLE_TIME_TOTAL BUSY_TIME_TOTAL CPU_SECS_TOTAL MSGS_SENT_TOTAL MSGS_RCVD_TOTAL
P000 IDLE 3 2 0 0 0 0 3 0 0 46 64
P001 IDLE 3 2 0 0 0 0 3 0 0 128 168
P002 IDLE 3 2 0 0 0 0 3 0 0 44 63
P003 IDLE 2 2 0 0 0 0 3 0 0 1242 1241
P004 IDLE 2 2 0 0 0 0 3 0 0 364 32
P005 IDLE 2 2 0 0 0 0 3 0 0 322 29
P006 IDLE 2 2 0 0 0 0 3 0 0 434 37
P007 IDLE 2 2 0 0 0 0 3 0 0 419 36
8 rows selected
—–IDLE是空闲状态,BUSY是忙碌状态,PMON进程会每隔一个时间去检查,如果发现是IDLE状态,就将进程关闭
SQL> select * from v$pq_slave;
SLAVE_NAME STATUS SESSIONS IDLE_TIME_CUR BUSY_TIME_CUR CPU_SECS_CUR MSGS_SENT_CUR MSGS_RCVD_CUR IDLE_TIME_TOTAL BUSY_TIME_TOTAL CPU_SECS_TOTAL MSGS_SENT_TOTAL MSGS_RCVD_TOTAL
开4个进程的测试结果:
—-cmd下执行
SQL> set autot trace
SQL> select /+ parallel(t1,4) / * from t1;
—-PLSQL DEV
SQL> select * from v$pq_slave;
SLAVE_NAME STATUS SESSIONS IDLE_TIME_CUR BUSY_TIME_CUR CPU_SECS_CUR MSGS_SENT_CUR MSGS_RCVD_CUR IDLE_TIME_TOTAL BUSY_TIME_TOTAL CPU_SECS_TOTAL MSGS_SENT_TOTAL MSGS_RCVD_TOTAL
P000 BUSY 4 0 0 0 173 13 0 0 0 219 77
P001 BUSY 4 0 0 0 187 14 0 0 0 315 182
P002 BUSY 4 0 0 0 176 13 0 0 0 220 76
P003 BUSY 3 0 0 0 174 13 0 0 0 1416 1254
SQL> select * from v$pq_slave;
SLAVE_NAME STATUS SESSIONS IDLE_TIME_CUR BUSY_TIME_CUR CPU_SECS_CUR MSGS_SENT_CUR MSGS_RCVD_CUR IDLE_TIME_TOTAL BUSY_TIME_TOTAL CPU_SECS_TOTAL MSGS_SENT_TOTAL MSGS_RCVD_TOTAL
P000 IDLE 4 0 0 0 0 0 0 0 0 226 78
P001 IDLE 4 0 0 0 0 0 0 0 0 322 183
P002 IDLE 4 0 0 0 0 0 0 0 0 238 78
P003 IDLE 3 0 0 0 0 0 0 0 0 1430 1256
select /+ parallel(t1,4) / object_id,count(*) from t1 group by object_id;
alter session enable parallel DML;
ALTER SESSION SET db_file_multiblock_read_count=128;
INSERT /+append parallel(b 2)/
并行:两个并行包括三个进程,有一个进程是负责调度的。
2.并行度
并行度与CPU和当前的负载有关
—cmd下执行
SQL> set autot trace
—-开并行的时候,Oracle会分配一组或两组Slave Set
–并行度4指的是Slave Set中的从属进程的数量。
SQL> select /+ parallel(t1,4) / * from t1 order by 1;
并行度是4,很有可能开八个进程。一组用来生产数据(select),一组用来消费数据(order by)
测试结果:
SQL> select * from v$pq_slave;
SLAVE_NAME STATUS SESSIONS IDLE_TIME_CUR BUSY_TIME_CUR CPU_SECS_CUR MSGS_SENT_CUR MSGS_RCVD_CUR IDLE_TIME_TOTAL BUSY_TIME_TOTAL CPU_SECS_TOTAL MSGS_SENT_TOTAL MSGS_RCVD_TOTAL
P000 IDLE 3 2 0 0 0 0 3 0 0 46 64
P001 IDLE 3 2 0 0 0 0 3 0 0 128 168
P002 IDLE 3 2 0 0 0 0 3 0 0 44 63
P003 IDLE 2 2 0 0 0 0 3 0 0 1242 1241
P004 IDLE 2 2 0 0 0 0 3 0 0 364 32
P005 IDLE 2 2 0 0 0 0 3 0 0 322 29
P006 IDLE 2 2 0 0 0 0 3 0 0 434 37
P007 IDLE 2 2 0 0 0 0 3 0 0 419 36
8 rows selected
—–IDLE是空闲状态,BUSY是忙碌状态,PMON进程会每隔一个时间去检查,如果发现是IDLE状态,就将进程关闭
SQL> select * from v$pq_slave;
SLAVE_NAME STATUS SESSIONS IDLE_TIME_CUR BUSY_TIME_CUR CPU_SECS_CUR MSGS_SENT_CUR MSGS_RCVD_CUR IDLE_TIME_TOTAL BUSY_TIME_TOTAL CPU_SECS_TOTAL MSGS_SENT_TOTAL MSGS_RCVD_TOTAL
开4个进程的测试结果:
—-cmd下执行
SQL> set autot trace
SQL> select /+ parallel(t1,4) / * from t1;
—-PLSQL DEV
SQL> select * from v$pq_slave;
SLAVE_NAME STATUS SESSIONS IDLE_TIME_CUR BUSY_TIME_CUR CPU_SECS_CUR MSGS_SENT_CUR MSGS_RCVD_CUR IDLE_TIME_TOTAL BUSY_TIME_TOTAL CPU_SECS_TOTAL MSGS_SENT_TOTAL MSGS_RCVD_TOTAL
P000 BUSY 4 0 0 0 173 13 0 0 0 219 77
P001 BUSY 4 0 0 0 187 14 0 0 0 315 182
P002 BUSY 4 0 0 0 176 13 0 0 0 220 76
P003 BUSY 3 0 0 0 174 13 0 0 0 1416 1254
SQL> select * from v$pq_slave;
SLAVE_NAME STATUS SESSIONS IDLE_TIME_CUR BUSY_TIME_CUR CPU_SECS_CUR MSGS_SENT_CUR MSGS_RCVD_CUR IDLE_TIME_TOTAL BUSY_TIME_TOTAL CPU_SECS_TOTAL MSGS_SENT_TOTAL MSGS_RCVD_TOTAL
P000 IDLE 4 0 0 0 0 0 0 0 0 226 78
P001 IDLE 4 0 0 0 0 0 0 0 0 322 183
P002 IDLE 4 0 0 0 0 0 0 0 0 238 78
P003 IDLE 3 0 0 0 0 0 0 0 0 1430 1256
select /+ parallel(t1,4) / object_id,count(*) from t1 group by object_id;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询