CTAS ステートメントの select 句でNO_PARALLEL ヒントを使用し
ます。並列ヒントに関する注意も参照してください。
create table t as
select /*+ NO_PARALLEL */ *
from large_table;
調査とテスト:
SQL*Plus のバージョンと Oracle データベースのバージョン:
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
2 つの異なる sqlplus プロセスを使用して、異なるサービス名を介して同じデータベースに接続しました。CTAS の実行には、実行中の sqlplus のコピーが 1 つ使用されます。sqlplus のもう 1 つのコピーは、セッション数を照会するために使用されます。
何よりも先にセッション数と結果を取得するクエリ:
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
作成中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
large_table
は で作成されたためparallel 4
、単純な CTAS はデフォルトで 4 つのワーカー プロセス、CTAS:
create table t as
select * from large_table;
セッション:
SERVICE_NAME COUNT(*)
---------------------------------------------------------------- ----------
aaaaaa2 5
aaaaaa3 1
さて、noparallel
テーブルオプション。(デフォルトでは DML の並列プランを持たないテーブルを作成しますが、並列処理large_table
により CTAS が並列に実行されます。)
drop table t;
create table t noparallel as
select * from large_table;
セッション (最後のクエリの最後に SYS$BACKGROUND が表示された後、立ち往生しました。一定の時間内に必要がなければ終了すると思います。):
SERVICE_NAME COUNT(*)
---------------------------------------------------------------- ----------
SYS$BACKGROUND 1
aaaaaa2 5
aaaaaa3 1
select 句の NO_PARALLEL ヒントは機能します。
drop table t;
create table t as
select /*+ NO_PARALLEL */ * from large_table;
セッション:
SERVICE_NAME COUNT(*)
---------------------------------------------------------------- ----------
SYS$BACKGROUND 1
aaaaaa2 1
aaaaaa3 1
最後の CTAS では、デフォルトで複数のプロセスを使用するテーブルが作成されますが、CTAS 中は使用されません。
drop table t;
create table t parallel 4 as
select /*+ NO_PARALLEL */ * from large_table;
セッション:
SERVICE_NAME COUNT(*)
---------------------------------------------------------------- ----------
SYS$BACKGROUND 1
aaaaaa2 1
aaaaaa3 1