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 thinko in outer-join removal.
Date: Sat, 04 Feb 2023 20:20:07 +0000
Message-ID: <E1pOP13-001bUe-Kg@gemulon.postgresql.org> (raw)

Fix thinko in outer-join removal.

If we have a RestrictInfo that mentions both the removal-candidate
relation and the outer join's relid, then that is a pushed-down
condition not a join condition, so it should be grounds for deciding
that we can't remove the outer join.  In commit 2489d76c4, I'd blindly
included the OJ's relid into "joinrelids" as per the new standard
convention, but the checks of attr_needed and ph_needed should only
allow the join's input rels to be mentioned.

Having done that, the check for references in pushed-down quals
a few lines further down should be redundant.  I left it in place
as an Assert, though.

While researching this I happened across a couple of comments that
worried about the effects of update_placeholder_eval_levels.
That's gone as of b448f1c8d, so we can remove some worry.

Per bug #17769 from Robins Tharakan.  The submitted test case
triggers this more or less accidentally because we flatten out
a LATERAL sub-select after we've done join strength reduction;
if we did that in the other order, this problem would be masked
because the outer join would get simplified to an inner join.
To ensure that the committed test case will continue to test
what it means to even if we make that happen someday, use a
test clause involving COALESCE(), which will prevent us from
using it to do join strength reduction.

Patch by me, but thanks to Richard Guo for initial investigation.

Discussion: https://postgr.es/m/17769-e4f7a5c9d84a80a7@postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/8538519db107777a6b06b7277185e6605caf8d4c

Modified Files
--------------
src/backend/optimizer/plan/analyzejoins.c | 30 ++++++++++++++----------------
src/backend/optimizer/plan/initsplan.c    |  6 +++---
src/backend/optimizer/util/var.c          | 10 ----------
src/test/regress/expected/join.out        | 15 +++++++++++++++
src/test/regress/sql/join.sql             |  7 +++++++
5 files changed, 39 insertions(+), 29 deletions(-)



Message-ID: <E1pOP13-001bUe-Kg@gemulon.postgresql.org>
Permalink:  ../E1pOP13-001bUe-Kg@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1pOP13-001bUe-Kg@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 thinko in outer-join removal.
  In-Reply-To: <E1pOP13-001bUe-Kg@gemulon.postgresql.org>
  References: <E1pOP13-001bUe-Kg@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