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 confusion about havingQual vs hasHavingQual in planner.
Date: Tue, 18 Oct 2022 14:44:41 +0000
Message-ID: <E1oknpg-002vpe-Sv@gemulon.postgresql.org> (raw)

Fix confusion about havingQual vs hasHavingQual in planner.

Preprocessing of the HAVING clause will reduce havingQual to NIL
if the clause is constant-TRUE.  This is one case where that
convention is rather unfortunate, because "HAVING TRUE" is not at all
the same as not having any HAVING clause at all.  (Per the SQL spec,
it still forces the query to be grouped.)  The planner deals with this
by having a boolean hasHavingQual that records whether havingQual was
originally nonempty; places that just want to check whether HAVING
was specified are supposed to consult that.

I found three places that got that wrong.  Fortunately, these could
only affect cost estimates not correctness.  It'd be hard even
to demonstrate the errors; for example, the one in allpaths.c would
only matter in a query that has HAVING TRUE but no GROUP BY and no
aggregates, which would require a completely variable-free SELECT
list, making the case probably of only academic interest.  Hence,
while these are worth fixing before someone copies the incorrect
coding somewhere more critical, they don't seem worth back-patching.
I didn't bother trying to devise regression tests, either.

Discussion: https://postgr.es/m/2503888.1666042643@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/8bf66dedd88673f94122c3f3337e7d58e561ef4f

Modified Files
--------------
contrib/postgres_fdw/postgres_fdw.c   | 4 ++--
src/backend/optimizer/path/allpaths.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)



Message-ID: <E1oknpg-002vpe-Sv@gemulon.postgresql.org>
Permalink:  ../E1oknpg-002vpe-Sv@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1oknpg-002vpe-Sv@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 confusion about havingQual vs hasHavingQual in planner.
  In-Reply-To: <E1oknpg-002vpe-Sv@gemulon.postgresql.org>
  References: <E1oknpg-002vpe-Sv@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