The difference between using parallelism “/*+parallel(4)*/” in the subquery or the outer query in terms of performance in Oracle

dba.stackexchange https://dba.stackexchange.com/questions/270144

Question

I have the below query :

select /*+parallel(4)*/ ---> First Location
       <Desc_1> Amount,
       <Desc_2> Amount,
       <Desc_3> Amount
from (select /*+parallel(4)*/ ---> Second Location
             <Column_1>,
             <Column_2>
      from <Example_Table>
      where <Conditions>
      )
pivot(sum(Column_1) Amount
for <Column_2> in (1 as <Desc_1>,
                   2 as <Desc_2>,
                   3 as <Desc_3>)
                   );

The point is that <Example_Table> is a very big table and I want to ask where is the best to location to use the /*+parallel(4)*/ ? Is it better to use it in theSubQuery or in the outer select? What if we use /*+parallel(4)*/ in both outer and inner select? Is it bad for performance?

Was it helpful?

Solution

Well, if you have just one table, and your outer select is not accessing other tables, I would guess that "Second Location" would be the only one the optimizer looks at. In practice, easy to test: just do an explain plan on the two options, and see. Then invoke it both ways, and verify what happens.

Oracle is pretty smart in doing the right thing for parallel queries; take a look at the following parameters, if neither option is producing a parallel execution plan:

select name, value from v$parameter where name like 'parallel%' order by 1;

And look at Oracle Database Reference section on "Initialization Parameters" such as parallel_adaptive_multi_user for details.

So nothing terrible is likely to happen if you put it in both places, but definately test in a development environment first.

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top