fix plans in tests broken by adding Sort Key to EXPLAIN(VERBOSE)
authorTomas Vondra <[email protected]>
Sun, 29 Jan 2017 02:06:51 +0000 (03:06 +0100)
committerTomas Vondra <[email protected]>
Sun, 29 Jan 2017 02:06:51 +0000 (03:06 +0100)
This fixes explain plans broken only because of the extra bit of
information added to EXPLAIN VERBOSE output. If the plan was broken
for some other reasons too, this not fix it.

src/test/regress/expected/limit.out
src/test/regress/expected/select_parallel.out
src/test/regress/expected/xc_FQS.out
src/test/regress/expected/xc_groupby.out

index 1ffd81ec5ef9f503f18963cb8680602a6eecb171..0ec3d30e00846491d30d82f1c2b2ecab940024e6 100644 (file)
@@ -143,11 +143,12 @@ select unique1, unique2, nextval('testseq')
    Output: unique1, unique2, (nextval('testseq'::regclass))
    ->  Remote Subquery Scan on all (datanode_1,datanode_2)
          Output: unique1, unique2, nextval('testseq'::regclass)
+         Sort Key: tenk1.unique2
          ->  Limit
                Output: unique1, unique2, (nextval('testseq'::regclass))
                ->  Index Scan using tenk1_unique2 on public.tenk1
                      Output: unique1, unique2, nextval('testseq'::regclass)
-(8 rows)
+(9 rows)
 
 select unique1, unique2, nextval('testseq')
   from tenk1 order by unique2 limit 10;
@@ -180,6 +181,7 @@ select unique1, unique2, nextval('testseq')
    Output: unique1, unique2, (nextval('testseq'::regclass)), tenthous
    ->  Remote Subquery Scan on all (datanode_1,datanode_2)
          Output: unique1, unique2, nextval('testseq'::regclass), tenthous
+         Sort Key: tenk1.tenthous
          ->  Limit
                Output: unique1, unique2, (nextval('testseq'::regclass)), tenthous
                ->  Result
@@ -189,7 +191,7 @@ select unique1, unique2, nextval('testseq')
                            Sort Key: tenk1.tenthous
                            ->  Seq Scan on public.tenk1
                                  Output: unique1, unique2, tenthous
-(13 rows)
+(14 rows)
 
 select unique1, unique2, nextval('testseq')
   from tenk1 order by tenthous limit 10;
@@ -222,11 +224,12 @@ select unique1, unique2, generate_series(1,10)
    Output: unique1, unique2, (generate_series(1, 10))
    ->  Remote Subquery Scan on all (datanode_1,datanode_2)
          Output: unique1, unique2, generate_series(1, 10)
+         Sort Key: tenk1.unique2
          ->  Limit
                Output: unique1, unique2, (generate_series(1, 10))
                ->  Index Scan using tenk1_unique2 on public.tenk1
                      Output: unique1, unique2, generate_series(1, 10)
-(8 rows)
+(9 rows)
 
 select unique1, unique2, generate_series(1,10)
   from tenk1 order by unique2 limit 7;
@@ -250,6 +253,7 @@ select unique1, unique2, generate_series(1,10)
    Output: unique1, unique2, (generate_series(1, 10)), tenthous
    ->  Remote Subquery Scan on all (datanode_1,datanode_2)
          Output: unique1, unique2, generate_series(1, 10), tenthous
+         Sort Key: tenk1.tenthous
          ->  Limit
                Output: unique1, unique2, (generate_series(1, 10)), tenthous
                ->  Result
@@ -259,7 +263,7 @@ select unique1, unique2, generate_series(1,10)
                            Sort Key: tenk1.tenthous
                            ->  Seq Scan on public.tenk1
                                  Output: unique1, unique2, tenthous
-(13 rows)
+(14 rows)
 
 select unique1, unique2, generate_series(1,10)
   from tenk1 order by tenthous limit 7;
@@ -325,12 +329,13 @@ select sum(tenthous) as s1, sum(tenthous) + random()*0 as s2
          Group Key: tenk1.thousand
          ->  Remote Subquery Scan on all (datanode_1,datanode_2)
                Output: thousand, PARTIAL sum(tenthous)
+               Sort Key: tenk1.thousand
                ->  Partial GroupAggregate
                      Output: thousand, PARTIAL sum(tenthous)
                      Group Key: tenk1.thousand
                      ->  Index Only Scan using tenk1_thous_tenthous on public.tenk1
                            Output: thousand, tenthous
-(12 rows)
+(13 rows)
 
 select sum(tenthous) as s1, sum(tenthous) + random()*0 as s2
   from tenk1 group by thousand order by thousand limit 3;
index 78d32e08ff384b0e0054a463d5b68dd6d7daff49..33f3ee6f8de25ee271b17c134bcd47df16223101 100644 (file)
@@ -44,6 +44,7 @@ select parallel_restricted(unique1) from tenk1
 ---------------------------------------------------------------
  Remote Subquery Scan on all (datanode_1,datanode_2)
    Output: parallel_restricted(unique1)
+   Sort Key: parallel_restricted(tenk1.unique1)
    ->  Sort
          Output: (parallel_restricted(unique1))
          Sort Key: (parallel_restricted(tenk1.unique1))
@@ -53,7 +54,7 @@ select parallel_restricted(unique1) from tenk1
                ->  Parallel Seq Scan on public.tenk1
                      Output: unique1
                      Filter: (tenk1.stringu1 = 'GRAAAA'::name)
-(11 rows)
+(12 rows)
 
 -- test parallel plan when group by expression is in target list.
 explain (costs off)
@@ -78,13 +79,13 @@ select length(stringu1) from tenk1 group by length(stringu1);
 
 explain (costs off)
        select stringu1, count(*) from tenk1 group by stringu1 order by stringu1;
-                           QUERY PLAN                            
------------------------------------------------------------------
- Sort
-   Sort Key: stringu1
-   ->  Finalize GroupAggregate
-         Group Key: stringu1
-         ->  Remote Subquery Scan on all (datanode_1,datanode_2)
+                        QUERY PLAN                         
+-----------------------------------------------------------
+ Finalize GroupAggregate
+   Group Key: stringu1
+   ->  Remote Subquery Scan on all (datanode_1,datanode_2)
+         ->  Sort
+               Sort Key: stringu1
                ->  Partial HashAggregate
                      Group Key: stringu1
                      ->  Gather
index 41ec56b7867641cdfb8e13f6c6c49048cd0d5f9a..ba56c7df0cd94e1762bbb3a544ebc61927b3fd26 100644 (file)
@@ -119,12 +119,13 @@ explain (verbose on, nodes off, costs off) select first_value(val) over (partiti
    Output: first_value(val) OVER (?), val, val2
    ->  Remote Subquery Scan on all
          Output: val, val2
+         Sort Key: tab1_rr.val2, tab1_rr.val
          ->  Sort
                Output: val, val2
                Sort Key: tab1_rr.val2, tab1_rr.val
                ->  Seq Scan on public.tab1_rr
                      Output: val, val2
-(9 rows)
+(10 rows)
 
 -- should not get FQSed because of LIMIT clause
 select * from tab1_rr where val2 = 3 limit 1;
@@ -181,12 +182,13 @@ explain (verbose on, nodes off, costs off) select * from tab1_rr order by val;
 ----------------------------------------
  Remote Subquery Scan on all
    Output: val, val2
+   Sort Key: tab1_rr.val
    ->  Sort
          Output: val, val2
          Sort Key: tab1_rr.val
          ->  Seq Scan on public.tab1_rr
                Output: val, val2
-(7 rows)
+(8 rows)
 
 -- should not get FQSed because of DISTINCT clause
 select distinct val, val2 from tab1_rr where val2 = 8;
@@ -290,13 +292,14 @@ explain (verbose on, nodes off, costs off) select * from tab1_rr where val = 7 o
 ----------------------------------------------------------------
  Remote Subquery Scan on all
    Output: val, val2
+   Sort Key: tab1_rr.val
    ->  Sort
          Output: val, val2
          Sort Key: tab1_rr.val
          ->  Seq Scan on public.tab1_rr
                Output: val, val2
                Filter: ((tab1_rr.val = 7) OR (tab1_rr.val = 2))
-(8 rows)
+(9 rows)
 
 select * from tab1_rr where val = 7 and val2 = 8;
  val | val2 
@@ -380,13 +383,14 @@ explain (verbose on, nodes off, costs off) select val, val2 from tab1_rr where v
 -----------------------------------------
  Remote Subquery Scan on all
    Output: val, val2
+   Sort Key: tab1_rr.val2
    ->  Sort
          Output: val, val2
          Sort Key: tab1_rr.val2
          ->  Seq Scan on public.tab1_rr
                Output: val, val2
                Filter: (tab1_rr.val = 7)
-(8 rows)
+(9 rows)
 
 select distinct val2 from tab1_rr where val = 7;
  val2 
@@ -532,12 +536,13 @@ explain (verbose on, nodes off, costs off) select first_value(val) over (partiti
    Output: first_value(val) OVER (?), val, val2
    ->  Remote Subquery Scan on all
          Output: val, val2
+         Sort Key: tab1_hash.val2, tab1_hash.val
          ->  Sort
                Output: val, val2
                Sort Key: tab1_hash.val2, tab1_hash.val
                ->  Seq Scan on public.tab1_hash
                      Output: val, val2
-(9 rows)
+(10 rows)
 
 -- should not get FQSed because of LIMIT clause
 select * from tab1_hash where val2 = 3 limit 1;
@@ -594,12 +599,13 @@ explain (verbose on, nodes off, costs off) select * from tab1_hash order by val;
 ------------------------------------------
  Remote Subquery Scan on all
    Output: val, val2
+   Sort Key: tab1_hash.val
    ->  Sort
          Output: val, val2
          Sort Key: tab1_hash.val
          ->  Seq Scan on public.tab1_hash
                Output: val, val2
-(7 rows)
+(8 rows)
 
 -- should get FQSed because DISTINCT clause contains distkey
 select distinct val, val2 from tab1_hash where val2 = 8;
@@ -698,13 +704,14 @@ explain (verbose on, nodes off, costs off) select * from tab1_hash where val = 7
 --------------------------------------------------------------------
  Remote Subquery Scan on all
    Output: val, val2
+   Sort Key: tab1_hash.val
    ->  Sort
          Output: val, val2
          Sort Key: tab1_hash.val
          ->  Seq Scan on public.tab1_hash
                Output: val, val2
                Filter: ((tab1_hash.val = 7) OR (tab1_hash.val = 2))
-(8 rows)
+(9 rows)
 
 select * from tab1_hash where val = 7 and val2 = 8;
  val | val2 
@@ -941,12 +948,13 @@ explain (verbose on, nodes off, costs off) select first_value(val) over (partiti
    Output: first_value(val) OVER (?), val, val2
    ->  Remote Subquery Scan on all
          Output: val, val2
+         Sort Key: tab1_modulo.val2, tab1_modulo.val
          ->  Sort
                Output: val, val2
                Sort Key: tab1_modulo.val2, tab1_modulo.val
                ->  Seq Scan on public.tab1_modulo
                      Output: val, val2
-(9 rows)
+(10 rows)
 
 -- should not get FQSed because of LIMIT clause
 select * from tab1_modulo where val2 = 3 limit 1;
@@ -1003,12 +1011,13 @@ explain (verbose on, nodes off, costs off) select * from tab1_modulo order by va
 --------------------------------------------
  Remote Subquery Scan on all
    Output: val, val2
+   Sort Key: tab1_modulo.val
    ->  Sort
          Output: val, val2
          Sort Key: tab1_modulo.val
          ->  Seq Scan on public.tab1_modulo
                Output: val, val2
-(7 rows)
+(8 rows)
 
 -- should get FQSed because DISTINCT clause contains distkey
 select distinct val, val2 from tab1_modulo where val2 = 8;
@@ -1107,13 +1116,14 @@ explain (verbose on, nodes off, costs off) select * from tab1_modulo where val =
 ------------------------------------------------------------------------
  Remote Subquery Scan on all
    Output: val, val2
+   Sort Key: tab1_modulo.val
    ->  Sort
          Output: val, val2
          Sort Key: tab1_modulo.val
          ->  Seq Scan on public.tab1_modulo
                Output: val, val2
                Filter: ((tab1_modulo.val = 7) OR (tab1_modulo.val = 2))
-(8 rows)
+(9 rows)
 
 select * from tab1_modulo where val = 7 and val2 = 8;
  val | val2 
index 6bebddc0b8176ba6b39d3e5524c3c4cb8626f20a..0b0f0b28261e530e4670bed4a24ea0063049c4f3 100644 (file)
@@ -177,12 +177,13 @@ explain (verbose true, costs false, nodes false) select val + val2, val, val2 fr
 --------------------------------------------------------------
  Remote Subquery Scan on all
    Output: (val + val2), val, val2
+   Sort Key: xc_groupby_tab1.val, xc_groupby_tab1.val2
    ->  HashAggregate
          Output: (val + val2), val, val2
          Group Key: xc_groupby_tab1.val, xc_groupby_tab1.val2
          ->  Seq Scan on public.xc_groupby_tab1
                Output: val, val2
-(7 rows)
+(8 rows)
 
 select xc_groupby_tab1.val + xc_groupby_tab2.val2, xc_groupby_tab1.val, xc_groupby_tab2.val2 from xc_groupby_tab1, xc_groupby_tab2 where xc_groupby_tab1.val = xc_groupby_tab2.val group by xc_groupby_tab1.val, xc_groupby_tab2.val2;
  ?column? | val | val2 
@@ -200,6 +201,7 @@ explain (verbose true, costs false, nodes false) select xc_groupby_tab1.val + xc
 ---------------------------------------------------------------------------------------------------------
  Remote Subquery Scan on all
    Output: (xc_groupby_tab1.val + xc_groupby_tab2.val2), xc_groupby_tab1.val, xc_groupby_tab2.val2
+   Sort Key: xc_groupby_tab1.val, xc_groupby_tab2.val2
    ->  HashAggregate
          Output: (xc_groupby_tab1.val + xc_groupby_tab2.val2), xc_groupby_tab1.val, xc_groupby_tab2.val2
          Group Key: xc_groupby_tab1.val, xc_groupby_tab2.val2
@@ -216,7 +218,7 @@ explain (verbose true, costs false, nodes false) select xc_groupby_tab1.val + xc
                      Sort Key: xc_groupby_tab2.val
                      ->  Seq Scan on public.xc_groupby_tab2
                            Output: xc_groupby_tab2.val2, xc_groupby_tab2.val
-(18 rows)
+(19 rows)
 
 select xc_groupby_tab1.val + xc_groupby_tab2.val2 from xc_groupby_tab1, xc_groupby_tab2 where xc_groupby_tab1.val = xc_groupby_tab2.val group by xc_groupby_tab1.val + xc_groupby_tab2.val2;
  ?column? 
@@ -339,6 +341,7 @@ explain (verbose true, costs false, nodes false) select a,count(a) from xc_group
 -----------------------------------------------------
  Remote Subquery Scan on all
    Output: a, count(a)
+   Sort Key: xc_groupby_def.a
    ->  Sort
          Output: a, (count(a))
          Sort Key: xc_groupby_def.a
@@ -347,7 +350,7 @@ explain (verbose true, costs false, nodes false) select a,count(a) from xc_group
                Group Key: xc_groupby_def.a
                ->  Seq Scan on public.xc_groupby_def
                      Output: a, b
-(10 rows)
+(11 rows)
 
 select avg(a) from xc_groupby_def group by a; 
           avg           
@@ -386,12 +389,13 @@ explain (verbose true, costs false, nodes false) select avg(a) from xc_groupby_d
 -----------------------------------------------
  Remote Subquery Scan on all
    Output: avg(a), a
+   Sort Key: xc_groupby_def.a
    ->  HashAggregate
          Output: avg(a), a
          Group Key: xc_groupby_def.a
          ->  Seq Scan on public.xc_groupby_def
                Output: a, b
-(7 rows)
+(8 rows)
 
 select avg(a) from xc_groupby_def group by b;
         avg         
@@ -485,13 +489,14 @@ explain (verbose true, costs false, nodes false) select count(*) from xc_groupby
 ------------------------------------------------------
  Remote Subquery Scan on all
    Output: count(*), a
+   Sort Key: xc_groupby_def.a
    ->  HashAggregate
          Output: count(*), a
          Group Key: xc_groupby_def.a
          ->  Seq Scan on public.xc_groupby_def
                Output: a, b
                Filter: (xc_groupby_def.a IS NOT NULL)
-(8 rows)
+(9 rows)
 
 select * from (select b from xc_groupby_def group by b) q order by q.b;
    b   
@@ -585,12 +590,13 @@ explain (verbose true, costs false, nodes false) select sum(a) from xc_groupby_g
 ---------------------------------------------
  Remote Subquery Scan on all
    Output: sum(a), a
+   Sort Key: xc_groupby_g.a
    ->  HashAggregate
          Output: sum(a), a
          Group Key: xc_groupby_g.a
          ->  Seq Scan on public.xc_groupby_g
                Output: a, b, c
-(7 rows)
+(8 rows)
 
 select sum(b) from xc_groupby_g group by b;
  sum 
@@ -1549,6 +1555,7 @@ explain (verbose true, costs false, nodes false) select val + val2, val, val2 fr
 -------------------------------------------------------------------
  Remote Subquery Scan on all
    Output: (val + val2), val, val2
+   Sort Key: xc_groupby_tab1.val, xc_groupby_tab1.val2
    ->  Group
          Output: (val + val2), val, val2
          Group Key: xc_groupby_tab1.val, xc_groupby_tab1.val2
@@ -1557,7 +1564,7 @@ explain (verbose true, costs false, nodes false) select val + val2, val, val2 fr
                Sort Key: xc_groupby_tab1.val, xc_groupby_tab1.val2
                ->  Seq Scan on public.xc_groupby_tab1
                      Output: val, val2
-(10 rows)
+(11 rows)
 
 select xc_groupby_tab1.val + xc_groupby_tab2.val2, xc_groupby_tab1.val, xc_groupby_tab2.val2 from xc_groupby_tab1, xc_groupby_tab2 where xc_groupby_tab1.val = xc_groupby_tab2.val group by xc_groupby_tab1.val, xc_groupby_tab2.val2;
  ?column? | val | val2 
@@ -1575,6 +1582,7 @@ explain (verbose true, costs false, nodes false) select xc_groupby_tab1.val + xc
 ---------------------------------------------------------------------------------------------------------
  Remote Subquery Scan on all
    Output: (xc_groupby_tab1.val + xc_groupby_tab2.val2), xc_groupby_tab1.val, xc_groupby_tab2.val2
+   Sort Key: xc_groupby_tab1.val, xc_groupby_tab2.val2
    ->  Group
          Output: (xc_groupby_tab1.val + xc_groupby_tab2.val2), xc_groupby_tab1.val, xc_groupby_tab2.val2
          Group Key: xc_groupby_tab1.val, xc_groupby_tab2.val2
@@ -1594,7 +1602,7 @@ explain (verbose true, costs false, nodes false) select xc_groupby_tab1.val + xc
                            Sort Key: xc_groupby_tab2.val
                            ->  Seq Scan on public.xc_groupby_tab2
                                  Output: xc_groupby_tab2.val2, xc_groupby_tab2.val
-(21 rows)
+(22 rows)
 
 select xc_groupby_tab1.val + xc_groupby_tab2.val2 from xc_groupby_tab1, xc_groupby_tab2 where xc_groupby_tab1.val = xc_groupby_tab2.val group by xc_groupby_tab1.val + xc_groupby_tab2.val2;
  ?column? 
@@ -1613,6 +1621,7 @@ explain (verbose true, costs false, nodes false) select xc_groupby_tab1.val + xc
    Group Key: (xc_groupby_tab1.val + xc_groupby_tab2.val2)
    ->  Remote Subquery Scan on all
          Output: (xc_groupby_tab1.val + xc_groupby_tab2.val2)
+         Sort Key: (xc_groupby_tab1.val + xc_groupby_tab2.val2)
          ->  Sort
                Output: ((xc_groupby_tab1.val + xc_groupby_tab2.val2))
                Sort Key: ((xc_groupby_tab1.val + xc_groupby_tab2.val2))
@@ -1629,7 +1638,7 @@ explain (verbose true, costs false, nodes false) select xc_groupby_tab1.val + xc
                            Sort Key: xc_groupby_tab2.val
                            ->  Seq Scan on public.xc_groupby_tab2
                                  Output: xc_groupby_tab2.val2, xc_groupby_tab2.val
-(21 rows)
+(22 rows)
 
 -- group by with aggregates in expression
 select count(*) + sum(val) + avg(val), val2 from xc_groupby_tab1 group by val2;
@@ -1723,6 +1732,7 @@ explain (verbose true, costs false, nodes false) select a,count(a) from xc_group
 -----------------------------------------------------
  Remote Subquery Scan on all
    Output: a, count(a)
+   Sort Key: xc_groupby_def.a
    ->  GroupAggregate
          Output: a, count(a)
          Group Key: xc_groupby_def.a
@@ -1731,7 +1741,7 @@ explain (verbose true, costs false, nodes false) select a,count(a) from xc_group
                Sort Key: xc_groupby_def.a
                ->  Seq Scan on public.xc_groupby_def
                      Output: a
-(10 rows)
+(11 rows)
 
 select avg(a) from xc_groupby_def group by a; 
           avg           
@@ -1770,6 +1780,7 @@ explain (verbose true, costs false, nodes false) select avg(a) from xc_groupby_d
 -----------------------------------------------------
  Remote Subquery Scan on all
    Output: avg(a), a
+   Sort Key: xc_groupby_def.a
    ->  GroupAggregate
          Output: avg(a), a
          Group Key: xc_groupby_def.a
@@ -1778,7 +1789,7 @@ explain (verbose true, costs false, nodes false) select avg(a) from xc_groupby_d
                Sort Key: xc_groupby_def.a
                ->  Seq Scan on public.xc_groupby_def
                      Output: a
-(10 rows)
+(11 rows)
 
 select avg(a) from xc_groupby_def group by b;
         avg         
@@ -1881,6 +1892,7 @@ explain (verbose true, costs false, nodes false) select count(*) from xc_groupby
 ------------------------------------------------------------
  Remote Subquery Scan on all
    Output: count(*), a
+   Sort Key: xc_groupby_def.a
    ->  GroupAggregate
          Output: count(*), a
          Group Key: xc_groupby_def.a
@@ -1890,7 +1902,7 @@ explain (verbose true, costs false, nodes false) select count(*) from xc_groupby
                ->  Seq Scan on public.xc_groupby_def
                      Output: a
                      Filter: (xc_groupby_def.a IS NOT NULL)
-(11 rows)
+(12 rows)
 
 select b from xc_groupby_def group by b;
    b   
@@ -1984,6 +1996,7 @@ explain (verbose true, costs false, nodes false) select sum(a) from xc_groupby_g
 ---------------------------------------------------
  Remote Subquery Scan on all
    Output: sum(a), a
+   Sort Key: xc_groupby_g.a
    ->  GroupAggregate
          Output: sum(a), a
          Group Key: xc_groupby_g.a
@@ -1992,7 +2005,7 @@ explain (verbose true, costs false, nodes false) select sum(a) from xc_groupby_g
                Sort Key: xc_groupby_g.a
                ->  Seq Scan on public.xc_groupby_g
                      Output: a
-(10 rows)
+(11 rows)
 
 select sum(b) from xc_groupby_g group by b;
  sum 
@@ -3176,6 +3189,7 @@ explain (verbose true, costs false, nodes false) select a,count(a) from xc_group
 -----------------------------------------------------
  Remote Subquery Scan on all
    Output: a, count(a)
+   Sort Key: xc_groupby_def.a
    ->  Sort
          Output: a, (count(a))
          Sort Key: xc_groupby_def.a
@@ -3184,7 +3198,7 @@ explain (verbose true, costs false, nodes false) select a,count(a) from xc_group
                Group Key: xc_groupby_def.a
                ->  Seq Scan on public.xc_groupby_def
                      Output: a, b
-(10 rows)
+(11 rows)
 
 select avg(a) from xc_groupby_def group by a; 
           avg           
@@ -3223,12 +3237,13 @@ explain (verbose true, costs false, nodes false) select avg(a) from xc_groupby_d
 -----------------------------------------------
  Remote Subquery Scan on all
    Output: avg(a), a
+   Sort Key: xc_groupby_def.a
    ->  HashAggregate
          Output: avg(a), a
          Group Key: xc_groupby_def.a
          ->  Seq Scan on public.xc_groupby_def
                Output: a, b
-(7 rows)
+(8 rows)
 
 select avg(a) from xc_groupby_def group by b;
         avg         
@@ -3322,13 +3337,14 @@ explain (verbose true, costs false, nodes false) select count(*) from xc_groupby
 ------------------------------------------------------
  Remote Subquery Scan on all
    Output: count(*), a
+   Sort Key: xc_groupby_def.a
    ->  HashAggregate
          Output: count(*), a
          Group Key: xc_groupby_def.a
          ->  Seq Scan on public.xc_groupby_def
                Output: a, b
                Filter: (xc_groupby_def.a IS NOT NULL)
-(8 rows)
+(9 rows)
 
 select * from (select b from xc_groupby_def group by b) q order by q.b;
    b   
@@ -3422,12 +3438,13 @@ explain (verbose true, costs false, nodes false) select sum(a) from xc_groupby_g
 ---------------------------------------------
  Remote Subquery Scan on all
    Output: sum(a), a
+   Sort Key: xc_groupby_g.a
    ->  HashAggregate
          Output: sum(a), a
          Group Key: xc_groupby_g.a
          ->  Seq Scan on public.xc_groupby_g
                Output: a, b, c
-(7 rows)
+(8 rows)
 
 select sum(b) from xc_groupby_g group by b;
  sum 
@@ -4470,6 +4487,7 @@ explain (verbose true, costs false, nodes false) select xc_groupby_tab1.val + xc
    Group Key: (xc_groupby_tab1.val + xc_groupby_tab2.val2)
    ->  Remote Subquery Scan on all
          Output: (xc_groupby_tab1.val + xc_groupby_tab2.val2)
+         Sort Key: (xc_groupby_tab1.val + xc_groupby_tab2.val2)
          ->  Sort
                Output: ((xc_groupby_tab1.val + xc_groupby_tab2.val2))
                Sort Key: ((xc_groupby_tab1.val + xc_groupby_tab2.val2))
@@ -4486,7 +4504,7 @@ explain (verbose true, costs false, nodes false) select xc_groupby_tab1.val + xc
                            Sort Key: xc_groupby_tab2.val
                            ->  Seq Scan on public.xc_groupby_tab2
                                  Output: xc_groupby_tab2.val2, xc_groupby_tab2.val
-(21 rows)
+(22 rows)
 
 -- group by with aggregates in expression
 select count(*) + sum(val) + avg(val), val2 from xc_groupby_tab1 group by val2;
@@ -4580,6 +4598,7 @@ explain (verbose true, costs false, nodes false) select a,count(a) from xc_group
 -----------------------------------------------------
  Remote Subquery Scan on all
    Output: a, count(a)
+   Sort Key: xc_groupby_def.a
    ->  GroupAggregate
          Output: a, count(a)
          Group Key: xc_groupby_def.a
@@ -4588,7 +4607,7 @@ explain (verbose true, costs false, nodes false) select a,count(a) from xc_group
                Sort Key: xc_groupby_def.a
                ->  Seq Scan on public.xc_groupby_def
                      Output: a
-(10 rows)
+(11 rows)
 
 select avg(a) from xc_groupby_def group by a; 
           avg           
@@ -4627,6 +4646,7 @@ explain (verbose true, costs false, nodes false) select avg(a) from xc_groupby_d
 -----------------------------------------------------
  Remote Subquery Scan on all
    Output: avg(a), a
+   Sort Key: xc_groupby_def.a
    ->  GroupAggregate
          Output: avg(a), a
          Group Key: xc_groupby_def.a
@@ -4635,7 +4655,7 @@ explain (verbose true, costs false, nodes false) select avg(a) from xc_groupby_d
                Sort Key: xc_groupby_def.a
                ->  Seq Scan on public.xc_groupby_def
                      Output: a
-(10 rows)
+(11 rows)
 
 select avg(a) from xc_groupby_def group by b;
         avg         
@@ -4738,6 +4758,7 @@ explain (verbose true, costs false, nodes false) select count(*) from xc_groupby
 ------------------------------------------------------------
  Remote Subquery Scan on all
    Output: count(*), a
+   Sort Key: xc_groupby_def.a
    ->  GroupAggregate
          Output: count(*), a
          Group Key: xc_groupby_def.a
@@ -4747,7 +4768,7 @@ explain (verbose true, costs false, nodes false) select count(*) from xc_groupby
                ->  Seq Scan on public.xc_groupby_def
                      Output: a
                      Filter: (xc_groupby_def.a IS NOT NULL)
-(11 rows)
+(12 rows)
 
 select b from xc_groupby_def group by b;
    b   
@@ -4841,6 +4862,7 @@ explain (verbose true, costs false, nodes false) select sum(a) from xc_groupby_g
 ---------------------------------------------------
  Remote Subquery Scan on all
    Output: sum(a), a
+   Sort Key: xc_groupby_g.a
    ->  GroupAggregate
          Output: sum(a), a
          Group Key: xc_groupby_g.a
@@ -4849,7 +4871,7 @@ explain (verbose true, costs false, nodes false) select sum(a) from xc_groupby_g
                Sort Key: xc_groupby_g.a
                ->  Seq Scan on public.xc_groupby_g
                      Output: a
-(10 rows)
+(11 rows)
 
 select sum(b) from xc_groupby_g group by b;
  sum