Re: Hash support for grouping sets

From: Mark Dilger <hornschnorter(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk>
Subject: Re: Hash support for grouping sets
Date: 2017-03-07 21:43:32
Message-ID: 20170307214332.10866.34332.pgcf@coridan.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

The following review has been posted through the commitfest application:
make installcheck-world: tested, failed
Implements feature: not tested
Spec compliant: not tested
Documentation: not tested

On my MacBook, `make check-world` gives differences in the contrib modules:

cat contrib/postgres_fdw/regression.diffs
*** /Users/mark/hydra/postgresql.review/contrib/postgres_fdw/expected/postgres_fdw.out 2017-03-03 13:33:47.000000000 -0800
--- /Users/mark/hydra/postgresql.review/contrib/postgres_fdw/results/postgres_fdw.out 2017-03-07 13:27:56.000000000 -0800
***************
*** 3148,3163 ****
-- Grouping sets
explain (verbose, costs off)
select c2, sum(c1) from ft1 where c2 < 3 group by rollup(c2) order by 1 nulls last;
! QUERY PLAN
! ---------------------------------------------------------------------------------------------------
! GroupAggregate
! Output: c2, sum(c1)
! Group Key: ft1.c2
! Group Key: ()
! -> Foreign Scan on public.ft1
! Output: c2, c1
! Remote SQL: SELECT "C 1", c2 FROM "S 1"."T 1" WHERE ((c2 < 3)) ORDER BY c2 ASC NULLS LAST
! (7 rows)

select c2, sum(c1) from ft1 where c2 < 3 group by rollup(c2) order by 1 nulls last;
c2 | sum
--- 3148,3166 ----
-- Grouping sets
explain (verbose, costs off)
select c2, sum(c1) from ft1 where c2 < 3 group by rollup(c2) order by 1 nulls last;
! QUERY PLAN
! ------------------------------------------------------------------------------
! Sort
! Output: c2, (sum(c1))
! Sort Key: ft1.c2
! -> MixedAggregate
! Output: c2, sum(c1)
! Hash Key: ft1.c2
! Group Key: ()
! -> Foreign Scan on public.ft1
! Output: c2, c1
! Remote SQL: SELECT "C 1", c2 FROM "S 1"."T 1" WHERE ((c2 < 3))
! (10 rows)

select c2, sum(c1) from ft1 where c2 < 3 group by rollup(c2) order by 1 nulls last;
c2 | sum
***************
*** 3170,3185 ****

explain (verbose, costs off)
select c2, sum(c1) from ft1 where c2 < 3 group by cube(c2) order by 1 nulls last;
! QUERY PLAN
! ---------------------------------------------------------------------------------------------------
! GroupAggregate
! Output: c2, sum(c1)
! Group Key: ft1.c2
! Group Key: ()
! -> Foreign Scan on public.ft1
! Output: c2, c1
! Remote SQL: SELECT "C 1", c2 FROM "S 1"."T 1" WHERE ((c2 < 3)) ORDER BY c2 ASC NULLS LAST
! (7 rows)

select c2, sum(c1) from ft1 where c2 < 3 group by cube(c2) order by 1 nulls last;
c2 | sum
--- 3173,3191 ----

explain (verbose, costs off)
select c2, sum(c1) from ft1 where c2 < 3 group by cube(c2) order by 1 nulls last;
! QUERY PLAN
! ------------------------------------------------------------------------------
! Sort
! Output: c2, (sum(c1))
! Sort Key: ft1.c2
! -> MixedAggregate
! Output: c2, sum(c1)
! Hash Key: ft1.c2
! Group Key: ()
! -> Foreign Scan on public.ft1
! Output: c2, c1
! Remote SQL: SELECT "C 1", c2 FROM "S 1"."T 1" WHERE ((c2 < 3))
! (10 rows)

select c2, sum(c1) from ft1 where c2 < 3 group by cube(c2) order by 1 nulls last;
c2 | sum
***************
*** 3192,3211 ****

explain (verbose, costs off)
select c2, c6, sum(c1) from ft1 where c2 < 3 group by grouping sets(c2, c6) order by 1 nulls last, 2 nulls last;
! QUERY PLAN
! -------------------------------------------------------------------------------------------------------------
Sort
Output: c2, c6, (sum(c1))
Sort Key: ft1.c2, ft1.c6
! -> GroupAggregate
Output: c2, c6, sum(c1)
! Group Key: ft1.c2
! Sort Key: ft1.c6
! Group Key: ft1.c6
-> Foreign Scan on public.ft1
Output: c2, c6, c1
! Remote SQL: SELECT "C 1", c2, c6 FROM "S 1"."T 1" WHERE ((c2 < 3)) ORDER BY c2 ASC NULLS LAST
! (11 rows)

select c2, c6, sum(c1) from ft1 where c2 < 3 group by grouping sets(c2, c6) order by 1 nulls last, 2 nulls last;
c2 | c6 | sum
--- 3198,3216 ----

explain (verbose, costs off)
select c2, c6, sum(c1) from ft1 where c2 < 3 group by grouping sets(c2, c6) order by 1 nulls last, 2 nulls last;
! QUERY PLAN
! ----------------------------------------------------------------------------------
Sort
Output: c2, c6, (sum(c1))
Sort Key: ft1.c2, ft1.c6
! -> HashAggregate
Output: c2, c6, sum(c1)
! Hash Key: ft1.c2
! Hash Key: ft1.c6
-> Foreign Scan on public.ft1
Output: c2, c6, c1
! Remote SQL: SELECT "C 1", c2, c6 FROM "S 1"."T 1" WHERE ((c2 < 3))
! (10 rows)

select c2, c6, sum(c1) from ft1 where c2 < 3 group by grouping sets(c2, c6) order by 1 nulls last, 2 nulls last;
c2 | c6 | sum

======================================================================

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Mark Dilger 2017-03-07 21:53:03 Re: Hash support for grouping sets
Previous Message Sven R. Kunze 2017-03-07 21:43:16 Re: SQL/JSON in PostgreSQL