Simplify restriction matching in self-join elimination.

In match_unique_clauses(), use equal() to compare complete restriction
clauses after substituting the relation ID, instead of comparing their
operands separately.  This ensures that the operator and input
collation also match, preventing incorrect self-join elimination when
restrictions have identical operands but different semantics.

The former code apparently intended to support matching clauses to
commuted versions of those clauses, but the amount of complication
that added seems far out of proportion to the value, so just drop
that goal.  (If we wanted to reinstate it, something based on
applying CommuteOpExpr or equivalent logic would be better.)

Author: Tender Wang <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Discussion: 
https://postgr.es/m/cahewxnmwyrp0dtuiscyfxxjva_iruddfapuzlvdg3j4mar6...@mail.gmail.com
Backpatch-through: 18

Branch
------
master

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

Modified Files
--------------
src/backend/optimizer/plan/analyzejoins.c | 48 ++++++++-----------------------
1 file changed, 12 insertions(+), 36 deletions(-)

Reply via email to