今天遇到一个问题,某sql的并发度虽然已经全部获得但是只有少数几个slave干活。
1 2 3 4 |
alter session enable parallel dml; insert /*+ parallel(t 16)*/一个本地分区表t select /*+ full(a parallel(a 32))*/* from 远程分区表a@dblink where 时间>=xxxx and 时间<xxxxx; |
insert要求有16个并发,虽然在v$PX_SESSION看到其获得的degree是16,但是并不是这16个slave都在干活,从sqlmonitor里面看,16个并发子进程只有4个在干活,有消耗cpu time,有buffer get,有read reqs或write reqs。在v$session中也能看到这16个session,但是只有4个session是active的状态,其他都是inactive的。(虽然一开始16个都是active)
为什么其他的子进程不干活呢?
干活的子进程的数量,好像还和通过where条件选出来的分区有关系。如果where条件选出来的只有4个分区,那么干活的子进程只有4个。如果where条件选出来的分区只有3个,那么就只有3个slave会干活。但是他们都能获得16个并发子进程,只是并不是所有的子进程都干活。
通过分析发现,并发量只能用到涉及到的分区数,是因为表中包含lob字段。
(1) 并发dml不能用在分布式事物中,oracle的在线文档中可以看到
Distributed Transaction Restrictions:
1 |
A DML operation cannot be executed in parallel if it is in a distributed transaction or if the DML or the query operation is on a remote object. |
(2) 但上面的文档描述的是普通表,对分区表来说,还是可以用到并发。并发度为在hint中指定的parallel的值。一开始是会各个子进程处于direct path write temp,在最后阶段汇总并发子进程的信息第时候,子进程会处于较多的enq: HV – contention等待。观测其sqlmonitor的记录,可以看到用到了16个并发度,每个并发度都有CPU、buffer、IO的消耗。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
SQL Monitoring Report SQL Text ------------------------------ insert /*+ monitor parallel(t 16) */ into test2 t --orasup17 select /*+ FULL(a) parallel(a 32) )*/ * from CHSEGDATA.test1@mig_link a where a.UPDATED_DATE >= to_date('20130701', 'yyyymmdd') and a.UPDATED_DATE < to_date('20131101', 'yyyymmdd') Global Information ------------------------------ Status : DONE Instance ID : 1 Session : MIG_TARGET (661:45989) SQL ID : 1t3sqks6s5knp SQL Execution ID : 16777217 Execution Started : 02/27/2014 17:05:13 First Refresh Time : 02/27/2014 17:05:13 Last Refresh Time : 02/27/2014 17:19:45 Duration : 872s Module/Action : PL/SQL Developer/Command Window - New Service : SYS$USERS Program : plsqldev.exe Global Stats ================================================================================================= | Elapsed | Cpu | IO | Concurrency | Other | Buffer | Read | Read | Write | Write | | Time(s) | Time(s) | Waits(s) | Waits(s) | Waits(s) | Gets | Reqs | Bytes | Reqs | Bytes | ================================================================================================= | 2642 | 1187 | 245 | 379 | 831 | 3M | 227K | 12GB | 120K | 24GB | ================================================================================================= Parallel Execution Details (DOP=16 , Servers Allocated=16) ========================================================================================================================================================================== | Name | Type | Server# | Elapsed | Cpu | IO | Concurrency | Other | Buffer | Read | Read | Write | Write | Wait Events | | | | | Time(s) | Time(s) | Waits(s) | Waits(s) | Waits(s) | Gets | Reqs | Bytes | Reqs | Bytes | (sample #) | ========================================================================================================================================================================== | PX Coordinator | QC | | 563 | 528 | | 0.61 | 35 | 13 | | . | | . | os thread startup (1) | | | | | | | | | | | | | | | SQL*Net message from dblink (2) | | | | | | | | | | | | | | | SQL*Net more data from dblink (21) | | p000 | Set 1 | 1 | 125 | 39 | 14 | 22 | 49 | 160K | 14164 | 745MB | 7488 | 1GB | log file sync (2) | | | | | | | | | | | | | | | enq: HV - contention (5) | | | | | | | | | | | | | | | log buffer space (23) | | | | | | | | | | | | | | | log file switch completion (3) | | | | | | | | | | | | | | | direct path write (1) | | | | | | | | | | | | | | | direct path write temp (6) | | p001 | Set 1 | 2 | 131 | 41 | 15 | 19 | 56 | 162K | 14164 | 745MB | 7540 | 1GB | enq: HV - contention (3) | | | | | | | | | | | | | | | log buffer space (28) | | | | | | | | | | | | | | | log file switch completion (4) | | | | | | | | | | | | | | | direct path write temp (1) | | p002 | Set 1 | 3 | 131 | 42 | 16 | 24 | 49 | 161K | 14162 | 745MB | 7491 | 1GB | enq: HV - contention (3) | | | | | | | | | | | | | | | log buffer space (26) | | | | | | | | | | | | | | | log file switch completion (4) | | | | | | | | | | | | | | | direct path write (3) | | | | | | | | | | | | | | | direct path write temp (1) | | p003 | Set 1 | 4 | 128 | 41 | 14 | 25 | 48 | 162K | 14161 | 745MB | 7555 | 1GB | enq: HV - contention (6) | | | | | | | | | | | | | | | log buffer space (26) | | | | | | | | | | | | | | | log file switch completion (4) | | | | | | | | | | | | | | | direct path read temp (1) | | | | | | | | | | | | | | | direct path write temp (4) | | p004 | Set 1 | 5 | 132 | 42 | 16 | 24 | 50 | 164K | 14160 | 745MB | 7573 | 1GB | enq: HV - contention (5) | | | | | | | | | | | | | | | log buffer space (27) | | | | | | | | | | | | | | | log file switch completion (2) | | | | | | | | | | | | | | | direct path write (2) | | | | | | | | | | | | | | | direct path write temp (4) | | p005 | Set 1 | 6 | 127 | 41 | 13 | 26 | 48 | 162K | 14165 | 745MB | 7532 | 1GB | enq: HV - contention (2) | | | | | | | | | | | | | | | log buffer space (27) | | | | | | | | | | | | | | | log file switch completion (2) | | | | | | | | | | | | | | | direct path read temp (1) | | | | | | | | | | | | | | | direct path write (1) | | | | | | | | | | | | | | | direct path write temp (1) | | p006 | Set 1 | 7 | 125 | 40 | 12 | 23 | 50 | 158K | 14156 | 745MB | 7474 | 1GB | log file sync (1) | | | | | | | | | | | | | | | enq: HV - contention (6) | | | | | | | | | | | | | | | log buffer space (24) | | | | | | | | | | | | | | | log file switch completion (2) | | | | | | | | | | | | | | | direct path write (1) | | | | | | | | | | | | | | | direct path write temp (3) | | p007 | Set 1 | 8 | 131 | 41 | 16 | 24 | 49 | 164K | 14155 | 745MB | 7548 | 1GB | enq: HV - contention (6) | | | | | | | | | | | | | | | log buffer space (24) | | | | | | | | | | | | | | | log file switch completion (3) | | | | | | | | | | | | | | | direct path write (1) | | | | | | | | | | | | | | | direct path write temp (2) | | p008 | Set 1 | 9 | 131 | 40 | 17 | 23 | 50 | 165K | 14156 | 745MB | 7586 | 1GB | enq: HV - contention (6) | | | | | | | | | | | | | | | log buffer space (26) | | | | | | | | | | | | | | | log file switch completion (3) | | | | | | | | | | | | | | | direct path write (1) | | | | | | | | | | | | | | | direct path write temp (3) | | p009 | Set 1 | 10 | 131 | 41 | 16 | 25 | 49 | 160K | 14156 | 745MB | 7454 | 1GB | enq: HV - contention (2) | | | | | | | | | | | | | | | log buffer space (28) | | | | | | | | | | | | | | | log file switch completion (3) | | | | | | | | | | | | | | | direct path write (1) | | | | | | | | | | | | | | | direct path write temp (5) | | p010 | Set 1 | 11 | 132 | 43 | 17 | 20 | 52 | 162K | 14160 | 745MB | 7482 | 1GB | enq: HV - contention (3) | | | | | | | | | | | | | | | log buffer space (28) | | | | | | | | | | | | | | | log file switch completion (3) | | | | | | | | | | | | | | | direct path read temp (1) | | | | | | | | | | | | | | | direct path write (2) | | | | | | | | | | | | | | | direct path write temp (1) | | p011 | Set 1 | 12 | 131 | 42 | 16 | 25 | 47 | 162K | 14158 | 745MB | 7545 | 1GB | enq: HV - contention (3) | | | | | | | | | | | | | | | log buffer space (26) | | | | | | | | | | | | | | | log file switch completion (2) | | | | | | | | | | | | | | | direct path read temp (1) | | | | | | | | | | | | | | | direct path write (2) | | | | | | | | | | | | | | | direct path write temp (5) | | p012 | Set 1 | 13 | 131 | 42 | 15 | 19 | 55 | 164K | 14156 | 745MB | 7541 | 1GB | enq: HV - contention (3) | | | | | | | | | | | | | | | log buffer space (27) | | | | | | | | | | | | | | | log file switch completion (3) | | | | | | | | | | | | | | | direct path read temp (1) | | | | | | | | | | | | | | | direct path write temp (2) | | p013 | Set 1 | 14 | 131 | 41 | 16 | 26 | 48 | 161K | 14155 | 745MB | 7499 | 1GB | enq: HV - contention (10) | | | | | | | | | | | | | | | log buffer space (25) | | | | | | | | | | | | | | | log file switch completion (3) | | | | | | | | | | | | | | | direct path write (1) | | | | | | | | | | | | | | | direct path write temp (2) | | p014 | Set 1 | 15 | 131 | 42 | 16 | 26 | 47 | 162K | 14157 | 745MB | 7531 | 1GB | enq: HV - contention (5) | | | | | | | | | | | | | | | log buffer space (24) | | | | | | | | | | | | | | | log file switch completion (4) | | | | | | | | | | | | | | | direct path sync (1) | | | | | | | | | | | | | | | direct path write (1) | | | | | | | | | | | | | | | direct path write temp (1) | | p015 | Set 1 | 16 | 131 | 41 | 17 | 25 | 48 | 161K | 14156 | 745MB | 7525 | 1GB | enq: HV - contention (4) | | | | | | | | | | | | | | | log buffer space (27) | | | | | | | | | | | | | | | log file switch completion (2) | | | | | | | | | | | | | | | direct path write (2) | | | | | | | | | | | | | | | direct path write temp (1) | ========================================================================================================================================================================== SQL Plan Monitoring Details (Plan Hash Value=1336317309) ====================================================================================================================================================================================================== | Id | Operation | Name | Rows | Cost | Time | Start | Execs | Rows | Read | Read | Write | Write | Mem | Temp | Activity | Activity Detail | | | | | (Estim) | | Active(s) | Active | | (Actual) | Reqs | Bytes | Reqs | Bytes | (Max) | (Max) | (%) | (# samples) | ====================================================================================================================================================================================================== | 0 | INSERT STATEMENT | | | | 96 | +777 | 17 | 64 | | | | | | | 1.29 | log file sync (3) | | | | | | | | | | | | | | | | | | log buffer space (2) | | | | | | | | | | | | | | | | | | log file switch completion (2) | | | | | | | | | | | | | | | | | | Cpu (5) | | 1 | PX COORDINATOR | | | | 873 | +0 | 17 | 64 | | | | | | | 0.11 | os thread startup (1) | | 2 | PX SEND QC (RANDOM) | :TQ10001 | 20 | 19 | 9 | +863 | 16 | 64 | | | | | | | | | | 3 | LOAD AS SELECT | | | | 114 | +758 | 16 | 64 | 10 | 81920 | 61308 | 12GB | 30M | | 63.91 | enq: HV - contention (72) | | | | | | | | | | | | | | | | | | log buffer space (414) | | | | | | | | | | | | | | | | | | log file switch completion (45) | | | | | | | | | | | | | | | | | | Cpu (45) | | | | | | | | | | | | | | | | | | direct path write (19) | | 4 | BUFFER SORT | | | | 870 | +2 | 16 | 41M | 227K | 12GB | 59056 | 12GB | 631M | 13G | 11.49 | Cpu (59) | | | | | | | | | | | | | | | | | | direct path read temp (5) | | | | | | | | | | | | | | | | | | direct path sync (1) | | | | | | | | | | | | | | | | | | direct path write temp (42) | | 5 | PX RECEIVE | | 20 | 19 | 758 | +2 | 16 | 41M | | | | | | | 2.04 | Cpu (19) | | 6 | PX SEND ROUND-ROBIN | :TQ10000 | 20 | 19 | 862 | +2 | 1 | 41M | | | | | | | 2.47 | Cpu (23) | | 7 | REMOTE | TEST1 | 20 | 19 | 863 | +1 | 1 | 41M | | | | | | | 18.58 | Cpu (150) | | | | | | | | | | | | | | | | | | SQL*Net message from dblink (2) | | | | | | | | | | | | | | | | | | SQL*Net more data from dblink (21) | ====================================================================================================================================================================================================== |
(3) 目前的分区数没有到达hint中的parallel数,这是因为该表中含有lob字段。
如果测试新建一个类似的分区表,只是不包含blob字段信息,做insert时即可拥有hint中指定的parallel数。
在12c之前,有lob字段的分区表是可以有parallel dml,但是intra-partition是不支持并行的,即分区内部是不支持并行的,因此有几个分区你就能看到几个并行。
在12c之后,应该可以支持有LOB字段的分区表的initra-partition。也就是你可以看到多余分区数的并行了。
我们可以在oracle的在线文档中提到:
Restrictions on Parallel DML:
1 |
Parallel DML can be done on tables with LOB columns provided the table is partitioned. However, intra-partition parallelism is not supported. |