はい、すでに発見したように、UNION クエリは並列で実行できます。
ここで何が起こっているのかを完全に理解するには、VLDB and Partitioning Guide で並列実行について読むことをお勧めします。
操作内の並列処理は、ほぼどこでも発生する可能性があります。相互操作の並列処理は、プロデューサーとコンシューマーの間でのみ発生します。この場合、UNION (コンシューマー) は常に並行して実行できることを意味します。各サブクエリ (プロデューサー) は並行して実行されますが、同時には実行されません。
以下の例で、クエリのアクティブなレポートを見ると、これが起こっていることがわかります。
--Create two simple tables
create table test1(a number);
create table test2(a number);
--Populate them with 10 million rows
begin
for i in 1 .. 100 loop
insert into test1 select level from dual connect by level <= 100000;
insert into test2 select level from dual connect by level <= 100000;
end loop;
end;
/
commit;
--Gather stats
begin
dbms_stats.gather_table_stats(user, 'TEST1');
dbms_stats.gather_table_stats(user, 'TEST2');
end;
/
--Run a simple UNION.
select /*+ parallel */ count(*) from
(
select a from test1 join test2 using (a) where a <= 1000
union
select a from test2 join test1 using (a) where a <= 1000
);
--Find the SQL_ID by looking at v$sql, then get the active report
--(which must be saved and viewed in a browser)
select dbms_sqltune.report_sql_monitor(sql_id => 'bv5c18gyykntv', type => 'active')
from dual;
これが出力の一部です。読むのは難しいですが、計画の最初の 11 のステップである UNION がどのように実行されるかを示しています。最初のサブクエリ (次の 9 行) は、クエリの前半で実行されます。次に、クエリの後半で 2 番目のサブクエリ (最後の 9 行) が実行されます。
