-- Since we are testing, the plan reduction of GROUP and AGG nodes, we should
-- disable fast query shipping
set enable_fast_query_shipping to off;
-ERROR: unrecognized configuration parameter "enable_fast_query_shipping"
-- Combination 1: enable_hashagg on and distributed tables
set enable_hashagg to on;
-- create required tables and fill them with data
(1 row)
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 val2 + 1 > 3;
- QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- Remote Fast Query Execution
- Output: count(*), sum(xc_having_tab1.val), avg(xc_having_tab1.val), ((sum(xc_having_tab1.val))::double precision / (count(*))::double precision), xc_having_tab1.val2
- Remote query: SELECT count(*) AS count, sum(val) AS sum, avg(val) AS avg, ((sum(val))::double precision / (count(*))::double precision), val2 FROM xc_having_tab1 GROUP BY val2 HAVING ((val2 + 1) > 3)
+ QUERY PLAN
+-------------------------------------------------------------------------------------------------------------------
+ Remote Subquery Scan on all
+ Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2
-> HashAggregate
Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2
Group Key: xc_having_tab1.val2
-> Seq Scan on public.xc_having_tab1
Output: val, val2
Filter: ((xc_having_tab1.val2 + 1) > 3)
-(9 rows)
+(8 rows)
-- 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;
(1 row)
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;
- QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- Remote Fast Query Execution
- Output: count(*), sum(xc_having_tab1.val), avg(xc_having_tab1.val), ((sum(xc_having_tab1.val))::double precision / (count(*))::double precision), xc_having_tab1.val2
- Remote query: SELECT count(*) AS count, sum(val) AS sum, avg(val) AS avg, ((sum(val))::double precision / (count(*))::double precision), val2 FROM xc_having_tab1 GROUP BY val2 HAVING (avg(val) > 3.75)
+ QUERY PLAN
+-------------------------------------------------------------------------------------------------------------------
+ Remote Subquery Scan on all
+ Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2
-> 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)
-> Seq Scan on public.xc_having_tab1
Output: val, val2
-(9 rows)
+(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;
count | sum | avg | ?column? | val2
(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;
- QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- Remote Fast Query Execution
- Output: count(*), sum(xc_having_tab1.val), avg(xc_having_tab1.val), ((sum(xc_having_tab1.val))::double precision / (count(*))::double precision), xc_having_tab1.val2
- Remote query: SELECT count(*) AS count, sum(val) AS sum, avg(val) AS avg, ((sum(val))::double precision / (count(*))::double precision), val2 FROM xc_having_tab1 GROUP BY val2 HAVING ((avg(val) > 3.75) OR (val2 > 2))
+ QUERY PLAN
+-------------------------------------------------------------------------------------------------------------------
+ Remote Subquery Scan on all
+ Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2
-> 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
-(9 rows)
+(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 and val2 > 2;
count | sum | avg | ?column? | val2
(0 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 and val2 > 2;
- QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- Remote Fast Query Execution
- Output: count(*), sum(xc_having_tab1.val), avg(xc_having_tab1.val), ((sum(xc_having_tab1.val))::double precision / (count(*))::double precision), xc_having_tab1.val2
- Remote query: SELECT count(*) AS count, sum(val) AS sum, avg(val) AS avg, ((sum(val))::double precision / (count(*))::double precision), val2 FROM xc_having_tab1 GROUP BY val2 HAVING ((avg(val) > 3.75) AND (val2 > 2))
+ QUERY PLAN
+-------------------------------------------------------------------------------------------------------------------
+ Remote Subquery Scan on all
+ Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2
-> HashAggregate
Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2
Group Key: xc_having_tab1.val2
-> Seq Scan on public.xc_having_tab1
Output: val, val2
Filter: (xc_having_tab1.val2 > 2)
-(10 rows)
+(9 rows)
-- joins and group by and having
select count(*), sum(xc_having_tab1.val * xc_having_tab2.val), avg(xc_having_tab1.val*xc_having_tab2.val), sum(xc_having_tab1.val*xc_having_tab2.val)::float8/count(*), xc_having_tab1.val2, xc_having_tab2.val2 from xc_having_tab1 full outer join xc_having_tab2 on xc_having_tab1.val2 = xc_having_tab2.val2 group by xc_having_tab1.val2, xc_having_tab2.val2 having xc_having_tab1.val2 + xc_having_tab2.val2 > 2;
(1 row)
explain (verbose true, costs false, nodes false) select val2 from xc_having_tab1 group by val2 having sum(val) > 8;
- QUERY PLAN
--------------------------------------------------------------------------------------
- Remote Fast Query Execution
- Output: xc_having_tab1.val2
- Remote query: SELECT val2 FROM xc_having_tab1 GROUP BY val2 HAVING (sum(val) > 8)
+ QUERY PLAN
+-----------------------------------------------
+ Remote Subquery Scan on all
+ Output: val2
-> HashAggregate
Output: val2
Group Key: xc_having_tab1.val2
Filter: (sum(xc_having_tab1.val) > 8)
-> Seq Scan on public.xc_having_tab1
Output: val, val2
-(9 rows)
+(8 rows)
select * from (select val + val2 sum from xc_having_tab1 group by val + val2 having sum(val) > 5) q order by q.sum;
sum
(1 row)
explain (verbose true, costs false, nodes false) select count(*) + sum(val) + avg(val), val2 from xc_having_tab1 group by val2 having min(val) < val2;
- QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------
- Remote Fast Query Execution
- Output: (((count(*) + sum(xc_having_tab1.val)))::numeric + avg(xc_having_tab1.val)), xc_having_tab1.val2
- Remote query: SELECT (((count(*) + sum(val)))::numeric + avg(val)), val2 FROM xc_having_tab1 GROUP BY val2 HAVING (min(val) < val2)
+ QUERY PLAN
+---------------------------------------------------------------------
+ Remote Subquery Scan on all
+ Output: (((count(*) + sum(val)))::numeric + avg(val)), val2
-> HashAggregate
Output: (((count(*) + sum(val)))::numeric + avg(val)), val2
Group Key: xc_having_tab1.val2
Filter: (min(xc_having_tab1.val) < xc_having_tab1.val2)
-> Seq Scan on public.xc_having_tab1
Output: val, val2
-(9 rows)
+(8 rows)
drop table xc_having_tab1;
drop table xc_having_tab2;
(1 row)
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 val2 + 1 > 3;
- QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- Remote Fast Query Execution
- Output: count(*), sum(xc_having_tab1.val), avg(xc_having_tab1.val), ((sum(xc_having_tab1.val))::double precision / (count(*))::double precision), xc_having_tab1.val2
- Remote query: SELECT count(*) AS count, sum(val) AS sum, avg(val) AS avg, ((sum(val))::double precision / (count(*))::double precision), val2 FROM xc_having_tab1 GROUP BY val2 HAVING ((val2 + 1) > 3)
+ QUERY PLAN
+-------------------------------------------------------------------------------------------------------------------
+ Remote Subquery Scan on all
+ Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2
-> GroupAggregate
Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2
Group Key: xc_having_tab1.val2
-> Seq Scan on public.xc_having_tab1
Output: val2, val
Filter: ((xc_having_tab1.val2 + 1) > 3)
-(12 rows)
+(11 rows)
-- 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;
(1 row)
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;
- QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- Remote Fast Query Execution
- Output: count(*), sum(xc_having_tab1.val), avg(xc_having_tab1.val), ((sum(xc_having_tab1.val))::double precision / (count(*))::double precision), xc_having_tab1.val2
- Remote query: SELECT count(*) AS count, sum(val) AS sum, avg(val) AS avg, ((sum(val))::double precision / (count(*))::double precision), val2 FROM xc_having_tab1 GROUP BY val2 HAVING (avg(val) > 3.75)
+ QUERY PLAN
+-------------------------------------------------------------------------------------------------------------------
+ Remote Subquery Scan on all
+ Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2
-> GroupAggregate
Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2
Group Key: xc_having_tab1.val2
Sort Key: xc_having_tab1.val2
-> Seq Scan on public.xc_having_tab1
Output: val2, val
-(12 rows)
+(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;
count | sum | avg | ?column? | val2
(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;
- QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- Remote Fast Query Execution
- Output: count(*), sum(xc_having_tab1.val), avg(xc_having_tab1.val), ((sum(xc_having_tab1.val))::double precision / (count(*))::double precision), xc_having_tab1.val2
- Remote query: SELECT count(*) AS count, sum(val) AS sum, avg(val) AS avg, ((sum(val))::double precision / (count(*))::double precision), val2 FROM xc_having_tab1 GROUP BY val2 HAVING ((avg(val) > 3.75) OR (val2 > 2))
+ QUERY PLAN
+-------------------------------------------------------------------------------------------------------------------
+ Remote Subquery Scan on all
+ Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2
-> GroupAggregate
Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2
Group Key: xc_having_tab1.val2
Sort Key: xc_having_tab1.val2
-> Seq Scan on public.xc_having_tab1
Output: val2, val
-(12 rows)
+(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 and val2 > 2;
count | sum | avg | ?column? | val2
(0 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 and val2 > 2;
- QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- Remote Fast Query Execution
- Output: count(*), sum(xc_having_tab1.val), avg(xc_having_tab1.val), ((sum(xc_having_tab1.val))::double precision / (count(*))::double precision), xc_having_tab1.val2
- Remote query: SELECT count(*) AS count, sum(val) AS sum, avg(val) AS avg, ((sum(val))::double precision / (count(*))::double precision), val2 FROM xc_having_tab1 GROUP BY val2 HAVING ((avg(val) > 3.75) AND (val2 > 2))
+ QUERY PLAN
+-------------------------------------------------------------------------------------------------------------------
+ Remote Subquery Scan on all
+ Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2
-> GroupAggregate
Output: count(*), sum(val), avg(val), ((sum(val))::double precision / (count(*))::double precision), val2
Group Key: xc_having_tab1.val2
-> Seq Scan on public.xc_having_tab1
Output: val2, val
Filter: (xc_having_tab1.val2 > 2)
-(13 rows)
+(12 rows)
-- joins and group by and having
select count(*), sum(xc_having_tab1.val * xc_having_tab2.val), avg(xc_having_tab1.val*xc_having_tab2.val), sum(xc_having_tab1.val*xc_having_tab2.val)::float8/count(*), xc_having_tab1.val2, xc_having_tab2.val2 from xc_having_tab1 full outer join xc_having_tab2 on xc_having_tab1.val2 = xc_having_tab2.val2 group by xc_having_tab1.val2, xc_having_tab2.val2 having xc_having_tab1.val2 + xc_having_tab2.val2 > 2;
(1 row)
explain (verbose true, costs false, nodes false) select val2 from xc_having_tab1 group by val2 having sum(val) > 8;
- QUERY PLAN
--------------------------------------------------------------------------------------
- Remote Fast Query Execution
- Output: xc_having_tab1.val2
- Remote query: SELECT val2 FROM xc_having_tab1 GROUP BY val2 HAVING (sum(val) > 8)
+ QUERY PLAN
+-----------------------------------------------------
+ Remote Subquery Scan on all
+ Output: val2
-> GroupAggregate
Output: val2
Group Key: xc_having_tab1.val2
Sort Key: xc_having_tab1.val2
-> Seq Scan on public.xc_having_tab1
Output: val2, val
-(12 rows)
+(11 rows)
select val + val2 from xc_having_tab1 group by val + val2 having sum(val) > 5;
?column?
(3 rows)
explain (verbose true, costs false, nodes false) select val + val2 from xc_having_tab1 group by val + val2 having sum(val) > 5;
- QUERY PLAN
------------------------------------------------------------------------------------------------------
- Remote Fast Query Execution
- Output: (xc_having_tab1.val + xc_having_tab1.val2)
- Remote query: SELECT (val + val2) FROM xc_having_tab1 GROUP BY (val + val2) HAVING (sum(val) > 5)
+ QUERY PLAN
+----------------------------------------------------------------------
+ Remote Subquery Scan on all
+ Output: (val + val2)
-> GroupAggregate
Output: ((val + val2))
Group Key: ((xc_having_tab1.val + xc_having_tab1.val2))
Sort Key: ((xc_having_tab1.val + xc_having_tab1.val2))
-> Seq Scan on public.xc_having_tab1
Output: (val + val2), val
-(12 rows)
+(11 rows)
-- group by with aggregates in expression
select count(*) + sum(val) + avg(val), val2 from xc_having_tab1 group by val2 having min(val) < val2;
(1 row)
explain (verbose true, costs false, nodes false) select count(*) + sum(val) + avg(val), val2 from xc_having_tab1 group by val2 having min(val) < val2;
- QUERY PLAN
----------------------------------------------------------------------------------------------------------------------------------------
- Remote Fast Query Execution
- Output: (((count(*) + sum(xc_having_tab1.val)))::numeric + avg(xc_having_tab1.val)), xc_having_tab1.val2
- Remote query: SELECT (((count(*) + sum(val)))::numeric + avg(val)), val2 FROM xc_having_tab1 GROUP BY val2 HAVING (min(val) < val2)
+ QUERY PLAN
+---------------------------------------------------------------------
+ Remote Subquery Scan on all
+ Output: (((count(*) + sum(val)))::numeric + avg(val)), val2
-> GroupAggregate
Output: (((count(*) + sum(val)))::numeric + avg(val)), val2
Group Key: xc_having_tab1.val2
Sort Key: xc_having_tab1.val2
-> Seq Scan on public.xc_having_tab1
Output: val2, val
-(12 rows)
+(11 rows)
drop table xc_having_tab1;
drop table xc_having_tab2;
reset enable_hashagg;
reset enable_fast_query_shipping;
-ERROR: unrecognized configuration parameter "enable_fast_query_shipping"