diff --git a/src/backend/executor/nodeGatherMerge.c b/src/backend/executor/nodeGatherMerge.c index 9a81e22..64c6239 100644 --- a/src/backend/executor/nodeGatherMerge.c +++ b/src/backend/executor/nodeGatherMerge.c @@ -334,6 +334,7 @@ ExecReScanGatherMerge(GatherMergeState *node) ExecShutdownGatherMergeWorkers(node); node->initialized = false; + node->gm_initialized = false; if (node->pei) ExecParallelReinitialize(node->pei); diff --git a/src/test/regress/expected/select_parallel.out b/src/test/regress/expected/select_parallel.out index 0efb211..d9402a7 100644 --- a/src/test/regress/expected/select_parallel.out +++ b/src/test/regress/expected/select_parallel.out @@ -300,6 +300,42 @@ select count(*) from tenk1 group by twenty; 500 (20 rows) +--test rescan behavior of gather merge +set enable_material TO 0; +explain (costs off) select * from (select string4, count((unique2)) from + tenk1 group by string4 order by string4) ss right join + (values(1),(2)) v(x) on true; + QUERY PLAN +---------------------------------------------------------- + Nested Loop Left Join + -> Values Scan on "*VALUES*" + -> Finalize GroupAggregate + Group Key: tenk1.string4 + -> Gather Merge + Workers Planned: 4 + -> Partial GroupAggregate + Group Key: tenk1.string4 + -> Sort + Sort Key: tenk1.string4 + -> Parallel Seq Scan on tenk1 +(11 rows) + +select * from (select string4, count((unique2)) from +tenk1 group by string4 order by string4) ss right join +(values(1),(2)) v(x) on true; + string4 | count | x +---------+-------+--- + AAAAxx | 2500 | 1 + HHHHxx | 2500 | 1 + OOOOxx | 2500 | 1 + VVVVxx | 2500 | 1 + AAAAxx | 2500 | 2 + HHHHxx | 2500 | 2 + OOOOxx | 2500 | 2 + VVVVxx | 2500 | 2 +(8 rows) + +reset enable_material; -- gather merge test with 0 worker set max_parallel_workers = 0; explain (costs off) diff --git a/src/test/regress/sql/select_parallel.sql b/src/test/regress/sql/select_parallel.sql index e717f92..7a0fb7f 100644 --- a/src/test/regress/sql/select_parallel.sql +++ b/src/test/regress/sql/select_parallel.sql @@ -118,6 +118,19 @@ explain (costs off) select count(*) from tenk1 group by twenty; +--test rescan behavior of gather merge +set enable_material TO 0; + +explain (costs off) select * from (select string4, count((unique2)) from + tenk1 group by string4 order by string4) ss right join + (values(1),(2)) v(x) on true; + +select * from (select string4, count((unique2)) from +tenk1 group by string4 order by string4) ss right join +(values(1),(2)) v(x) on true; + +reset enable_material; + -- gather merge test with 0 worker set max_parallel_workers = 0; explain (costs off)