Sunday, February 28, 2016

Oracle SQL Parallel hint

Each SQL statement undergoes an optimization and parallelization process when it is parsed. If parallel execution is chosen, then the following steps occur:
  1. The user session or shadow process takes on the role of a coordinator, often called the query coordinator.
  2. The query coordinator obtains the necessary number of parallel servers.
  3. The SQL statement is executed as a sequence of operations (a full table scan to perform a join on a nonindexed column, an ORDER BY clause, and so on). The parallel execution servers performs each operation in parallel if possible.
  4. When the parallel servers are finished executing the statement, the query coordinator performs any portion of the work that cannot be executed in parallel. For example, a parallel query with a SUM() operation requires adding the individual subtotals calculated by each parallel server.
  5. Finally, the query coordinator returns any results to the user
Example
Parallel hint at Query level
SELECT /*+ PARALLEL(4) */
               e.name,
               e.dept
FROM   emp e,
               dept d
WHERE e.emp_id = d.emp_id

Parallel hint at Table level
Use table alias to provide hint at Table level
SELECT /*+ PARALLEL(e, 4) */ 
               e.name,
               e.dept
FROM   emp e,
               dept d
WHERE e.emp_id = d.emp_id

1 comment:

Haseeb Majid said...

Nice post thanks for sharring