mirror of
https://github.com/postgres/postgres.git
synced 2025-06-01 00:01:20 -04:00
Commit 45be99f8cd5d606086e0a458c9c72910ba8a613d took the position that performing a merge join in parallel was not likely to work out well, but this conclusion was greeted with skepticism even at the time. Whether it was true then or not, it's clearly not true any more now that we have parallel index scan. Dilip Kumar, reviewed by Amit Kapila and by me. Discussion: http://postgr.es/m/CAFiTN-v3=cM6nyFwFGp0fmvY4=kk79Hq9Fgu0u8CSJ-EEq1Tiw@mail.gmail.com
214 lines
6.7 KiB
Plaintext
214 lines
6.7 KiB
Plaintext
--
|
|
-- PARALLEL
|
|
--
|
|
create or replace function parallel_restricted(int) returns int as
|
|
$$begin return $1; end$$ language plpgsql parallel restricted;
|
|
-- Serializable isolation would disable parallel query, so explicitly use an
|
|
-- arbitrary other level.
|
|
begin isolation level repeatable read;
|
|
-- encourage use of parallel plans
|
|
set parallel_setup_cost=0;
|
|
set parallel_tuple_cost=0;
|
|
set min_parallel_table_scan_size=0;
|
|
set max_parallel_workers_per_gather=4;
|
|
explain (costs off)
|
|
select count(*) from a_star;
|
|
QUERY PLAN
|
|
-----------------------------------------------------
|
|
Finalize Aggregate
|
|
-> Gather
|
|
Workers Planned: 1
|
|
-> Partial Aggregate
|
|
-> Append
|
|
-> Parallel Seq Scan on a_star
|
|
-> Parallel Seq Scan on b_star
|
|
-> Parallel Seq Scan on c_star
|
|
-> Parallel Seq Scan on d_star
|
|
-> Parallel Seq Scan on e_star
|
|
-> Parallel Seq Scan on f_star
|
|
(11 rows)
|
|
|
|
select count(*) from a_star;
|
|
count
|
|
-------
|
|
50
|
|
(1 row)
|
|
|
|
-- test that parallel_restricted function doesn't run in worker
|
|
alter table tenk1 set (parallel_workers = 4);
|
|
explain (verbose, costs off)
|
|
select parallel_restricted(unique1) from tenk1
|
|
where stringu1 = 'GRAAAA' order by 1;
|
|
QUERY PLAN
|
|
---------------------------------------------------------
|
|
Sort
|
|
Output: (parallel_restricted(unique1))
|
|
Sort Key: (parallel_restricted(tenk1.unique1))
|
|
-> Gather
|
|
Output: parallel_restricted(unique1)
|
|
Workers Planned: 4
|
|
-> Parallel Seq Scan on public.tenk1
|
|
Output: unique1
|
|
Filter: (tenk1.stringu1 = 'GRAAAA'::name)
|
|
(9 rows)
|
|
|
|
-- test parallel plan when group by expression is in target list.
|
|
explain (costs off)
|
|
select length(stringu1) from tenk1 group by length(stringu1);
|
|
QUERY PLAN
|
|
---------------------------------------------------
|
|
Finalize HashAggregate
|
|
Group Key: (length((stringu1)::text))
|
|
-> Gather
|
|
Workers Planned: 4
|
|
-> Partial HashAggregate
|
|
Group Key: length((stringu1)::text)
|
|
-> Parallel Seq Scan on tenk1
|
|
(7 rows)
|
|
|
|
select length(stringu1) from tenk1 group by length(stringu1);
|
|
length
|
|
--------
|
|
6
|
|
(1 row)
|
|
|
|
explain (costs off)
|
|
select stringu1, count(*) from tenk1 group by stringu1 order by stringu1;
|
|
QUERY PLAN
|
|
----------------------------------------------------
|
|
Sort
|
|
Sort Key: stringu1
|
|
-> Finalize HashAggregate
|
|
Group Key: stringu1
|
|
-> Gather
|
|
Workers Planned: 4
|
|
-> Partial HashAggregate
|
|
Group Key: stringu1
|
|
-> Parallel Seq Scan on tenk1
|
|
(9 rows)
|
|
|
|
-- test that parallel plan for aggregates is not selected when
|
|
-- target list contains parallel restricted clause.
|
|
explain (costs off)
|
|
select sum(parallel_restricted(unique1)) from tenk1
|
|
group by(parallel_restricted(unique1));
|
|
QUERY PLAN
|
|
-------------------------------------------------------------------
|
|
HashAggregate
|
|
Group Key: parallel_restricted(unique1)
|
|
-> Gather
|
|
Workers Planned: 4
|
|
-> Parallel Index Only Scan using tenk1_unique1 on tenk1
|
|
(5 rows)
|
|
|
|
-- test parallel plans for queries containing un-correlated subplans.
|
|
alter table tenk2 set (parallel_workers = 0);
|
|
explain (costs off)
|
|
select count(*) from tenk1 where (two, four) not in
|
|
(select hundred, thousand from tenk2 where thousand > 100);
|
|
QUERY PLAN
|
|
------------------------------------------------------
|
|
Finalize Aggregate
|
|
-> Gather
|
|
Workers Planned: 4
|
|
-> Partial Aggregate
|
|
-> Parallel Seq Scan on tenk1
|
|
Filter: (NOT (hashed SubPlan 1))
|
|
SubPlan 1
|
|
-> Seq Scan on tenk2
|
|
Filter: (thousand > 100)
|
|
(9 rows)
|
|
|
|
select count(*) from tenk1 where (two, four) not in
|
|
(select hundred, thousand from tenk2 where thousand > 100);
|
|
count
|
|
-------
|
|
10000
|
|
(1 row)
|
|
|
|
alter table tenk2 reset (parallel_workers);
|
|
-- test parallel index scans.
|
|
set enable_seqscan to off;
|
|
set enable_bitmapscan to off;
|
|
explain (costs off)
|
|
select count((unique1)) from tenk1 where hundred > 1;
|
|
QUERY PLAN
|
|
--------------------------------------------------------------------
|
|
Finalize Aggregate
|
|
-> Gather
|
|
Workers Planned: 4
|
|
-> Partial Aggregate
|
|
-> Parallel Index Scan using tenk1_hundred on tenk1
|
|
Index Cond: (hundred > 1)
|
|
(6 rows)
|
|
|
|
select count((unique1)) from tenk1 where hundred > 1;
|
|
count
|
|
-------
|
|
9800
|
|
(1 row)
|
|
|
|
-- test parallel index-only scans.
|
|
explain (costs off)
|
|
select count(*) from tenk1 where thousand > 95;
|
|
QUERY PLAN
|
|
--------------------------------------------------------------------------------
|
|
Finalize Aggregate
|
|
-> Gather
|
|
Workers Planned: 4
|
|
-> Partial Aggregate
|
|
-> Parallel Index Only Scan using tenk1_thous_tenthous on tenk1
|
|
Index Cond: (thousand > 95)
|
|
(6 rows)
|
|
|
|
select count(*) from tenk1 where thousand > 95;
|
|
count
|
|
-------
|
|
9040
|
|
(1 row)
|
|
|
|
reset enable_seqscan;
|
|
reset enable_bitmapscan;
|
|
-- test parallel merge join path.
|
|
set enable_hashjoin to off;
|
|
set enable_nestloop to off;
|
|
explain (costs off)
|
|
select count(*) from tenk1, tenk2 where tenk1.unique1 = tenk2.unique1;
|
|
QUERY PLAN
|
|
-------------------------------------------------------------------------------
|
|
Finalize Aggregate
|
|
-> Gather
|
|
Workers Planned: 4
|
|
-> Partial Aggregate
|
|
-> Merge Join
|
|
Merge Cond: (tenk1.unique1 = tenk2.unique1)
|
|
-> Parallel Index Only Scan using tenk1_unique1 on tenk1
|
|
-> Index Only Scan using tenk2_unique1 on tenk2
|
|
(8 rows)
|
|
|
|
select count(*) from tenk1, tenk2 where tenk1.unique1 = tenk2.unique1;
|
|
count
|
|
-------
|
|
10000
|
|
(1 row)
|
|
|
|
reset enable_hashjoin;
|
|
reset enable_nestloop;
|
|
set force_parallel_mode=1;
|
|
explain (costs off)
|
|
select stringu1::int2 from tenk1 where unique1 = 1;
|
|
QUERY PLAN
|
|
-----------------------------------------------
|
|
Gather
|
|
Workers Planned: 1
|
|
Single Copy: true
|
|
-> Index Scan using tenk1_unique1 on tenk1
|
|
Index Cond: (unique1 = 1)
|
|
(5 rows)
|
|
|
|
-- provoke error in worker
|
|
select stringu1::int2 from tenk1 where unique1 = 1;
|
|
ERROR: invalid input syntax for integer: "BAAAAA"
|
|
CONTEXT: parallel worker
|
|
rollback;
|