From: Tomas Vondra <tomas.vondra@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Implement GROUP BY DISTINCT
Date: Thu, 18 Mar 2021 17:23:04 +0000
Message-ID: <E1lMwMS-0007AP-Qu@gemulon.postgresql.org> (raw)
Implement GROUP BY DISTINCT
With grouping sets, it's possible that some of the grouping sets are
duplicate. This is especially common with CUBE and ROLLUP clauses. For
example GROUP BY CUBE (a,b), CUBE (b,c) is equivalent to
GROUP BY GROUPING SETS (
(a, b, c),
(a, b, c),
(a, b, c),
(a, b),
(a, b),
(a, b),
(a),
(a),
(a),
(c, a),
(c, a),
(c, a),
(c),
(b, c),
(b),
()
)
Some of the grouping sets are calculated multiple times, which is mostly
unnecessary. This commit implements a new GROUP BY DISTINCT feature, as
defined in the SQL standard, which eliminates the duplicate sets.
Author: Vik Fearing
Reviewed-by: Erik Rijkers, Georgios Kokolatos, Tomas Vondra
Discussion: https://postgr.es/m/bf3805a8-d7d1-ae61-fece-761b7ff41ecc@postgresfriends.org
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/be45be9c33a85e72cdaeb9967e9f6d2d00199e09
Modified Files
--------------
doc/src/sgml/queries.sgml | 54 ++++++++++++++
doc/src/sgml/ref/select.sgml | 9 ++-
src/backend/catalog/sql_features.txt | 2 +-
src/backend/nodes/copyfuncs.c | 2 +
src/backend/nodes/equalfuncs.c | 2 +
src/backend/nodes/list.c | 16 +++++
src/backend/nodes/outfuncs.c | 2 +
src/backend/nodes/readfuncs.c | 1 +
src/backend/optimizer/plan/planner.c | 2 +-
src/backend/parser/analyze.c | 1 +
src/backend/parser/gram.y | 59 ++++++++++-----
src/backend/parser/parse_agg.c | 58 +++++++++++++--
src/backend/utils/adt/ruleutils.c | 2 +
src/include/nodes/parsenodes.h | 10 +++
src/include/nodes/pg_list.h | 1 +
src/include/parser/parse_agg.h | 2 +-
src/test/regress/expected/groupingsets.out | 111 +++++++++++++++++++++++++++++
src/test/regress/sql/groupingsets.sql | 26 +++++++
18 files changed, 333 insertions(+), 27 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tomas.vondra@postgresql.org
Subject: Re: pgsql: Implement GROUP BY DISTINCT
In-Reply-To: <E1lMwMS-0007AP-Qu@gemulon.postgresql.org>
References: <E1lMwMS-0007AP-Qu@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox