Skip to Main Content
  • Questions
  • DBMS_PARALLEL_EXECUTE for create table as select

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, EDUARDO.

Asked: February 05, 2018 - 9:27 pm UTC

Last updated: February 14, 2018 - 1:50 am UTC

Version: 12.2

Viewed 1000+ times

You Asked

Hi Tom,

I am trying to make use of this package at some SE 12.2 and 11.2 databases we have our customers' data.

What I have already read about, always shows how to make chunks of a table object.

I would like to usae it with the result of a complex SQL query, I explain my point...:

I have a relational Oracle DB from which I create aggregate structures with CTAS sentences.

I would like to create such tables with DBMS_PARALLEL_EXECUTE, having the SELECT in the CTAS as the source of the chunking process... Is this possible?

I would paste a sample CTAS below, but It surpasses the 2k characters limit on this page, may I use another method to send you that sample query?

Many thanks for your advice,

Eduardo

and Chris said...

DIY parallel splits up a statement into N chunks. Each chunk processes its own section of the data.

But only one statement can create a table!

Best case I imagine: one chunk would create the table, the others would fail.

But the real question is:

Why do you want to do this with DBMS_PARALLEL_EXECUTE?

As you've got a CTAS statement, you can parallelize this with standard parallel DDL:

https://docs.oracle.com/en/database/oracle/oracle-database/12.2/vldbg/types-parallelism.html#GUID-7E3B7D97-3AF2-4A5D-8C48-64AD35FD55D7

So why exactly are you wanting the complexity of DBMS_PARALLEL_EXECUTE?

Rating

  (2 ratings)

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

Comments

A reader, February 12, 2018 - 12:08 pm UTC

Hi Chris,

First of all excuse my delay in the answer, been so busy and forgot to make the followup to this, I'm sorry....

My Databases are Standard Edition. I tried to enable parallel DDL and DML, but It must be limited to EE databases, so I am looking for an alternative method with which to extract more juice out of the database without breaking the licensing limitations.

Isn't Parallel DDL and DML limited to EE? In the tests I made, I was simply not able to get it working...

Thanks again, regards,

PS: Promise to followup on this in a timely manner from now on! :)
Connor McDonald
February 13, 2018 - 1:49 am UTC

In that case, you could try this:

- run the create table in advance, so you have an empty table.
- then use dbms_parallel_execute to run insertion in parallel.

The issue here is that you can no longer do direct mode insert (because that requires a lock on the entire table).


Some guidance....

Eduardo, February 13, 2018 - 3:03 pm UTC

Many thanks for your suggestion,

I already thought of that posible method, creating the table first as empty, then populating with the DBMS_PARALLEL_EXECUTE.

However, I cannot figure out how to populate it, as the source data for the insertion at the empty table, does NOT come from another table, but from a complex SQL query with includes inner, right, left joins etc...

Would it be possible to have the DBMS_PARALLEL_EXECUTE get the chunks from such SQL query instead of a table? Would it be possible to have a view as the source for the chunking process?

Thanks in advance for your guidance and advice, regards,

Eduardo.
Connor McDonald
February 14, 2018 - 1:50 am UTC

Would it be possible to have the DBMS_PARALLEL_EXECUTE get the chunks from such SQL query instead of a table? Would it be possible to have a view as the source for the chunking process?

Yes. Ultimately DBMS_PARALLEL_EXECUTE breaks an existing process up into multiple processes via you providing a means to which the break-up can be done.

So if your original statement is (say):

insert into X
select ...
from   table1, table2, table3
where  [lots of joins]
and    [lots of other stuff]


then under DBMS_PARALLEL_EXECUTE the statement you would use is (for example)

insert into X
select ...
from   table1, table2, table3
where  [lots of joins]
and    [lots of other stuff]
and    table1.col between :start_id and :end_id


and use (say) CREATE_CHUNKS_BY_NUMBER_COL to build the ranges.

What DBMS_PARALLEL_EXECUTE will then do is create multiple scheduler jobs where

job1: runs the insert with start_id>0, end_id<=1000
job2: runs the insert with start_id>1000, end_id<=2000
job3: runs the insert with start_id>2000, end_id<=3000
job4: runs the insert with start_id>3000, end_id<=4000

where you define the number of chunks and the size of each.

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library