]> granicus.if.org Git - postgresql/commitdiff
Fix ExecReScanGatherMerge.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 17 Aug 2017 17:49:22 +0000 (13:49 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 17 Aug 2017 17:49:31 +0000 (13:49 -0400)
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

src/backend/executor/nodeGatherMerge.c
src/test/regress/expected/select_parallel.out
src/test/regress/sql/select_parallel.sql

index 9a81e225100cb673b183ba8e7c9d78b544e9ee9d..64c62398bbebbe86398484187c28e9395aa9ccba 100644 (file)
@@ -334,6 +334,7 @@ ExecReScanGatherMerge(GatherMergeState *node)
        ExecShutdownGatherMergeWorkers(node);
 
        node->initialized = false;
+       node->gm_initialized = false;
 
        if (node->pei)
                ExecParallelReinitialize(node->pei);
index 0efb211c970431a52d2ab53db708b6b109028e58..db31837edea3a93a49cd95e8a40292b2bc649622 100644 (file)
@@ -300,6 +300,49 @@ select count(*) from tenk1 group by twenty;
    500
 (20 rows)
 
+--test rescan behavior of gather merge
+set enable_material = false;
+explain (costs off)
+select * from
+  (select string4, count(unique2)
+   from tenk1 group by string4 order by string4) ss
+  right join (values (1),(2),(3)) 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),(3)) 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
+ AAAAxx  |  2500 | 3
+ HHHHxx  |  2500 | 3
+ OOOOxx  |  2500 | 3
+ VVVVxx  |  2500 | 3
+(12 rows)
+
+reset enable_material;
 -- gather merge test with 0 worker
 set max_parallel_workers = 0;
 explain (costs off)
index e717f92e530b64affb46983208189a3e30f8188b..33ce61a0260db34cb0e73f154a16a6065ad20ce7 100644 (file)
@@ -118,6 +118,22 @@ explain (costs off)
 
 select count(*) from tenk1 group by twenty;
 
+--test rescan behavior of gather merge
+set enable_material = false;
+
+explain (costs off)
+select * from
+  (select string4, count(unique2)
+   from tenk1 group by string4 order by string4) ss
+  right join (values (1),(2),(3)) v(x) on true;
+
+select * from
+  (select string4, count(unique2)
+   from tenk1 group by string4 order by string4) ss
+  right join (values (1),(2),(3)) v(x) on true;
+
+reset enable_material;
+
 -- gather merge test with 0 worker
 set max_parallel_workers = 0;
 explain (costs off)