Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a2b70c8

Browse files
committed
Fix ExecReScanGatherMerge.
Not surprisingly, since it'd never ever been tested, ExecReScanGatherMerge didn't work. Fix it, and add a regression test case to exercise it. Amit Kapila Discussion: https://postgr.es/m/CAA4eK1JkByysFJNh9M349u_nNjqETuEnY_y1VUc_kJiU0bxtaQ@mail.gmail.com
1 parent b5178c5 commit a2b70c8

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

src/backend/executor/nodeGatherMerge.c

+1
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ ExecReScanGatherMerge(GatherMergeState *node)
334334
ExecShutdownGatherMergeWorkers(node);
335335

336336
node->initialized = false;
337+
node->gm_initialized = false;
337338

338339
if (node->pei)
339340
ExecParallelReinitialize(node->pei);

src/test/regress/expected/select_parallel.out

+43
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,49 @@ select count(*) from tenk1 group by twenty;
300300
500
301301
(20 rows)
302302

303+
--test rescan behavior of gather merge
304+
set enable_material = false;
305+
explain (costs off)
306+
select * from
307+
(select string4, count(unique2)
308+
from tenk1 group by string4 order by string4) ss
309+
right join (values (1),(2),(3)) v(x) on true;
310+
QUERY PLAN
311+
----------------------------------------------------------
312+
Nested Loop Left Join
313+
-> Values Scan on "*VALUES*"
314+
-> Finalize GroupAggregate
315+
Group Key: tenk1.string4
316+
-> Gather Merge
317+
Workers Planned: 4
318+
-> Partial GroupAggregate
319+
Group Key: tenk1.string4
320+
-> Sort
321+
Sort Key: tenk1.string4
322+
-> Parallel Seq Scan on tenk1
323+
(11 rows)
324+
325+
select * from
326+
(select string4, count(unique2)
327+
from tenk1 group by string4 order by string4) ss
328+
right join (values (1),(2),(3)) v(x) on true;
329+
string4 | count | x
330+
---------+-------+---
331+
AAAAxx | 2500 | 1
332+
HHHHxx | 2500 | 1
333+
OOOOxx | 2500 | 1
334+
VVVVxx | 2500 | 1
335+
AAAAxx | 2500 | 2
336+
HHHHxx | 2500 | 2
337+
OOOOxx | 2500 | 2
338+
VVVVxx | 2500 | 2
339+
AAAAxx | 2500 | 3
340+
HHHHxx | 2500 | 3
341+
OOOOxx | 2500 | 3
342+
VVVVxx | 2500 | 3
343+
(12 rows)
344+
345+
reset enable_material;
303346
-- gather merge test with 0 worker
304347
set max_parallel_workers = 0;
305348
explain (costs off)

src/test/regress/sql/select_parallel.sql

+16
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,22 @@ explain (costs off)
118118

119119
select count(*) from tenk1 group by twenty;
120120

121+
--test rescan behavior of gather merge
122+
set enable_material = false;
123+
124+
explain (costs off)
125+
select * from
126+
(select string4, count(unique2)
127+
from tenk1 group by string4 order by string4) ss
128+
right join (values (1),(2),(3)) v(x) on true;
129+
130+
select * from
131+
(select string4, count(unique2)
132+
from tenk1 group by string4 order by string4) ss
133+
right join (values (1),(2),(3)) v(x) on true;
134+
135+
reset enable_material;
136+
121137
-- gather merge test with 0 worker
122138
set max_parallel_workers = 0;
123139
explain (costs off)

0 commit comments

Comments
 (0)