Skip to Main Content
  • Questions
  • ENABLE PARALLEL DML Vs FORCE PARALLEL DML

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question.

Asked: August 03, 2017 - 9:58 am UTC

Last updated: August 03, 2017 - 11:21 am UTC

Version: 11g

Viewed 10K+ times! This question is

You Asked

Hi Chris/Connor,

I came across below two piece of codes where only difference is "ALTER SESSION FORCE PARALLEL DML PARALLEL 16"

Can you please help to understand if we need to perform DELTE using parallelism, do i need to write both ALTER SESSION ENABLE PARALLEL DML & ALTER SESSION FORCE PARALLEL DML PARALLEL 16 ? or only ENABLE PARALLEL session will help here..

declare
begin
OPEN cur_get FOR SELECT * FROM table a;
loop
 fetch cur_get bulk collect into rec_collection limit 5000;
 exit when rec_collection.COUNT = 0;

 EXECUTE IMMEDIATE 'ALTER SESSION ENABLE PARALLEL DML';
 EXECUTE IMMEDIATE 'ALTER SESSION FORCE PARALLEL DML PARALLEL 16';

 FORALL i IN 1..rec_collection.COUNT
  DELETE /*+ PARALLEL(table a,16) */ FROM table a 
  WHERE ..
  ..;
 COMMIT;
end loop;
end;

declare
begin
OPEN cur_get FOR SELECT * FROM table a;
loop
 fetch cur_get bulk collect into rec_collection limit 5000;
 exit when rec_collection.COUNT = 0;

 EXECUTE IMMEDIATE 'ALTER SESSION ENABLE PARALLEL DML';

 FORALL i IN 1..rec_collection.COUNT
  DELETE /*+ PARALLEL(table a,16) */ FROM table a 
  WHERE ..
  ..;
 COMMIT;
end loop;
end;

and Chris said...

The docs seem clear on this one to me:

Enabling Parallel SQL Execution

You enable parallel SQL execution with an ALTER SESSION ENABLE PARALLEL DML|DDL|QUERY statement. Subsequently, when a PARALLEL clause or parallel hint is associated with a statement, those DML, DDL, or query statements will execute in parallel. By default, parallel execution is enabled for DDL and query statements.

Forcing Parallel SQL Execution

You can force parallel execution of all subsequent DML, DDL, or query statements for which parallelization is possible with the ALTER SESSION FORCE PARALLEL DML|DDL|QUERY statement. Additionally you can force a specific degree of parallelism to be in effect, overriding any PARALLEL clause associated with subsequent statements. If you do not specify a degree of parallelism in this statement, the default degree of parallelism is used. Forcing parallel execution overrides any parallel hints in SQL statements.


http://docs.oracle.com/database/122/ADMIN/managing-processes.htm#ADMIN11188

So you either you need to enable it and use the parallel hint. Or jut force it.

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

More to Explore

Performance

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