pgsql: Use PlaceHolderVars within the quals of a FULL JOIN.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Use PlaceHolderVars within the quals of a FULL JOIN.
Date: 2018-10-14 17:07:46
Message-ID: E1gBjrm-0002cy-Cp@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Use PlaceHolderVars within the quals of a FULL JOIN.

This prevents failures in cases where we pull up a constant or var-free
expression from a subquery and put it into a full join's qual. That can
result in not recognizing the qual as containing a mergejoin-able or
hashjoin-able condition. A PHV prevents the problem because it is still
recognized as belonging to the side of the join the subquery is in.

I'm not very sure about the net effect of this change on plan quality.
In "typical" cases where the join keys are Vars, nothing changes.
In an affected case, the PHV-wrapped expression is less likely to be seen
as equal to PHV-less instances below the join, but more likely to be seen
as equal to similar expressions above the join, so it may end up being a
wash. In the one existing case where there's any visible change in a
regression-test plan, it amounts to referencing a lower computation of a
COALESCE result instead of recomputing it, which seems like a win.

Given my uncertainty about that and the lack of field complaints,
no back-patch, even though this is a very ancient problem.

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

Branch
------
master

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

Modified Files
--------------
src/backend/optimizer/prep/prepjointree.c | 12 ++++++++++++
src/test/regress/expected/join.out | 16 +++++++++++++++-
src/test/regress/sql/join.sql | 7 +++++++
3 files changed, 34 insertions(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Andres Freund 2018-10-14 17:42:40 Re: pgsql: Avoid duplicate XIDs at recovery when building initial snapshot
Previous Message Tom Lane 2018-10-14 16:11:24 pgsql: Clean up/tighten up coercibility checks in opr_sanity regression