What's difference between parallel (4) and parallel 4 with and without brackets? For eg :
select /*+parallel(4) */ * from table_name;
select /*+parallel 4 */ * from table_name;
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.
Sign up to join this communityThe first is proper syntax, the second is not.
See here: https://riptutorial.com/oracle/example/4853/parallel-hint
/*+ parallel 4 */
means use the automatically generated degree of parallelism, which is probably much higher (the 4
is ignored). I don't know why you are looking at cost.
Oct 11, 2020 at 9:21
1./*+ parallel(4) */
means you ask the optimizer to use 4 as degree of parallelism.
SQL> explain plan for select /*+ parallel(4) */ * from t1;
Explained.
SQL> select * from table(dbms_xplan.display(format=>'basic,cost,note'));
PLAN_TABLE_OUTPUT
--------------------------------------------------------------
Plan hash value: 2494645258
------------------------------------------------------
| Id | Operation | Name | Cost (%CPU)|
------------------------------------------------------
| 0 | SELECT STATEMENT | | 90 (2)|
| 1 | PX COORDINATOR | | |
| 2 | PX SEND QC (RANDOM)| :TQ10000 | 90 (2)|
| 3 | PX BLOCK ITERATOR | | 90 (2)|
| 4 | TABLE ACCESS FULL| T1 | 90 (2)|
------------------------------------------------------
Note
-----
- Degree of Parallelism is 4 because of hint
15 rows selected.
SQL>
2./*+ parallel 4 */
means you ask the optimizer to use parallel execution, but you do not specify the degree, you let the database automatically decide the degree of parallelism. 4
is not part of the hint, it is simply a comment, could be anything there.
SQL> explain plan for select /*+ parallel 4 */ * from t1;
Explained.
SQL> select * from table(dbms_xplan.display(format=>'basic,cost,note'));
PLAN_TABLE_OUTPUT
--------------------------------------------------------------
Plan hash value: 2494645258
------------------------------------------------------
| Id | Operation | Name | Cost (%CPU)|
------------------------------------------------------
| 0 | SELECT STATEMENT | | 179 (0)|
| 1 | PX COORDINATOR | | |
| 2 | PX SEND QC (RANDOM)| :TQ10000 | 179 (0)|
| 3 | PX BLOCK ITERATOR | | 179 (0)|
| 4 | TABLE ACCESS FULL| T1 | 179 (0)|
------------------------------------------------------
Note
-----
- automatic DOP: Computed Degree of Parallelism is 2
15 rows selected.
SQL>
Notice how the Note
section in first example shown that Degree of Parallelism is 4 because of hint
, so degree here used was 4.
In the second example, Note
section contains automatic DOP: Computed Degree of Parallelism is 2
, so degree here used was 2, which explains the difference in cost you experienced.