Skip to content

Commit 403318b

Browse files
author
Amit Kapila
committed
Don't consider parallel append for parallel unsafe paths.
Commit ab72716 allowed Parallel Append paths to be generated for a relation that is not parallel safe. Prevent that from happening. Initial analysis by Tom Lane. Reported-by: Rajkumar Raghuwanshi Author: Amit Kapila and Rajkumar Raghuwanshi Reviewed-by: Amit Khandekar and Robert Haas Discussion:https://postgr.es/m/CAKcux6=tPJ6nJ08r__nU_pmLQiC0xY15Fn0HvG1Cprsjdd9s_Q@mail.gmail.com
1 parent 1c7c317 commit 403318b

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

src/backend/optimizer/path/allpaths.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1383,14 +1383,17 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel,
13831383
List *pa_partial_subpaths = NIL;
13841384
List *pa_nonpartial_subpaths = NIL;
13851385
bool partial_subpaths_valid = true;
1386-
bool pa_subpaths_valid = enable_parallel_append;
1386+
bool pa_subpaths_valid;
13871387
List *all_child_pathkeys = NIL;
13881388
List *all_child_outers = NIL;
13891389
ListCell *l;
13901390
List *partitioned_rels = NIL;
13911391
bool build_partitioned_rels = false;
13921392
double partial_rows = -1;
13931393

1394+
/* If appropriate, consider parallel append */
1395+
pa_subpaths_valid = enable_parallel_append && rel->consider_parallel;
1396+
13941397
/*
13951398
* AppendPath generated for partitioned tables must record the RT indexes
13961399
* of partitioned tables that are direct or indirect children of this

src/test/regress/expected/select_parallel.out

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,32 @@ select sp_test_func() order by 1;
132132
foo
133133
(2 rows)
134134

135+
-- Parallel Append is not to be used when the subpath depends on the outer param
136+
create table part_pa_test(a int, b int) partition by range(a);
137+
create table part_pa_test_p1 partition of part_pa_test for values from (minvalue) to (0);
138+
create table part_pa_test_p2 partition of part_pa_test for values from (0) to (maxvalue);
139+
explain (costs off)
140+
select (select max((select pa1.b from part_pa_test pa1 where pa1.a = pa2.a)))
141+
from part_pa_test pa2;
142+
QUERY PLAN
143+
--------------------------------------------------------------
144+
Aggregate
145+
-> Gather
146+
Workers Planned: 3
147+
-> Parallel Append
148+
-> Parallel Seq Scan on part_pa_test_p1 pa2
149+
-> Parallel Seq Scan on part_pa_test_p2 pa2_1
150+
SubPlan 2
151+
-> Result
152+
SubPlan 1
153+
-> Append
154+
-> Seq Scan on part_pa_test_p1 pa1
155+
Filter: (a = pa2.a)
156+
-> Seq Scan on part_pa_test_p2 pa1_1
157+
Filter: (a = pa2.a)
158+
(14 rows)
159+
160+
drop table part_pa_test;
135161
-- test with leader participation disabled
136162
set parallel_leader_participation = off;
137163
explain (costs off)

src/test/regress/sql/select_parallel.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ $$ select 'foo'::varchar union all select 'bar'::varchar $$
5555
language sql stable;
5656
select sp_test_func() order by 1;
5757

58+
-- Parallel Append is not to be used when the subpath depends on the outer param
59+
create table part_pa_test(a int, b int) partition by range(a);
60+
create table part_pa_test_p1 partition of part_pa_test for values from (minvalue) to (0);
61+
create table part_pa_test_p2 partition of part_pa_test for values from (0) to (maxvalue);
62+
explain (costs off)
63+
select (select max((select pa1.b from part_pa_test pa1 where pa1.a = pa2.a)))
64+
from part_pa_test pa2;
65+
drop table part_pa_test;
66+
5867
-- test with leader participation disabled
5968
set parallel_leader_participation = off;
6069
explain (costs off)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy