Skip to Main Content

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Mahesh.

Asked: March 27, 2018 - 3:21 am UTC

Last updated: March 27, 2018 - 6:40 am UTC

Version: 11.2.0.4.0

Viewed 1000+ times

You Asked

Hi Tom,

What is difference in following two scenarios?
I am using parallel hints like -

1.
select /*+ parallel(e,4) parallel(d,4)*/ e.eid,d.did
from emp e, dept d
where e.did = d.did;

2.
select /*+ parallel(4)*/ e.eid,d.did
from emp e, dept d
where e.did = d.did;

Which is better to use? why?

and Connor said...

It depends on what you want to achieve.

They *might* run the same way, they *might* run differently.

The first one is saying I want to access EMP and DEPT *both* in parallel. So you might see an execution plan like this:

------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                      | Name     | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT               |          |    14 |   798 |     4   (0)| 00:00:01 |        |      |            |
|   1 |  PX COORDINATOR                |          |       |       |            |          |        |      |            |
|   2 |   PX SEND QC (RANDOM)          | :TQ10002 |    14 |   798 |     4   (0)| 00:00:01 |  Q1,02 | P->S | QC (RAND)  |
|*  3 |    HASH JOIN BUFFERED          |          |    14 |   798 |     4   (0)| 00:00:01 |  Q1,02 | PCWP |            |
|   4 |     PX RECEIVE                 |          |     4 |    80 |     2   (0)| 00:00:01 |  Q1,02 | PCWP |            |
|   5 |      PX SEND HYBRID HASH       | :TQ10000 |     4 |    80 |     2   (0)| 00:00:01 |  Q1,00 | P->P | HYBRID HASH|
|   6 |       STATISTICS COLLECTOR     |          |       |       |            |          |  Q1,00 | PCWC |            |
|   7 |        PX BLOCK ITERATOR       |          |     4 |    80 |     2   (0)| 00:00:01 |  Q1,00 | PCWC |            |
|   8 |         TABLE ACCESS FULL      | DEPT     |     4 |    80 |     2   (0)| 00:00:01 |  Q1,00 | PCWP |            |
|   9 |     PX RECEIVE                 |          |    14 |   518 |     2   (0)| 00:00:01 |  Q1,02 | PCWP |            |
|  10 |      PX SEND HYBRID HASH (SKEW)| :TQ10001 |    14 |   518 |     2   (0)| 00:00:01 |  Q1,01 | P->P | HYBRID HASH|
|  11 |       PX BLOCK ITERATOR        |          |    14 |   518 |     2   (0)| 00:00:01 |  Q1,01 | PCWC |            |
|  12 |        TABLE ACCESS FULL       | EMP      |    14 |   518 |     2   (0)| 00:00:01 |  Q1,01 | PCWP |            |
------------------------------------------------------------------------------------------------------------------------


Notice that just about all steps are parallel until we get to the last part where we send results to the coordinator (and hence back to the client) were we do P->S to bring a single (serial) result back.

The second one says - EMP must be parallel access but DEPT can be anything. You *might* see the exact same plan as above, ie, we decide, since EMP is parallel we may as well do DEPT as well. Or you *might* see something like this:

------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                      | Name     | Rows  | Bytes | Cost (%CPU)| Time     |    TQ  |IN-OUT| PQ Distrib |
------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT               |          |    14 |   798 |     5   (0)| 00:00:01 |        |      |            |
|   1 |  PX COORDINATOR                |          |       |       |            |          |        |      |            |
|   2 |   PX SEND QC (RANDOM)          | :TQ10002 |    14 |   798 |     5   (0)| 00:00:01 |  Q1,02 | P->S | QC (RAND)  |
|*  3 |    HASH JOIN BUFFERED          |          |    14 |   798 |     5   (0)| 00:00:01 |  Q1,02 | PCWP |            |
|   4 |     BUFFER SORT                |          |       |       |            |          |  Q1,02 | PCWC |            |
|   5 |      PX RECEIVE                |          |     4 |    80 |     3   (0)| 00:00:01 |  Q1,02 | PCWP |            |
|   6 |       PX SEND HYBRID HASH      | :TQ10000 |     4 |    80 |     3   (0)| 00:00:01 |        | S->P | HYBRID HASH|
|   7 |        STATISTICS COLLECTOR    |          |       |       |            |          |        |      |            |
|   8 |         TABLE ACCESS FULL      | DEPT     |     4 |    80 |     3   (0)| 00:00:01 |        |      |            |
|   9 |     PX RECEIVE                 |          |    14 |   518 |     2   (0)| 00:00:01 |  Q1,02 | PCWP |            |
|  10 |      PX SEND HYBRID HASH (SKEW)| :TQ10001 |    14 |   518 |     2   (0)| 00:00:01 |  Q1,01 | P->P | HYBRID HASH|
|  11 |       PX BLOCK ITERATOR        |          |    14 |   518 |     2   (0)| 00:00:01 |  Q1,01 | PCWC |            |
|  12 |        TABLE ACCESS FULL       | EMP      |    14 |   518 |     2   (0)| 00:00:01 |  Q1,01 | PCWP |            |
------------------------------------------------------------------------------------------------------------------------


See line 6. In this case, our DEPT table is so small, its better to scan it once and then send it to each of the parallel slaves for EMP. Hence the S=>P

There is no "better" here - it is "what do you want to achieve".


Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

A reader, March 27, 2018 - 7:01 am UTC


More to Explore

Performance

Get all the information about database performance in the Database Performance guide.