pgsql: Fix joinclause removal logic to cope with cloned clauses.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix joinclause removal logic to cope with cloned clauses.
Date: 2023-05-26 16:13:25
Message-ID: E1q2a4E-001qcA-2E@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix joinclause removal logic to cope with cloned clauses.

When we're deleting a no-op LEFT JOIN from the query, we must remove
the join's joinclauses from surviving relations' joininfo lists.
The invention of "cloned" clauses in 2489d76c4 broke the logic for
that; it'd fail to remove clones that include OJ relids outside the
doomed join's min relid sets, which could happen if that join was
previously discovered to commute with some other join.

This accidentally failed to cause problems in the majority of cases,
because we'd never decide that such a cloned clause was evaluatable at
any surviving join. However, Richard Guo discovered a case where that
did happen, leading to "no relation entry for relid" errors later.
Also, adding assertions that a non-removed clause contains no Vars from
the doomed join exposes that there are quite a few existing regression
test cases where the problem happens but is accidentally not exposed.

The fix for this is just to include the target join's commute_above_r
and commute_below_l sets in the relid set we test against when
deciding whether a join clause is "pushed down" and thus not
removable.

While at it, do a little refactoring: the join's relid set can be
computed inside remove_rel_from_query rather than in the caller.

Patch by me; thanks to Richard Guo for review.

Discussion: https://postgr.es/m/CAMbWs4_PHrRqTKDNnTRsxxQy6BtYCVKsgXm1_gdN2yQ=kmcO5g@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/7a844c77ece1bda3b076034bc20142d4bd66db7a

Modified Files
--------------
src/backend/optimizer/plan/analyzejoins.c | 91 ++++++++++++++++++++-----------
src/test/regress/expected/join.out | 16 ++++++
src/test/regress/sql/join.sql | 6 ++
3 files changed, 82 insertions(+), 31 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Jeff Davis 2023-05-26 18:44:26 pgsql: ICU: use uloc_getDefault() for initdb.
Previous Message Peter Eisentraut 2023-05-26 07:02:33 Re: testing dist tarballs