I have a select SQL query which use parallelism, something like this
INSERT/*+ APPEND PARALLEL (tst, 6) */ INTO test_table tst
(
**************
**************
**************
)
SELECT /*+ PARALLEL (a, 6) */ DISTINCT
**************
**************
**************
FROM src_table a;
As you can see here, i have hard-coded the degree but, i don't want to do that, since the number of CPUs are not same across all the DB where this code is executed.
My requirement:
I need to query V$PARAMETER
for the available CPU count and use the value as result-2
in my query. Something like this...
DECLARE
degree varchar2(1);
BEGIN
select value-2 INTO degree from v$parameter where name='cpu_count';
INSERT/*+ APPEND PARALLEL (tst, degree) */ INTO test_table tst
(
**************
**************
**************
)
SELECT /*+ PARALLEL (a, degree) */ DISTINCT
**************
**************
**************
FROM src_table a;
END;
But, it is not working as i expected it to be and i see 32 parallel threads, irrespective of the available CPUs. Is this a right way to do? If not, is there any other solution for my requirement ?
Default parallelism uses a formula to determine the DOP based on the system configuration, as in the following: For a single instance, DOP = PARALLEL_THREADS_PER_CPU x CPU_COUNT. For an Oracle RAC configuration, DOP = PARALLEL_THREADS_PER_CPU x CPU_COUNT x INSTANCE_COUNT.
The maximum degree of parallelism (MAXDOP) is a server configuration option for running SQL Server on multiple CPUs. It controls the number of processors used to run a single statement in parallel plan execution.
The degree of parallelism (DOP) is a property of a data flow that defines how many times each transform defined in the data flow replicates for use on a parallel subset of data. If there are multiple transforms in a data flow, SAP Data Services chains them together until it reaches a merge point.
Vivek,
You could use dynamic SQL to build up your INSERT statement within a PL/SQL function or procedure. That way you could utilise the variable "degree" that you have already retrieved.
Something like:
DECLARE
degree varchar2(1);
BEGIN
select value-2
INTO degree
from v$parameter
where name='cpu_count';
EXECUTE IMMEDIATE('INSERT /*+ APPEND PARALLEL (tst, '||degree||') */ '||
' INTO test_table tst ( '||
' ************** '||
' ************** '||
' ************** '||
' ) '||
'SELECT /*+ PARALLEL (a, '||degree||') */ '||
' DISTINCT '||
' ************** '||
' ************** '||
' ************** '||
' FROM src_table a');
END;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With