Here are some notes on oracle parallelism in the Oracle DB
DOP - Degree Of Parallelism
Three ways to set DOP:
ALTER SESSION SET parallel_degree_policy = auto;
ALTER SESSION ENABLE PARALLEL QUERY;
then use hint /*+ parallel(<DOP number fo process>) */
We can set the DOP with two steps:
PARALLEL_DEGREE_POLICY
specifies whether the automatic degree of parallelism,
statement queuing, and in-memory parallel execution will be enabled.ALTER SESSION SET parallel_degree_policy = auto;
ALTER SESSION ENABLE PARALLEL QUERY;
/*
ALTER SESSION ENABLE PARALLEL DML;
ALTER SESSION ENABLE PARALLEL DDL;
*/
We can use the PARALLEL hint to force parallelism.
It takes an optional parameter: the DOP at which the statement should run.
In addition, the NO_PARALLEL hint overrides a PARALLEL
parameter in the DDL that created or altered the table.
SELECT /*+PARALLEL */ ename, dname FROM emp e, dept d WHERE e.deptno=d.deptno;
SELECT /*+ parallel(10) */ ename, dname FROM emp e, dept d WHERE e.deptno=d.deptno;
SELECT /*+ no_parallel */ ename, dname FROM emp e, dept d WHERE e.deptno=d.deptno;
select /*+ PARALLEL(employees 4) PARALLEL(dept 4) USE_HASH(emp) ORDERED */
max(salary),
avg(salary)
from emp e inner inner join dept d on e.department_id = d.department_id
group by e.department_id;
In the above example, we use the USE_HASH to instruct the engine to use the hash method to join tables. Oracle accesses the emp table and builds a hash table on the join key in memory. It then scans the other table in the join.
SELECT /*+ parallel(auto) */ ename, dname FROM emp e, dept d
WHERE e.deptno=d.deptno;
ALTER TABLE customers PARALLEL 4;
Here queries accessing the customers table request a DOP of 4.
When the parameter PARALLEL_DEGREE_POLICY is set to AUTO, Oracle Database automatically decides if a statement should execute in parallel or not and what DOP it should use.
For more information, see “Determining Degree of Parallelism” and “Controlling Automatic Degree of Parallelism” on Oracle documantation.
PARALLEL_DEGREE_LIMIT
parameterThis parameter sets a limit on the maximum DOP.
The PARALLEL_DEGREE_LIMIT
parameter acts as a governor to the PARALLEL hint,
specifying the upper bound of parallelism for a parallelized query.
The default for PARALLEL_DEGREE_LIMIT
is cpu_count*2.