From b0f0d36ea775bccc9b0335e5cc7ee5538d392c35 Mon Sep 17 00:00:00 2001 From: shihao zhong Date: Mon, 5 Oct 2026 11:41:09 -0400 Subject: [PATCH v1 1/2] Use the join clause's collation for Memoize cache keys Memoize compared cache keys with the outer expression's collation. When that is nondeterministic and the join clause uses another one, keys the clause tells apart could share a cache entry, giving wrong results for LEFT and ANTI joins. Label the key with the clause's input collation instead. --- src/backend/optimizer/path/joinpath.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/backend/optimizer/path/joinpath.c b/src/backend/optimizer/path/joinpath.c index dfd08e7aeb1..ec141c1d47a 100644 --- a/src/backend/optimizer/path/joinpath.c +++ b/src/backend/optimizer/path/joinpath.c @@ -535,6 +535,15 @@ paraminfo_get_equal_hashops(PlannerInfo *root, ParamPathInfo *param_info, return false; } + /* + * Ensure the cache key exposes the clause's input collation, so + * that Memoize compares keys the same way the clause does. See + * comments for canonicalize_ec_expression. + */ + expr = (Node *) canonicalize_ec_expression((Expr *) expr, + exprType(expr), + opexpr->inputcollid); + /* * 'expr' may already exist as a parameter from a previous item in * ppi_clauses. No need to include it again, however we'd better -- 2.37.1 (Apple Git-137.1)