Stabilize result ordering in xc_having regression test
authorTomas Vondra <[email protected]>
Fri, 14 Jul 2017 23:43:53 +0000 (01:43 +0200)
committerTomas Vondra <[email protected]>
Fri, 14 Jul 2017 23:43:53 +0000 (01:43 +0200)
Stabilized by adding ORDER BY clause to two queries. Generate explain
plans both for the original and modified queries.

src/test/regress/expected/xc_having.out
src/test/regress/sql/xc_having.sql

index 1de1cf4b6a7e74319cd9753cd7bd44fb61288d28..9fea4093edc9eae9a9070bab70b81b85f4a740dc 100644 (file)
@@ -59,13 +59,32 @@ explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(
                      Output: val, val2
 (11 rows)
 
-select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2;
+select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2 order by 1;
  count | sum |        avg         |     ?column?     | val2 
 -------+-----+--------------------+------------------+------
-     3 |  11 | 3.6666666666666667 | 3.66666666666667 |    3
      2 |   8 | 4.0000000000000000 |                4 |    2
+     3 |  11 | 3.6666666666666667 | 3.66666666666667 |    3
 (2 rows)
 
+explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2 order by 1;
+                                                     QUERY PLAN                                                      
+---------------------------------------------------------------------------------------------------------------------
+ Sort
+   Output: (count(*)), (sum(val)), (avg(val)), (((sum(val))::double precision / (count(*))::double precision)), val2
+   Sort Key: (count(*))
+   ->  Finalize HashAggregate
+         Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2
+         Group Key: xc_having_tab1.val2
+         Filter: ((avg(xc_having_tab1.val) > 3.75) OR (xc_having_tab1.val2 > 2))
+         ->  Remote Subquery Scan on all
+               Output: val2, PARTIAL count(*), PARTIAL sum(val), PARTIAL avg(val)
+               ->  Partial HashAggregate
+                     Output: val2, PARTIAL count(*), PARTIAL sum(val), PARTIAL avg(val)
+                     Group Key: xc_having_tab1.val2
+                     ->  Seq Scan on public.xc_having_tab1
+                           Output: val, val2
+(14 rows)
+
 explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2;
                                                  QUERY PLAN                                                  
 -------------------------------------------------------------------------------------------------------------
@@ -269,13 +288,29 @@ explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(
                Output: val, val2
 (8 rows)
 
-select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2;
+select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2 order by 1;
  count | sum |        avg         |     ?column?     | val2 
 -------+-----+--------------------+------------------+------
-     3 |  11 | 3.6666666666666667 | 3.66666666666667 |    3
      2 |   8 | 4.0000000000000000 |                4 |    2
+     3 |  11 | 3.6666666666666667 | 3.66666666666667 |    3
 (2 rows)
 
+explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2 order by 1;
+                                                        QUERY PLAN                                                         
+---------------------------------------------------------------------------------------------------------------------------
+ Remote Subquery Scan on all
+   Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2
+   ->  Sort
+         Output: (count(*)), (sum(val)), (avg(val)), (((sum(val))::double precision / (count(*))::double precision)), val2
+         Sort Key: (count(*))
+         ->  HashAggregate
+               Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2
+               Group Key: xc_having_tab1.val2
+               Filter: ((avg(xc_having_tab1.val) > 3.75) OR (xc_having_tab1.val2 > 2))
+               ->  Seq Scan on public.xc_having_tab1
+                     Output: val, val2
+(11 rows)
+
 explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2;
                                                     QUERY PLAN                                                     
 -------------------------------------------------------------------------------------------------------------------
index 061ca3ae1c7169cfb131f25606b7aab1c49a7676..4f11110115dbc4a7ae98de558d1bed26fe26e80e 100644 (file)
@@ -21,7 +21,8 @@ explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(
 -- having clause containing aggregate
 select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75;
 explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75;
-select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2;
+select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2 order by 1;
+explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2 order by 1;
 explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2;
 select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 and val2 > 2;
 explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 and val2 > 2;
@@ -52,7 +53,8 @@ explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(
 -- having clause containing aggregate
 select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75;
 explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75;
-select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2;
+select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2 order by 1;
+explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2 order by 1;
 explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 or val2 > 2;
 select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 and val2 > 2;
 explain (verbose true, costs false, nodes false) select count(*), sum(val), avg(val), sum(val)::float8/count(*), val2 from xc_having_tab1 group by val2 having avg(val) > 3.75 and val2 > 2;