Sunday, March 29, 2015

Video Tutorial: XPLAN_ASH Active Session History - Part 4

The next part of the video tutorial explaining the XPLAN_ASH Active Session History functionality continuing the actual walk-through of the script output.

More parts to follow.


Sunday, March 22, 2015

12c Parallel Execution New Features: Concurrent UNION ALL - Part 3

In the final part of this instalment I want to focus on the possible optimisation of remote access that I outlined in the initial part, which is based on the idea of running multiple concurrent remote branches of a UNION ALL to overcome the query coordinator bottleneck of straightforward remote queries that need to transfer larger amounts of data.

For that purpose I now simply change my sample query to access the serial table T2 via the DB link defined in the setup of the initial part, like that:
set echo on timing on time on

select /*+ PQ_CONCURRENT_UNION(@"SET$1") */ count(*) from (
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') >= regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') >= regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') >= regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') >= regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') >= regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') >= regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') >= regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') >= regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') >= regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') >= regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
);
which gives me this execution plan:
--------------------------------------------------------------
| Id  | Operation        | Name | Cost (%CPU)| Inst   |IN-OUT|
--------------------------------------------------------------
|   0 | SELECT STATEMENT |      |     0   (0)|        |      |
|   1 |  REMOTE          |      |            |   LOOP | R->S |
--------------------------------------------------------------
Ouch, not exactly what I wanted. Of course it's nice that the optimizer recognizes that this is a statement that can be executed fully remotely, but for my particular purpose I don't want that to happen. So let's add a dummy local branch:
select /*+ PQ_CONCURRENT_UNION(@"SET$1") */ count(*) from (
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') >= regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') >= regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') >= regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') >= regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') >= regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') >= regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') >= regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') >= regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') >= regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') >= regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2
where 1 = 0
);
which gives now this plan:
---------------------------------------------------------------------------
| Id  | Operation                 | Name     |    TQ  |IN-OUT| PQ Distrib |
---------------------------------------------------------------------------
|   0 | SELECT STATEMENT          |          |        |      |            |
|   1 |  SORT AGGREGATE           |          |        |      |            |
|   2 |   PX COORDINATOR          |          |        |      |            |
|   3 |    PX SEND QC (RANDOM)    | :TQ10000 |  Q1,00 | P->S | QC (RAND)  |
|   4 |     SORT AGGREGATE        |          |  Q1,00 | PCWP |            |
|   5 |      VIEW                 |          |  Q1,00 | PCWP |            |
|   6 |       UNION-ALL           |          |  Q1,00 | PCWP |            |
|   7 |        PX SELECTOR        |          |  Q1,00 | PCWP |            |
|   8 |         REMOTE            | T2       |  Q1,00 | PCWP |            |
|   9 |        PX SELECTOR        |          |  Q1,00 | PCWP |            |
|  10 |         REMOTE            | T2       |  Q1,00 | PCWP |            |
|  11 |        PX SELECTOR        |          |  Q1,00 | PCWP |            |
|  12 |         REMOTE            | T2       |  Q1,00 | PCWP |            |
|  13 |        PX SELECTOR        |          |  Q1,00 | PCWP |            |
|  14 |         REMOTE            | T2       |  Q1,00 | PCWP |            |
|  15 |        PX SELECTOR        |          |  Q1,00 | PCWP |            |
|  16 |         REMOTE            | T2       |  Q1,00 | PCWP |            |
|  17 |        PX SELECTOR        |          |  Q1,00 | PCWP |            |
|  18 |         REMOTE            | T2       |  Q1,00 | PCWP |            |
|  19 |        PX SELECTOR        |          |  Q1,00 | PCWP |            |
|  20 |         REMOTE            | T2       |  Q1,00 | PCWP |            |
|  21 |        PX SELECTOR        |          |  Q1,00 | PCWP |            |
|  22 |         REMOTE            | T2       |  Q1,00 | PCWP |            |
|  23 |        PX SELECTOR        |          |  Q1,00 | PCWP |            |
|  24 |         REMOTE            | T2       |  Q1,00 | PCWP |            |
|  25 |        PX SELECTOR        |          |  Q1,00 | PCWP |            |
|  26 |         REMOTE            | T2       |  Q1,00 | PCWP |            |
|  27 |        PX SELECTOR        |          |  Q1,00 | PCWP |            |
|* 28 |         FILTER            |          |  Q1,00 | PCWP |            |
|  29 |          TABLE ACCESS FULL| T2       |  Q1,00 | PCWP |            |
---------------------------------------------------------------------------
That is more what I wanted. One funny side effect of the dummy branch is that the automatically derived degree is now 11, since there are 11 branches. Although the optimizer knows that the 11th branch won't be executed (the filter operator ID = 28 is "NULL IS NOT NULL") it gets its own PX SELECTOR assigned, so that's probably the explanation why the calculation arrives at 11.

So let's see what happens at runtime using the setup from the previous part where T2 has 2M rows:
Activity Timeline based on ASH
-----------------------------------------------

             |      |      |          |          |          |                            |
             |      |      |          |          |   AVERAGE|AVERAGE                     |
             |      |      |          |          |    ACTIVE|ACTIVE SESSIONS             |
DURATION_SECS|PGA   |TEMP  |       CPU|     OTHER|  SESSIONS|GRAPH                       |
-------------|------|------|----------|----------|----------|----------------------------|
            1| 4485K|      |         1|         4|         5|@****      (5)              |
            2|   45M|      |         0|        10|        10|********** (10)             |
            3|   46M|      |         1|         9|        10|@********* (10)             |
            4|   46M|      |         0|        10|        10|********** (10)             |
            5|   46M|      |         0|        10|        10|********** (10)             |
            6|   46M|      |         0|        10|        10|********** (10)             |
            7|   46M|      |         0|        10|        10|********** (10)             |
            8|   46M|      |         0|        10|        10|********** (10)             |
            9|   46M|      |         0|        10|        10|********** (10)             |
           10|   46M|      |         0|        10|        10|********** (10)             |
           11|   46M|      |         0|        10|        10|********** (10)             |
           12|   46M|      |         0|        10|        10|********** (10)             |
           13|   46M|      |         0|        10|        10|********** (10)             |
           14|   46M|      |         0|        10|        10|********** (10)             |
           15|   46M|      |         0|        10|        10|********** (10)             |
           16|   46M|      |         0|        10|        10|********** (10)             |
           17|   46M|      |         0|        10|        10|********** (10)             |
           18|   46M|      |         0|        10|        10|********** (10)             |
           19|   46M|      |         0|        10|        10|********** (10)             |
           20|   46M|      |         0|        10|        10|********** (10)             |
           21|   46M|      |         0|        10|        10|********** (10)             |
           22|   46M|      |         0|        10|        10|********** (10)             |
           23|   46M|      |         0|        10|        10|********** (10)             |
           24|   46M|      |         0|        10|        10|********** (10)             |
           25|   46M|      |         1|         9|        10|@********* (10)             |
           26|   46M|      |         1|         9|        10|@********* (10)             |
           27|   46M|      |         0|        10|        10|********** (10)             |
           28|   46M|      |         0|        10|        10|********** (10)             |
           29|   46M|      |         0|        10|        10|********** (10)             |
           30|   46M|      |         0|        10|        10|********** (10)             |
           31|   46M|      |         0|        10|        10|********** (10)             |
           32|   46M|      |         0|        10|        10|********** (10)             |
           33|   46M|      |         1|         9|        10|@********* (10)             |
           34|   46M|      |         0|        10|        10|********** (10)             |
           35|   46M|      |         1|         9|        10|@********* (10)             |
           36|   46M|      |         0|        10|        10|********** (10)             |
           37|   46M|      |         0|        10|        10|********** (10)             |
           38|      |      |         0|         0|         0|           (0)              |
           39|   46M|      |         2|         8|        10|@@******** (10)             |
           40|   46M|      |         0|        10|        10|********** (10)             |
           41|   46M|      |         0|        10|        10|********** (10)             |
           42|   46M|      |         0|        10|        10|********** (10)             |
           43|   46M|      |         1|         9|        10|@********* (10)             |
           44|   46M|      |         0|        10|        10|********** (10)             |
           45|   46M|      |         0|        10|        10|********** (10)             |
           46|   46M|      |         0|        10|        10|********** (10)             |
           47|   46M|      |         0|        10|        10|********** (10)             |
           48|   46M|      |         0|        10|        10|********** (10)             |
           49|   46M|      |         0|        10|        10|********** (10)             |
           50|   46M|      |         0|        10|        10|********** (10)             |
           51|   46M|      |         0|        10|        10|********** (10)             |
           52|   46M|      |         0|        10|        10|********** (10)             |
           53|   46M|      |         1|         9|        10|@********* (10)             |
           54|   46M|      |         0|        10|        10|********** (10)             |
           55|   46M|      |         0|        10|        10|********** (10)             |
           56|   46M|      |         0|        10|        10|********** (10)             |
           57|   46M|      |         0|        10|        10|********** (10)             |
           58|   46M|      |         0|        10|        10|********** (10)             |
           59|   36M|      |         0|         8|         8|********   (8)              |
           60| 4609K|      |         0|         1|         1|*          (1)              |

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                 | Name     | Execs | A-Rows| Start | Dur(T)| Dur(A)| Time Active Graph    | Parallel Distribution ASH                                                          |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT          |          |    1  |    1  |       |       |       |                      |   0:sqlplus.exe(0)[1],P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],...              |
|   1 |  SORT AGGREGATE           |          |    1  |    1  |       |       |       |                      |   0:sqlplus.exe(0)[1],P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],...              |
|   2 |   PX COORDINATOR          |          |   12  |   11  |       |       |       |                      |   0:sqlplus.exe(0)[11],P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],...             |
|   3 |    PX SEND QC (RANDOM)    | :TQ10000 |   11  |   11  |       |       |       |                      |   0:P00A(0)[1],P000(0)[1],P001(0)[1],P002(0)[1],P003(0)[1],...                     |
|   4 |     SORT AGGREGATE        |          |   11  |   11  |       |       |       |                      |   0:P00A(0)[1],P000(0)[1],P001(0)[1],P002(0)[1],P003(0)[1],...                     |
|   5 |      VIEW                 |          |   11  |   20M |    43 |     1 |     1 |               #      |   1:P002(1)[2000K],P00A(0)[2000K],P001(0)[2000K],P003(0)[2000K],P004(0)[2000K],... |
|   6 |       UNION-ALL           |          |   11  |   20M |       |       |       |                      |   0:P00A(0)[2000K],P001(0)[2000K],P002(0)[2000K],P003(0)[2000K],P004(0)[2000K],... |
|   7 |        PX SELECTOR        |          |   11  | 2000K |       |       |       |                      |   0:P006(0)[2000K],P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],...                 |
|   8 |         REMOTE            | T2       |   11  | 2000K |     1 |    59 |    58 | #################### |   3:P006(58)[2000K],P004(1)[0],P007(1)[0],P00A(0)[0],P000(0)[0],...                |
|   9 |        PX SELECTOR        |          |   11  | 2000K |       |       |       |                      |   0:P008(0)[2000K],P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],...                 |
|  10 |         REMOTE            | T2       |   11  | 2000K |     1 |    58 |    57 | #################### |   1:P008(57)[2000K],P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],...                |
|  11 |        PX SELECTOR        |          |   11  | 2000K |       |       |       |                      |   0:P00A(0)[2000K],P000(0)[0],P001(0)[0],P002(0)[0],P003(0)[0],...                 |
|  12 |         REMOTE            | T2       |   11  | 2000K |     1 |    59 |    58 | #################### |   1:P00A(58)[2000K],P000(0)[0],P001(0)[0],P002(0)[0],P003(0)[0],...                |
|  13 |        PX SELECTOR        |          |   11  | 2000K |       |       |       |                      |   0:P004(0)[2000K],P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],...                 |
|  14 |         REMOTE            | T2       |   11  | 2000K |     2 |    58 |    57 | #################### |   1:P004(57)[2000K],P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],...                |
|  15 |        PX SELECTOR        |          |   11  | 2000K |       |       |       |                      |   0:P007(0)[2000K],P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],...                 |
|  16 |         REMOTE            | T2       |   11  | 2000K |     2 |    59 |    58 | #################### |   1:P007(58)[2000K],P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],...                |
|  17 |        PX SELECTOR        |          |   11  | 2000K |       |       |       |                      |   0:P005(0)[2000K],P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],...                 |
|  18 |         REMOTE            | T2       |   11  | 2000K |     2 |    58 |    57 | #################### |   1:P005(57)[2000K],P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],...                |
|  19 |        PX SELECTOR        |          |   11  | 2000K |       |       |       |                      |   0:P002(0)[2000K],P00A(0)[0],P000(0)[0],P001(0)[0],P003(0)[0],...                 |
|  20 |         REMOTE            | T2       |   11  | 2000K |     2 |    58 |    56 | #################### |   1:P002(56)[2000K],P00A(0)[0],P000(0)[0],P001(0)[0],P003(0)[0],...                |
|  21 |        PX SELECTOR        |          |   11  | 2000K |       |       |       |                      |   0:P009(0)[2000K],P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],...                 |
|  22 |         REMOTE            | T2       |   11  | 2000K |     2 |    58 |    57 | #################### |   1:P009(57)[2000K],P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],...                |
|  23 |        PX SELECTOR        |          |   11  | 2000K |       |       |       |                      |   0:P003(0)[2000K],P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],...                 |
|  24 |         REMOTE            | T2       |   11  | 2000K |     2 |    57 |    56 | #################### |   1:P003(56)[2000K],P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],...                |
|  25 |        PX SELECTOR        |          |   11  | 2000K |       |       |       |                      |   0:P001(0)[2000K],P00A(0)[0],P000(0)[0],P002(0)[0],P003(0)[0],...                 |
|  26 |         REMOTE            | T2       |   11  | 2000K |     2 |    58 |    57 | #################### |   1:P001(57)[2000K],P00A(0)[0],P000(0)[0],P002(0)[0],P003(0)[0],...                |
|  27 |        PX SELECTOR        |          |   11  |    0  |       |       |       |                      |   0:P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],P003(0)[0],...                     |
|* 28 |         FILTER            |          |   11  |    0  |       |       |       |                      |   0:P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],P003(0)[0],...                     |
|  29 |          TABLE ACCESS FULL| T2       |    0  |    0  |       |       |       |                      |   0:P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],P003(0)[0],...                     |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
So in principle this works as desired, with the automatically derived degree all remote branches are active at the same time. If I queried now different chunks of the same remote object to speed up the transfer and maximize throughput this should give me what I want.

If you wonder why the execution took now almost one minute when the processing of the same query in the previous part just took 40-45 seconds: This seems to be a side-effect of running that many concurrent CPU intensive processes on my test system, which nominally has 12 cores / 24 CPUs, but obviously doesn't scale linearly, either due to some architectural issues, or simply because the CPU speed was lowered with that many cores active.

However, look what happens when I change the remote query slightly so that no rows will be returned:
select /*+ PQ_CONCURRENT_UNION(@"SET$1") */ count(*) from (
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') > regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') > regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') > regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') > regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') > regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') > regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') > regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') > regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') > regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2@loop
where regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') > regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'i')
union all
select id, regexp_replace(t2.filler, '^\s+([[:alnum:]]+)\s+$', lpad('\1', 10), 1, 1, 'c') as result from t2
where 1 = 0
);
The runtime profile now looks like this:
Activity Timeline based on ASH
-----------------------------------------------

             |      |      |          |          |          |                            |
             |      |      |          |          |   AVERAGE|AVERAGE                     |
             |      |      |          |          |    ACTIVE|ACTIVE SESSIONS             |
DURATION_SECS|PGA   |TEMP  |       CPU|     OTHER|  SESSIONS|GRAPH                       |
-------------|------|------|----------|----------|----------|----------------------------|
            6|   36M|      |         0|       9,2|       9,2|*********   (9,2)           |
           12|   36M|      |         0|        11|        11|*********** (11)            |
           18|   36M|      |         0|        11|        11|*********** (11)            |
           24|   36M|      |         0|        11|        11|*********** (11)            |
           30|   36M|      |         0|        11|        11|*********** (11)            |
           36|   36M|      |         0|        11|        11|*********** (11)            |
           42|   36M|      |         0|       9,2|       9,2|*********   (9,2)           |
           48|   36M|      |         0|        11|        11|*********** (11)            |
           54|   36M|      |         0|        11|        11|*********** (11)            |
           60|   32M|      |         0|        11|        11|*********** (11)            |
           66| 9641K|      |         0|        11|        11|*********** (11)            |
           72| 9641K|      |         0|        11|        11|*********** (11)            |
           78| 9641K|      |         0|        11|        11|*********** (11)            |
           84| 9641K|      |         0|        11|        11|*********** (11)            |
           90| 9641K|      |         0|        11|        11|*********** (11)            |
           96| 9641K|      |         0|        11|        11|*********** (11)            |
          102| 9641K|      |         0|       9,2|       9,2|*********   (9,2)           |
          108| 9641K|      |         0|        11|        11|*********** (11)            |
          114| 9801K|      |         0|        11|        11|*********** (11)            |
          120|10281K|      |         0|        11|        11|*********** (11)            |
          126|10281K|      |         0|        11|        11|*********** (11)            |
          132|10281K|      |         0|        11|        11|*********** (11)            |
          138|10281K|      |         0|        11|        11|*********** (11)            |
          144|10281K|      |         0|        11|        11|*********** (11)            |
          150|10281K|      |         0|        11|        11|*********** (11)            |
          156|10281K|      |         0|        11|        11|*********** (11)            |
          162|10281K|      |         0|       9,2|       9,2|*********   (9,2)           |
          168|10281K|      |         0|        11|        11|*********** (11)            |
          174|10281K|      |         0|        11|        11|*********** (11)            |
          180|10281K|      |         0|        11|        11|*********** (11)            |
          186|10281K|      |         0|        11|        11|*********** (11)            |
          192|10281K|      |         0|        11|        11|*********** (11)            |
          198|10281K|      |         0|        11|        11|*********** (11)            |
          204|10281K|      |         0|        11|        11|*********** (11)            |
          210|10281K|      |         0|        11|        11|*********** (11)            |
          216|10281K|      |         0|        11|        11|*********** (11)            |
          222|10281K|      |         0|       9,2|       9,2|*********   (9,2)           |
          228|10281K|      |         0|        11|        11|*********** (11)            |
          234|10281K|      |         0|        11|        11|*********** (11)            |
          240|10281K|      |         0|        11|        11|*********** (11)            |
          246|10281K|      |         0|        11|        11|*********** (11)            |
          252|10281K|      |         0|        11|        11|*********** (11)            |
          258|10281K|      |         0|        11|        11|*********** (11)            |
          264|10281K|      |         0|        11|        11|*********** (11)            |
          270|10281K|      |         0|        11|        11|*********** (11)            |
          276|10281K|      |         0|        11|        11|*********** (11)            |
          282|10281K|      |         0|       9,2|       9,2|*********   (9,2)           |
          287|10281K|      |         0|        11|        11|*********** (11)            |
          292|10281K|      |         0|        11|        11|*********** (11)            |
          297|10281K|      |         0|        11|        11|*********** (11)            |
          302|10281K|      |         0|        11|        11|*********** (11)            |
          307|10281K|      |         0|        11|        11|*********** (11)            |
          312|10281K|      |         0|        11|        11|*********** (11)            |
          317|10281K|      |         0|        11|        11|*********** (11)            |
          322|10281K|      |         0|        11|        11|*********** (11)            |
          327|10281K|      |         0|        11|        11|*********** (11)            |
          332|10281K|      |         0|        11|        11|*********** (11)            |
          337|10281K|      |         0|        11|        11|*********** (11)            |
          342|10281K|      |         0|       8,8|       8,8|*********   (8,8)           |
          347|10281K|      |         0|        11|        11|*********** (11)            |
          352|10281K|      |         0|        11|        11|*********** (11)            |
          357|10281K|      |         0|        11|        11|*********** (11)            |
          362|10281K|      |         0|        11|        11|*********** (11)            |
          367|10281K|      |         0|        11|        11|*********** (11)            |
          372|10281K|      |         0|        11|        11|*********** (11)            |
          377|10281K|      |         0|        11|        11|*********** (11)            |
          382|10281K|      |         0|        11|        11|*********** (11)            |
          387|10281K|      |         0|        11|        11|*********** (11)            |
          392|10281K|      |         0|        11|        11|*********** (11)            |
          397|10281K|      |         0|        11|        11|*********** (11)            |
          402|10281K|      |         0|       8,8|       8,8|*********   (8,8)           |
          407|10281K|      |         0|        11|        11|*********** (11)            |
          412|10281K|      |         0|        11|        11|*********** (11)            |
          417|10281K|      |         0|        11|        11|*********** (11)            |
          422|10281K|      |         0|        11|        11|*********** (11)            |
          427|10281K|      |         0|        11|        11|*********** (11)            |
          432|10281K|      |         0|        11|        11|*********** (11)            |
          437|10281K|      |         0|        11|        11|*********** (11)            |
          442|10281K|      |         0|        11|        11|*********** (11)            |
          447|10281K|      |         0|        11|        11|*********** (11)            |
          452|10281K|      |         0|        11|        11|*********** (11)            |
          457|10281K|      |         0|        11|        11|*********** (11)            |
          462|10281K|      |         0|       8,8|       8,8|*********   (8,8)           |
          467|10281K|      |         0|        11|        11|*********** (11)            |
          472|10281K|      |         0|        11|        11|*********** (11)            |
          477|10281K|      |         0|        11|        11|*********** (11)            |
          482|10281K|      |         0|        11|        11|*********** (11)            |
          487|10281K|      |         0|        11|        11|*********** (11)            |
          492|10281K|      |         0|        11|        11|*********** (11)            |
          497|10281K|      |         0|        11|        11|*********** (11)            |
          502|10281K|      |         0|        11|        11|*********** (11)            |
          507|10281K|      |         0|        11|        11|*********** (11)            |
          512|10281K|      |         0|        11|        11|*********** (11)            |
          517|10281K|      |         0|        11|        11|*********** (11)            |
          522|10281K|      |         0|       8,8|       8,8|*********   (8,8)           |
          527|10281K|      |         0|        11|        11|*********** (11)            |
          532|10281K|      |         0|        11|        11|*********** (11)            |
          537| 9535K|      |         0|        10|        10|**********  (10)            |
          542| 7902K|      |         0|       8,4|       8,4|********    (8,4)           |
          547| 4894K|      |         0|       5,2|       5,2|*****       (5,2)           |

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                 | Name     | Execs | A-Rows| Start | Dur(T)| Dur(A)| Time Active Graph    | Parallel Distribution ASH                                              |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT          |          |    1  |    1  |       |       |       |                      |   0:sqlplus.exe(0)[1],P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],...  |
|   1 |  SORT AGGREGATE           |          |    1  |    1  |       |       |       |                      |   0:sqlplus.exe(0)[1],P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],...  |
|   2 |   PX COORDINATOR          |          |   12  |   11  |       |       |       |                      |   0:sqlplus.exe(0)[11],P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],... |
|   3 |    PX SEND QC (RANDOM)    | :TQ10000 |   11  |   11  |       |       |       |                      |   0:P00A(0)[1],P000(0)[1],P001(0)[1],P002(0)[1],P003(0)[1],...         |
|   4 |     SORT AGGREGATE        |          |   11  |   11  |       |       |       |                      |   0:P00A(0)[1],P000(0)[1],P001(0)[1],P002(0)[1],P003(0)[1],...         |
|   5 |      VIEW                 |          |   11  |    0  |       |       |       |                      |   0:P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],P003(0)[0],...         |
|   6 |       UNION-ALL           |          |   11  |    0  |       |       |       |                      |   0:P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],P003(0)[0],...         |
|   7 |        PX SELECTOR        |          |   11  |    0  |       |       |       |                      |   0:P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],P003(0)[0],...         |
|   8 |         REMOTE            | T2       |   11  |    0  |     2 |    59 |    58 | ###                  |  11:P001(58)[0],P002(58)[0],P004(58)[0],P005(58)[0],P00A(57)[0],...    |
|   9 |        PX SELECTOR        |          |   11  |    0  |       |       |       |                      |   0:P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],P003(0)[0],...         |
|  10 |         REMOTE            | T2       |   11  |    0  |    58 |    57 |    56 |   ###                |  11:P00A(53)[0],P001(53)[0],P002(53)[0],P006(53)[0],P007(53)[0],...    |
|  11 |        PX SELECTOR        |          |   11  |    0  |       |       |       |                      |   0:P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],P003(0)[0],...         |
|  12 |         REMOTE            | T2       |   11  |    0  |   111 |    58 |    57 |    ###               |  11:P008(54)[0],P000(53)[0],P001(53)[0],P002(53)[0],P004(53)[0],...    |
|  13 |        PX SELECTOR        |          |   11  |    0  |       |       |       |                      |   0:P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],P003(0)[0],...         |
|  14 |         REMOTE            | T2       |   11  |    0  |   163 |    61 |    60 |      ###             |  11:P00A(54)[0],P001(54)[0],P004(54)[0],P000(53)[0],P002(53)[0],...    |
|  15 |        PX SELECTOR        |          |   11  |    0  |       |       |       |                      |   0:P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],P003(0)[0],...         |
|  16 |         REMOTE            | T2       |   11  |    0  |   216 |    61 |    60 |        ###           |  11:P00A(55)[0],P000(54)[0],P005(54)[0],P006(54)[0],P001(53)[0],...    |
|  17 |        PX SELECTOR        |          |   11  |    0  |       |       |       |                      |   0:P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],P003(0)[0],...         |
|  18 |         REMOTE            | T2       |   11  |    0  |   269 |    65 |    64 |          ####        |  11:P005(58)[0],P007(57)[0],P00A(56)[0],P000(56)[0],P004(56)[0],...    |
|  19 |        PX SELECTOR        |          |   11  |    0  |       |       |       |                      |   0:P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],P003(0)[0],...         |
|  20 |         REMOTE            | T2       |   11  |    0  |   324 |    64 |    63 |            ####      |  11:P006(55)[0],P00A(53)[0],P000(53)[0],P004(53)[0],P008(53)[0],...    |
|  21 |        PX SELECTOR        |          |   11  |    0  |       |       |       |                      |   0:P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],P003(0)[0],...         |
|  22 |         REMOTE            | T2       |   11  |    0  |   376 |    66 |    65 |              ####    |  11:P007(54)[0],P00A(53)[0],P005(53)[0],P001(52)[0],P003(52)[0],...    |
|  23 |        PX SELECTOR        |          |   11  |    0  |       |       |       |                      |   0:P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],P003(0)[0],...         |
|  24 |         REMOTE            | T2       |   11  |    0  |   429 |    67 |    66 |                ####  |  11:P004(54)[0],P008(54)[0],P00A(53)[0],P000(53)[0],P001(53)[0],...    |
|  25 |        PX SELECTOR        |          |   11  |    0  |       |       |       |                      |   0:P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],P003(0)[0],...         |
|  26 |         REMOTE            | T2       |   11  |    0  |   481 |    67 |    66 |                  ### |  11:P008(54)[0],P000(53)[0],P001(53)[0],P003(53)[0],P009(53)[0],...    |
|  27 |        PX SELECTOR        |          |   11  |    0  |       |       |       |                      |   0:P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],P003(0)[0],...         |
|  28 |         FILTER            |          |   11  |    0  |       |       |       |                      |   0:P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],P003(0)[0],...         |
|  29 |          TABLE ACCESS FULL| T2       |    0  |    0  |       |       |       |                      |   0:P00A(0)[0],P000(0)[0],P001(0)[0],P002(0)[0],P003(0)[0],...         |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Ouch, so this took now more than nine times longer, and although we see the concurrent UNION ALL plan shape there is not much concurrency visible from the runtime activity - each branch seems to be executed by all 11 PX servers concurrently, and only then the next branch gets executed again by all 11 PX servers... It more or less looks like the PX SELECTOR wouldn't work correctly and instead of assigning the branch only to one PX server it seems to get executed by all of them - which we've already seen in the previous parts of this series is what actually happens, but for non-remote branches the PX SELECTOR functionality made sure that only one of them actually did something whereas the other ones simply skipped the operation.

We can see this problem confirmed by looking at the SQL execution statistics of the remote queries executed via V$SQLSTATS or DBA_HIST_SQLSTAT:
SQL_ID           FETCHES END_OF_FETCH_COUNT EXECUTIONS PARSE_CALLS ROWS_PROCESSED
------------- ---------- ------------------ ---------- ----------- --------------
dtjb3bxg1ysdk        730                 10        110         110       20000100
d36r1d00yaunc        110                110        108         108              0
The first SQL_ID corresponds to the remote query used by my first successful example - it already confirms that the remote query was actually executed 110 times (=> 11 PX servers times 10 branches) instead of the expected 10 times. The "ROWS_PROCESSED" and "END_OF_FETCH_COUNT" suggest what seems to have happened: Ten of the executions actually fetched the rows to the end (10 times 2M rows), but 100 of them fetched only a single row and then stopped the processing.

This also explains why my slightly changed query influenced the runtime profile so dramatically: Since no rows were returned by the remote query all 110 executions had to run to the end, since they would only stop early after fetching the first row, but there were no rows to fetch.

This problem is tracked via bug 19565803: INEFFICIENT EXECUTION OF PARALLEL UNION-ALL INVOLVING REMOTE TABLES and is mentioned to be fixed in 12.2, but there doesn't seem to be patch/fix available for 12.1

So in principle my original idea should work, assuming that the remote queries just access different chunks/partitions of the same segment the issue just described shouldn't matter. However, depending on what the remote queries exactly do, some other scenarios might be affected. The possible overhead depends on how much work the remote queries have to perform before they return the first row.