The operation PX COORDINATOR FORCED SERIAL
implies the function was not defined with PARALLEL_ENABLE
. Adding that clause to the function should improve parallelism.
Regular function objects
create table c(b number);
create or replace package enc_dec is
function encrypt(p number) return number;
end;
/
create or replace package body enc_dec is
function encrypt(p number) return number is
begin
return p;
end;
end;
/
explain plan for
create table A as
select /*+ parallel(8) */ enc_dec.encrypt(B) as B from C;
select * from table(dbms_xplan.display);
Execution plan for regular function
Plan hash value: 1467482239
------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
------------------------------------------------------------------------------------------------------------------------------
| 0 | CREATE TABLE STATEMENT | | 1 | 13 | 3 (0)| 00:00:01 | | | |
| 1 | PX COORDINATOR FORCED SERIAL | | | | | | | | |
| 2 | PX SEND QC (RANDOM) | :TQ10001 | 1 | 13 | 2 (0)| 00:00:01 | Q1,01 | P->S | QC (RAND) |
| 3 | LOAD AS SELECT (HYBRID TSM/HWMB) | A | | | | | Q1,01 | PCWP | |
| 4 | PX RECEIVE | | 1 | 13 | 2 (0)| 00:00:01 | Q1,01 | PCWP | |
| 5 | PX SEND ROUND-ROBIN | :TQ10000 | 1 | 13 | 2 (0)| 00:00:01 | | S->P | RND-ROBIN |
| 6 | OPTIMIZER STATISTICS GATHERING | | 1 | 13 | 2 (0)| 00:00:01 | | | |
| 7 | TABLE ACCESS FULL | C | 1 | 13 | 2 (0)| 00:00:01 | | | |
------------------------------------------------------------------------------------------------------------------------------
Note
-----
- dynamic statistics used: dynamic sampling (level=2)
- Degree of Parallelism is 8 because of hint
Parallel function objects
This code is almost identical to above. The only differences are the package name and the PARALLEL_ENABLE
clause in the package specification and body.
create or replace package enc_dec_p is
function encrypt(p number) return number parallel_enable;
end;
/
create or replace package body enc_dec_p is
function encrypt(p number) return number parallel_enable is
begin
return p;
end;
end;
/
explain plan for
create table A as
select /*+ parallel(8) */ enc_dec_p.encrypt(B) as B from C;
select * from table(dbms_xplan.display);
Execution plan for parallel function
Note that the operation PX COORDINATOR FORCED SERIAL
was changed to PX COORDINATOR
.
Plan hash value: 3485102650
----------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
----------------------------------------------------------------------------------------------------------------------------
| 0 | CREATE TABLE STATEMENT | | 1 | 13 | 2 (0)| 00:00:01 | | | |
| 1 | PX COORDINATOR | | | | | | | | |
| 2 | PX SEND QC (RANDOM) | :TQ10000 | 1 | 13 | 2 (0)| 00:00:01 | Q1,00 | P->S | QC (RAND) |
| 3 | LOAD AS SELECT (HYBRID TSM/HWMB)| A | | | | | Q1,00 | PCWP | |
| 4 | OPTIMIZER STATISTICS GATHERING | | 1 | 13 | 2 (0)| 00:00:01 | Q1,00 | PCWP | |
| 5 | PX BLOCK ITERATOR | | 1 | 13 | 2 (0)| 00:00:01 | Q1,00 | PCWC | |
| 6 | TABLE ACCESS FULL | C | 1 | 13 | 2 (0)| 00:00:01 | Q1,00 | PCWP | |
----------------------------------------------------------------------------------------------------------------------------
Note
-----
- dynamic statistics used: dynamic sampling (level=2)
- Degree of Parallelism is 8 because of hint
If you're still having problems with parallelism I recommend you look at a long list of parallel factors in my answer here.
Java Function
There doesn't appear to be any inherent limitation preventing Java functions from running in parallel. I haven't used Java in parallel SQL before but the below example doesn't show the "FORCED SERIAL" operation.
create or replace and compile
java source named "JavaEncrypt"
as
public class JavaEncrypt
{
public static String create()
{
return "asdf";
}
}
/
create or replace package enc_dec is
function encrypt return varchar2 as language java
name 'JavaEncrypt.create() return java.lang.String';
end;
/
explain plan for
create table A as
select /*+ parallel(8) */ enc_dec.encrypt as B from C;
select * from table(dbms_xplan.display);
Execution plan:
Plan hash value: 3485102650
--------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
--------------------------------------------------------------------------------------------------------------------
| 0 | CREATE TABLE STATEMENT | | 1 | 2 (0)| 00:00:01 | | | |
| 1 | PX COORDINATOR | | | | | | | |
| 2 | PX SEND QC (RANDOM) | :TQ10000 | 1 | 2 (0)| 00:00:01 | Q1,00 | P->S | QC (RAND) |
| 3 | LOAD AS SELECT (HYBRID TSM/HWMB)| A | | | | Q1,00 | PCWP | |
| 4 | OPTIMIZER STATISTICS GATHERING | | 1 | 2 (0)| 00:00:01 | Q1,00 | PCWP | |
| 5 | PX BLOCK ITERATOR | | 1 | 2 (0)| 00:00:01 | Q1,00 | PCWC | |
| 6 | TABLE ACCESS FULL | C | 1 | 2 (0)| 00:00:01 | Q1,00 | PCWP | |
--------------------------------------------------------------------------------------------------------------------
Note
-----
- Degree of Parallelism is 8 because of hint
You may need to post the entire DDL for us to figure out what's causing the serial plan.