for some reason when I’m trying to CTAS (create table as select) on a large table (40million~ records ) I see in the v$session 18 active sessions with my sql statement.
when i’m trying to hint the optimizer to use less CPUs
create table table_name parallel (degree 2) as
select * from large_table;
I see 6 active sessions.
with degree 3 I see 8 active sessions.
I tryed degree default but it created 18 sessions as well.
previously in the code , before executing the CREATE TABLE statement I changed few attributes in my session :
alter session set workarea_size_policy = manual;
alter session set hash_area_size = 1048576000;
I want to create the table in 1 session , how to I do it ?
Thanks !
Use the
NO_PARALLEL hint
in the select clause of the CTAS statement.
See also Note on Parallel Hints
Investigation & testing:
SQL*Plus version and Oracle Database version:
I used two different sqlplus processes to connect to the same database via different service names. One running copy of sqlplus will be used to perform the CTAS. The other copy of sqlplus will be used to to query the number of sessions.
The query to get session count and results prior to anything else:
Creating
large_table:Since
large_tablewas created withparallel 4, a simple CTAS defaults to 4 worker processes, CTAS:Sessions:
Now, the
noparalleltable option. (Creating a table that by default won’t have parallel plans for DML, but the parallelism oflarge_tablecauses the CTAS to run in parallel.)Sessions (SYS$BACKGROUND showed up towards the end of the last query, then just stuck around. I believe it dies if not needed in a certain amount of time.):
The NO_PARALLEL hint in the select clause does work:
Sessions:
One last CTAS, where a table is created that will use multiple processes by default, but will not during the CTAS:
Sessions: