Use the
NO_PARALLEL hint
in the select clause of the CTAS statement.
See also Note on Parallel Hints
create table t as
select /*+ NO_PARALLEL */ *
from large_table;
Investigation & testing:
SQL*Plus version and Oracle Database version:
SQL*Plus: Release 11.1.0.6.0 - Production on Fri Sep 21 11:56:58 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
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:
SQL> select service_name, count(*)
2 from v$session
3 where username = 'ME'
4 group by service_name
5 order by service_name;
SERVICE_NAME COUNT(*)
---------------------------------------------------------------- ----------
aaaaaa2 1
aaaaaa3 1
Creating large_table
:
SQL> create table LAO as select * from all_objects;
Table created.
SQL> exec dbms_stats.gather_table_stats(user, 'LAO');
PL/SQL procedure successfully completed.
SQL> create table large_table parallel 4 as
2 select N.N, LAO.*
3 from LAO
4 cross join (select level as N from dual connect by level <= 400) N
5 /
Table created.
SQL> select to_char(count(*), 'fm999,999,999')
2 from large_table;
TO_CHAR(COUN
------------
42,695,200
Since large_table
was created with parallel 4
, a simple CTAS defaults to 4 worker processes, CTAS:
create table t as
select * from large_table;
Sessions:
SERVICE_NAME COUNT(*)
---------------------------------------------------------------- ----------
aaaaaa2 5
aaaaaa3 1
Now, the noparallel
table option. (Creating a table that by default won't have parallel plans for DML, but the parallelism of large_table
causes the CTAS to run in parallel.)
drop table t;
create table t noparallel as
select * from large_table;
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.):
SERVICE_NAME COUNT(*)
---------------------------------------------------------------- ----------
SYS$BACKGROUND 1
aaaaaa2 5
aaaaaa3 1
The NO_PARALLEL hint in the select clause does work:
drop table t;
create table t as
select /*+ NO_PARALLEL */ * from large_table;
Sessions:
SERVICE_NAME COUNT(*)
---------------------------------------------------------------- ----------
SYS$BACKGROUND 1
aaaaaa2 1
aaaaaa3 1
One last CTAS, where a table is created that will use multiple processes by default, but will not during the CTAS:
drop table t;
create table t parallel 4 as
select /*+ NO_PARALLEL */ * from large_table;
Sessions:
SERVICE_NAME COUNT(*)
---------------------------------------------------------------- ----------
SYS$BACKGROUND 1
aaaaaa2 1
aaaaaa3 1