pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix assorted missing logic for GroupingFunc nodes.
Date: Mon, 21 Mar 2022 21:44:56 +0000
Message-ID: <E1nWPpf-000lzI-DD@gemulon.postgresql.org> (raw)

Fix assorted missing logic for GroupingFunc nodes.

The planner needs to treat GroupingFunc like Aggref for many purposes,
in particular with respect to processing of the argument expressions,
which are not to be evaluated at runtime.  A few places hadn't gotten
that memo, notably including subselect.c's processing of outer-level
aggregates.  This resulted in assertion failures or wrong plans for
cases in which a GROUPING() construct references an outer aggregation
level.

Also fix missing special cases for GroupingFunc in cost_qual_eval
(resulting in wrong cost estimates for GROUPING(), although it's
not clear that that would affect plan shapes in practice) and in
ruleutils.c (resulting in excess parentheses in pretty-print mode).

Per bug #17088 from Yaoguang Chen.  Back-patch to all supported
branches.

Richard Guo, Tom Lane

Discussion: https://postgr.es/m/17088-e33882b387de7f5c@postgresql.org

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/dfefe38fbea4c6f003319a9921f3fd6ded5e70aa

Modified Files
--------------
src/backend/nodes/nodeFuncs.c              |  2 ++
src/backend/optimizer/path/costsize.c      |  6 ++++
src/backend/optimizer/plan/subselect.c     | 30 ++++++++++++--------
src/backend/utils/adt/ruleutils.c          | 10 +++++--
src/test/regress/expected/groupingsets.out | 45 ++++++++++++++++++++++++++++++
src/test/regress/sql/groupingsets.sql      |  9 ++++++
6 files changed, 88 insertions(+), 14 deletions(-)



view thread (6+ messages)

Message-ID: <E1nWPpf-000lzI-DD@gemulon.postgresql.org>
Permalink:  ../E1nWPpf-000lzI-DD@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1nWPpf-000lzI-DD@gemulon.postgresql.org

 · 

reply

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: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Fix assorted missing logic for GroupingFunc nodes.
  In-Reply-To: <E1nWPpf-000lzI-DD@gemulon.postgresql.org>
  References: <E1nWPpf-000lzI-DD@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