pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Guo <rguo@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Allow pushdown of HAVING clauses with grouping sets
Date: Wed, 09 Oct 2024 08:22:36 +0000
Message-ID: <E1syRxs-0000Tr-Pz@gemulon.postgresql.org> (raw)

Allow pushdown of HAVING clauses with grouping sets

In some cases, we may want to transfer a HAVING clause into WHERE in
hopes of eliminating tuples before aggregation instead of after.

Previously, we couldn't do this if there were any nonempty grouping
sets, because we didn't have a way to tell if the HAVING clause
referenced any columns that were nullable by the grouping sets, and
moving such a clause into WHERE could potentially change the results.

Now, with expressions marked nullable by grouping sets with the RT
index of the RTE_GROUP RTE, it is much easier to identify those
clauses that reference any nullable-by-grouping-sets columns: we just
need to check if the RT index of the RTE_GROUP RTE is present in the
clause.  For other HAVING clauses, they can be safely pushed down.

Author: Richard Guo
Discussion: https://postgr.es/m/CAMbWs4-NpzPgtKU=hgnvyn+J-GanxQCjrUi7piNzZ=upiCV=2Q@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/67a54b9e83d331eadd3a595e6c3bfec06288d2c4

Modified Files
--------------
src/backend/optimizer/plan/planner.c       | 17 +++++++++--------
src/test/regress/expected/groupingsets.out | 21 +++++++++++++++++++++
src/test/regress/sql/groupingsets.sql      |  5 +++++
3 files changed, 35 insertions(+), 8 deletions(-)



Message-ID: <E1syRxs-0000Tr-Pz@gemulon.postgresql.org>
Permalink:  ../E1syRxs-0000Tr-Pz@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1syRxs-0000Tr-Pz@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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: rguo@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Allow pushdown of HAVING clauses with grouping sets
  In-Reply-To: <E1syRxs-0000Tr-Pz@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