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 ------ REL_18_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/10b2d9986b958b413d169b30ea43ae32a405bc72 Modified Files -------------- src/backend/optimizer/plan/analyzejoins.c | 48 ++++++++----------------------- 1 file changed, 12 insertions(+), 36 deletions(-)
