pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #19853: Memoize returns wrong rows when the join operator is hashable but its equality semantics differ from
3+ messages / 2 participants
[nested] [flat]
Commits from this thread:
2026-11-11 76c0df7381 Remove needless initialization work in ExecInitMemoize
2026-11-11 8cdf3c9214 04c5de538e 91ab6a7296 c4d8000eb2 9846de28b7 a9ad341bd6 Fix Memoize using the wrong equality operator for cache keys
* BUG #19853: Memoize returns wrong rows when the join operator is hashable but its equality semantics differ from
@ 2026-11-08 04:40 PG Bug reporting form <noreply@postgresql.org>
0 siblings, 1 reply; 3+ messages in thread
From: PG Bug reporting form @ 2026-11-08 04:40 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: 303677365@qq.com
The following bug has been logged on the website:
Bug reference: 19853
Logged by: chunling qin
Email address: 303677365@qq.com
PostgreSQL version: 18.6
Operating system: Linux x86_64; platform-independent (reproduced ide
Description:
**Description:**
Memoize decides "are these outer-scan parameters the same as a cached
entry's?" using the **type's default equality operator** (texteq for text),
not the operator the join clause actually uses. When the join uses a
hashable operator whose equality semantics differ from the default '=' —
here a user-defined `===` that compares the raw bytes (case-SENSITIVE) while
the column uses a nondeterministic (case-insensitive) collation — the
default texteq treats 'abc' == 'ABC', so the cache wrongly shares one entry
between the two outer values. The cached inner rows computed for one key are
then returned for the other: group counts silently merge across values the
join distinguishes.
A hash join on the very same tables/operator (control below) returns the
correct result, proving the operator, opclass and index are sound — only
Memoize is wrong.
This is the same invariant that the 2021 binary-comparison-mode fix
addressed for the -0.0/+0.0 case, and that commit 35273454065 (2026-11-04)
addressed for the collation dimension — the operator dimension remains:
cache key equality must agree with join-clause equality.
**Reproduction (self-contained SQL; verified identically on 18.6 and
master):**
```sql
CREATE COLLATION ci (provider = icu, locale = '@colStrength=secondary',
deterministic = false);
-- case-SENSITIVE byte equality (non-inlinable so the operator node
survives)
CREATE FUNCTION byte_eq(text, text) RETURNS bool AS
$$ BEGIN RETURN $1::bytea = $2::bytea; END $$
LANGUAGE plpgsql IMMUTABLE STRICT PARALLEL SAFE;
CREATE FUNCTION byte_hash(text) RETURNS integer AS
$$ SELECT hashtext($1) $$ LANGUAGE sql IMMUTABLE STRICT PARALLEL SAFE;
CREATE OPERATOR === (LEFTARG = text, RIGHTARG = text, FUNCTION = byte_eq,
COMMUTATOR = ===, HASHES);
CREATE OPERATOR CLASS hops FOR TYPE text USING hash AS
OPERATOR 1 === (text, text), FUNCTION 1 (text) byte_hash(text);
-- outer: 10 rows each of abc,ABC,def,DEF,ghi (nondeterministic collation)
CREATE TABLE o (x text COLLATE ci);
INSERT INTO o SELECT v FROM (VALUES ('abc'),('ABC'),('def'),('DEF'),('ghi'))
s(v), generate_series(1,10);
-- inner: 3x 'abc', 1x 'ABC', 1x 'def', 2x 'DEF', 1x 'ghi'
CREATE TABLE i (x text COLLATE ci);
INSERT INTO i VALUES
('abc'),('abc'),('abc'),('ABC'),('def'),('DEF'),('DEF'),('ghi');
CREATE INDEX i_idx ON i USING hash (x hops);
ANALYZE o; ANALYZE i;
-- A. HASH JOIN (control) - CORRECT: byte-equal pairs kept apart:
SELECT t1.x COLLATE "C" AS ox, t2.x COLLATE "C" AS ix, count(*)
FROM o t1 JOIN i t2 ON t2.x === t1.x GROUP BY 1,2 ORDER BY 1,2;
-- ABC|ABC|10 DEF|DEF|20 abc|abc|30 def|def|10 ghi|ghi|10
-- B. DEFAULT SETTINGS (planner picks Memoize) - WRONG: groups merged across
case:
SELECT t1.x COLLATE "C" AS ox, t2.x COLLATE "C" AS ix, count(*)
FROM o t1 JOIN i t2 ON t2.x === t1.x GROUP BY 1,2 ORDER BY 1,2;
-- ABC|abc|30 <- 'ABC' outer wrongly served the cache entry of 'abc'
-- DEF|def|10 <- same false merge; DEF|DEF|20 and abc rows lost their
true split
-- C. MEMOIZE OFF (oracle) - CORRECT (same as A):
SET enable_memoize=off;
SELECT t1.x COLLATE "C" AS ox, t2.x COLLATE "C" AS ix, count(*)
FROM o t1 JOIN i t2 ON t2.x === t1.x GROUP BY 1,2 ORDER BY 1,2;
RESET enable_memoize;
```
**Root cause:** `check_memoizable()` (initsplan.c) fills
`rinfo->left/right_hasheqoperator` from `lookup_type_cache(type,
TYPECACHE_EQ_OPR)->eq_opr` — the type's default equality — instead of the
join operator; `paraminfo_get_equal_hashops()` (joinpath.c) then builds the
cache keys with that default operator. Commit 35273454065 relabels the cache
keys with the clause's input collation but leaves this operator selection
untouched.
**Expected behavior:** when the join clause's operator differs from the
type's default equality operator, Memoize must not treat the default-equal
values as the same cache key (e.g. fall back to binary comparison, or
compare with the join operator) — otherwise cache key equality disagrees
with join equality, which is the same class of defect as the -0.0/+0.0 case
fixed in 2021.
**Related:** shihao zhong's report (2026-10-08, "[PG19] Wrong results from
Memoize with a nondeterministic collation") — same symptom family, collation
dimension, fixed by 35273454065; this report is the operator dimension that
the fix did not cover.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #19853: Memoize returns wrong rows when the join operator is hashable but its equality semantics differ from
@ 2026-11-08 23:07 David Rowley <dgrowleyml@gmail.com>
parent: PG Bug reporting form <noreply@postgresql.org>
0 siblings, 1 reply; 3+ messages in thread
From: David Rowley @ 2026-11-08 23:07 UTC (permalink / raw)
To: 303677365@qq.com; pgsql-bugs@lists.postgresql.org
On Sun, 8 Nov 2026 at 22:55, PG Bug reporting form
<noreply@postgresql.org> wrote:
> Memoize decides "are these outer-scan parameters the same as a cached
> entry's?" using the **type's default equality operator** (texteq for text),
> not the operator the join clause actually uses. When the join uses a
> hashable operator whose equality semantics differ from the default '=' —
> here a user-defined `===` that compares the raw bytes (case-SENSITIVE) while
> the column uses a nondeterministic (case-insensitive) collation — the
> default texteq treats 'abc' == 'ABC', so the cache wrongly shares one entry
> between the two outer values. The cached inner rows computed for one key are
> then returned for the other: group counts silently merge across values the
> join distinguishes.
Thanks for the report.
The attached is a lightly edited LLM-generated fix with my
supervision. Its first choice was to switch to binary mode for this
case, but I told it to only change check_memoizable() and use the
joinoperator when the left and right types match, and then only check
to see if there's another suitable operator when the types don't
match.
I (not the LLM) also noticed that during ExecInitMemoize(), the
cache_eq_expr is initialised even when in binary mode. Since it's not
used in binary mode, this seems like a waste of effort. The 0002
adjusts Memoize so it doesn't do this. This seems more like
master-only material. Further to that, the lookup_type_cache() code in
check_memoizable() doesn't technically seem needed as if
paraminfo_get_equal_hashops() sees an invalid hashjoinoperator while
processing the ppi_clauses, it'll switch to binary mode, so
technically we don't need a hash operator as binary mode uses
datum_image_hash() and datum_image_eq(). I'm not so sure about
changing that however, as 1) it's likely not causing many cases not to
Memoize that could, and b) someone might have left off a hash operator
to ensure the planner opts not to Memoize anything using that type.
David
Attachments: download all (2 files, .tar.gz)
v1-0001-Fix-Memoize-using-the-wrong-equality-operator-for.patch (application/octet-stream, 10.5K) download
From 09341382386dd4e7387a7ea13422593a138eab10 Mon Sep 17 00:00:00 2001
From: David Rowley <dgrowleyml@gmail.com>
Date: Mon, 9 Nov 2026 11:01:23 +1300
Subject: [PATCH v1] Fix Memoize using the wrong equality operator for cache
keys
Memoize compared cache keys with the type's default equality operator
rather than the operator used by the parameterized join clause. If a
hashable join operator considers fewer values equal than the type's
default equality operator, two outer values could share one cache
entry, and the inner rows cached for one value were returned for the
other. One example is a byte-wise equality operator on a column with
a case-insensitive nondeterministic collation.
To fix, have check_memoizable() take the hash equality operators from
the clause's hashjoinoperator. When both inputs are of the same type,
use the join operator itself. For cross-type operators, look up the
same-type equality members in the join operator's hash opfamily. If
no such member exists, don't set a hash equality operator, so Memoize
isn't used for that clause. Clauses that aren't hashjoinable keep
using the type's default equality operator along with binary mode, as
before.
Backpatch to all supported versions.
Bug: #19853
Reported-by: chunling qin <303677365@qq.com>
Author: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/19853-22fde551f71cbadb@postgresql.org
Backpatch-through: 15
---
src/backend/optimizer/plan/initsplan.c | 72 ++++++++++++++++++-
.../regress/expected/collate.icu.utf8.out | 58 +++++++++++++++
src/test/regress/sql/collate.icu.utf8.sql | 41 +++++++++++
3 files changed, 169 insertions(+), 2 deletions(-)
diff --git a/src/backend/optimizer/plan/initsplan.c b/src/backend/optimizer/plan/initsplan.c
index cec76342f6e..73aa4d535c9 100644
--- a/src/backend/optimizer/plan/initsplan.c
+++ b/src/backend/optimizer/plan/initsplan.c
@@ -14,8 +14,12 @@
*/
#include "postgres.h"
+#include "access/htup_details.h"
#include "access/nbtree.h"
+#include "access/stratnum.h"
#include "access/sysattr.h"
+#include "catalog/pg_am.h"
+#include "catalog/pg_amop.h"
#include "catalog/pg_constraint.h"
#include "catalog/pg_type.h"
#include "nodes/makefuncs.h"
@@ -32,8 +36,10 @@
#include "optimizer/restrictinfo.h"
#include "parser/analyze.h"
#include "rewrite/rewriteManip.h"
+#include "utils/catcache.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
+#include "utils/syscache.h"
#include "utils/typcache.h"
/* These parameters are set by GUC */
@@ -4035,11 +4041,55 @@ check_hashjoinable(RestrictInfo *restrictinfo)
restrictinfo->hashjoinoperator = opno;
}
+/*
+ * get_memoize_eqop
+ * Find the equality operator for comparing two values of type 'type' with
+ * the same semantics as the cross-type hashjoinable operator 'joinop'.
+ *
+ * We look for an equality member of 'type' in a hash opfamily that contains
+ * 'joinop'. Returns InvalidOid if there is none.
+ */
+static Oid
+get_memoize_eqop(Oid joinop, Oid type)
+{
+ Oid result = InvalidOid;
+ CatCList *catlist;
+
+ catlist = SearchSysCacheList1(AMOPOPID, ObjectIdGetDatum(joinop));
+
+ for (int i = 0; i < catlist->n_members; i++)
+ {
+ HeapTuple tuple = &catlist->members[i]->tuple;
+ Form_pg_amop aform = (Form_pg_amop) GETSTRUCT(tuple);
+
+ if (aform->amopmethod != HASH_AM_OID ||
+ aform->amopstrategy != HTEqualStrategyNumber)
+ continue;
+
+ result = get_opfamily_member(aform->amopfamily, type, type,
+ HTEqualStrategyNumber);
+ if (OidIsValid(result))
+ break;
+ }
+
+ ReleaseSysCacheList(catlist);
+
+ return result;
+}
+
/*
* check_memoizable
* If the restrictinfo's clause is suitable to be used for a Memoize node,
* set the left_hasheqoperator and right_hasheqoperator to the hash equality
* operator that will be needed during caching.
+ *
+ * When the clause is hashjoinable, the cache must use the same notion of
+ * equality as the join operator, as the type's default equality operator
+ * could consider values equal that the join operator does not. If both
+ * inputs are of the same type, we can just use the join operator itself;
+ * otherwise we look up the same-type equality operators in the join
+ * operator's hash opfamily. When the clause is not hashjoinable, we use the
+ * type's default equality operator and Memoize uses binary mode.
*/
static void
check_memoizable(RestrictInfo *restrictinfo)
@@ -4057,6 +4107,26 @@ check_memoizable(RestrictInfo *restrictinfo)
return;
lefttype = exprType(linitial(((OpExpr *) clause)->args));
+ righttype = exprType(lsecond(((OpExpr *) clause)->args));
+
+ if (OidIsValid(restrictinfo->hashjoinoperator))
+ {
+ Oid joinop = restrictinfo->hashjoinoperator;
+
+ if (lefttype == righttype)
+ {
+ restrictinfo->left_hasheqoperator = joinop;
+ restrictinfo->right_hasheqoperator = joinop;
+ }
+ else
+ {
+ restrictinfo->left_hasheqoperator = get_memoize_eqop(joinop,
+ lefttype);
+ restrictinfo->right_hasheqoperator = get_memoize_eqop(joinop,
+ righttype);
+ }
+ return;
+ }
typentry = lookup_type_cache(lefttype, TYPECACHE_HASH_PROC |
TYPECACHE_EQ_OPR);
@@ -4064,8 +4134,6 @@ check_memoizable(RestrictInfo *restrictinfo)
if (OidIsValid(typentry->hash_proc) && OidIsValid(typentry->eq_opr))
restrictinfo->left_hasheqoperator = typentry->eq_opr;
- righttype = exprType(lsecond(((OpExpr *) clause)->args));
-
/*
* Lookup the right type, unless it's the same as the left type, in which
* case typentry is already pointing to the required TypeCacheEntry.
diff --git a/src/test/regress/expected/collate.icu.utf8.out b/src/test/regress/expected/collate.icu.utf8.out
index 4db10b3e8c1..636f0dfefc3 100644
--- a/src/test/regress/expected/collate.icu.utf8.out
+++ b/src/test/regress/expected/collate.icu.utf8.out
@@ -2237,6 +2237,64 @@ GROUP BY t2.x ORDER BY t2.x;
ghi | 10
(4 rows)
+ROLLBACK;
+-- Likewise, but with a case-sensitive hashable join operator that is not the
+-- type's default equality operator. Memoize must use the join operator's
+-- notion of equality for its cache keys.
+BEGIN;
+CREATE FUNCTION test_memoize_byteeq(text, text) RETURNS bool
+ AS $$ BEGIN RETURN $1::bytea = $2::bytea; END $$
+ LANGUAGE plpgsql IMMUTABLE STRICT;
+CREATE FUNCTION test_memoize_bytehash(text) RETURNS int
+ AS $$ SELECT hashtext($1 COLLATE "C") $$
+ LANGUAGE sql IMMUTABLE STRICT;
+CREATE OPERATOR === (LEFTARG = text, RIGHTARG = text,
+ FUNCTION = test_memoize_byteeq, COMMUTATOR = ===, HASHES);
+CREATE OPERATOR CLASS test_memoize_byteops FOR TYPE text USING hash AS
+ OPERATOR 1 === (text, text),
+ FUNCTION 1 test_memoize_bytehash(text);
+CREATE TABLE test_memoize_ci (x text COLLATE case_insensitive);
+INSERT INTO test_memoize_ci SELECT x FROM test3ci, generate_series(1, 10);
+CREATE TABLE test_memoize_ci_inner (x text COLLATE case_insensitive);
+INSERT INTO test_memoize_ci_inner SELECT x FROM test3ci;
+CREATE INDEX ON test_memoize_ci_inner USING hash (x test_memoize_byteops);
+ANALYZE test_memoize_ci, test_memoize_ci_inner;
+SET LOCAL enable_hashjoin TO off;
+SET LOCAL enable_mergejoin TO off;
+SET LOCAL enable_seqscan TO off;
+-- Ensure we get a Memoize plan
+EXPLAIN (COSTS OFF)
+SELECT t1.x COLLATE "C", t2.x COLLATE "C", count(*) FROM test_memoize_ci t1
+ INNER JOIN test_memoize_ci_inner t2 ON t2.x === t1.x
+GROUP BY 1, 2 ORDER BY 1, 2;
+ QUERY PLAN
+--------------------------------------------------------------------------------------------------
+ Sort
+ Sort Key: ((t1.x)::text) COLLATE "C", ((t2.x)::text) COLLATE "C"
+ -> HashAggregate
+ Group Key: (t1.x)::text, (t2.x)::text
+ -> Nested Loop
+ -> Seq Scan on test_memoize_ci t1
+ Disabled: true
+ -> Memoize
+ Cache Key: t1.x
+ Cache Mode: logical
+ -> Index Scan using test_memoize_ci_inner_x_idx on test_memoize_ci_inner t2
+ Index Cond: (x === t1.x)
+(12 rows)
+
+-- Ensure we get the expected results
+SELECT t1.x COLLATE "C", t2.x COLLATE "C", count(*) FROM test_memoize_ci t1
+ INNER JOIN test_memoize_ci_inner t2 ON t2.x === t1.x
+GROUP BY 1, 2 ORDER BY 1, 2;
+ x | x | count
+-----+-----+-------
+ ABC | ABC | 10
+ abc | abc | 10
+ def | def | 10
+ ghi | ghi | 10
+(4 rows)
+
ROLLBACK;
-- These queries should be able to use the index on test1ci.x:
SET enable_seqscan = off;
diff --git a/src/test/regress/sql/collate.icu.utf8.sql b/src/test/regress/sql/collate.icu.utf8.sql
index 937efa17041..b2d6f7d64ca 100644
--- a/src/test/regress/sql/collate.icu.utf8.sql
+++ b/src/test/regress/sql/collate.icu.utf8.sql
@@ -821,6 +821,47 @@ GROUP BY t2.x ORDER BY t2.x;
ROLLBACK;
+-- Likewise, but with a case-sensitive hashable join operator that is not the
+-- type's default equality operator. Memoize must use the join operator's
+-- notion of equality for its cache keys.
+BEGIN;
+
+CREATE FUNCTION test_memoize_byteeq(text, text) RETURNS bool
+ AS $$ BEGIN RETURN $1::bytea = $2::bytea; END $$
+ LANGUAGE plpgsql IMMUTABLE STRICT;
+CREATE FUNCTION test_memoize_bytehash(text) RETURNS int
+ AS $$ SELECT hashtext($1 COLLATE "C") $$
+ LANGUAGE sql IMMUTABLE STRICT;
+CREATE OPERATOR === (LEFTARG = text, RIGHTARG = text,
+ FUNCTION = test_memoize_byteeq, COMMUTATOR = ===, HASHES);
+CREATE OPERATOR CLASS test_memoize_byteops FOR TYPE text USING hash AS
+ OPERATOR 1 === (text, text),
+ FUNCTION 1 test_memoize_bytehash(text);
+
+CREATE TABLE test_memoize_ci (x text COLLATE case_insensitive);
+INSERT INTO test_memoize_ci SELECT x FROM test3ci, generate_series(1, 10);
+CREATE TABLE test_memoize_ci_inner (x text COLLATE case_insensitive);
+INSERT INTO test_memoize_ci_inner SELECT x FROM test3ci;
+CREATE INDEX ON test_memoize_ci_inner USING hash (x test_memoize_byteops);
+ANALYZE test_memoize_ci, test_memoize_ci_inner;
+
+SET LOCAL enable_hashjoin TO off;
+SET LOCAL enable_mergejoin TO off;
+SET LOCAL enable_seqscan TO off;
+
+-- Ensure we get a Memoize plan
+EXPLAIN (COSTS OFF)
+SELECT t1.x COLLATE "C", t2.x COLLATE "C", count(*) FROM test_memoize_ci t1
+ INNER JOIN test_memoize_ci_inner t2 ON t2.x === t1.x
+GROUP BY 1, 2 ORDER BY 1, 2;
+
+-- Ensure we get the expected results
+SELECT t1.x COLLATE "C", t2.x COLLATE "C", count(*) FROM test_memoize_ci t1
+ INNER JOIN test_memoize_ci_inner t2 ON t2.x === t1.x
+GROUP BY 1, 2 ORDER BY 1, 2;
+
+ROLLBACK;
+
-- These queries should be able to use the index on test1ci.x:
SET enable_seqscan = off;
SET enable_indexonlyscan = off;
--
2.53.0
v1-0002-Don-t-build-unused-Memoize-hash-and-equality-stat.patch (application/octet-stream, 3.9K) download
From c32a5139e4535313f20a23345fdca17d18298228 Mon Sep 17 00:00:00 2001
From: David Rowley <dgrowleyml@gmail.com>
Date: Mon, 9 Nov 2026 11:19:43 +1300
Subject: [PATCH v1 2/2] Don't build unused Memoize hash and equality state in
binary mode
When a Memoize node is in binary mode, cache keys are hashed with
datum_image_hash() and compared with datum_image_eq(). Despite that,
ExecInitMemoize() always looked up the hash functions for each cache
key and built cache_eq_expr, neither of which binary mode uses.
Only do that work when not in binary mode. This saves some executor
startup work and memory for Memoize nodes using binary mode.
Author: David Rowley <dgrowleyml@gmail.com>
---
src/backend/executor/nodeMemoize.c | 67 ++++++++++++++++++------------
1 file changed, 40 insertions(+), 27 deletions(-)
diff --git a/src/backend/executor/nodeMemoize.c b/src/backend/executor/nodeMemoize.c
index 023468e056c..5de7c613cd8 100644
--- a/src/backend/executor/nodeMemoize.c
+++ b/src/backend/executor/nodeMemoize.c
@@ -1038,39 +1038,58 @@ ExecInitMemoize(Memoize *node, EState *estate, int eflags)
mstate->probeslot = MakeSingleTupleTableSlot(mstate->hashkeydesc,
&TTSOpsVirtual);
+ /*
+ * Record if the cache keys should be compared bit by bit, or logically
+ * using the type's hash equality operator
+ */
+ mstate->binary_mode = node->binary_mode;
+
mstate->param_exprs = palloc_array(ExprState *, nkeys);
mstate->collations = node->collations; /* Just point directly to the plan
* data */
- mstate->hashfunctions = palloc_array(FmgrInfo, nkeys);
-
- eqfuncoids = palloc_array(Oid, nkeys);
for (i = 0; i < nkeys; i++)
{
- Oid hashop = node->hashOperators[i];
- Oid left_hashfn;
- Oid right_hashfn;
Expr *param_expr = (Expr *) list_nth(node->param_exprs, i);
- if (!get_op_hash_functions(hashop, &left_hashfn, &right_hashfn))
- elog(ERROR, "could not find hash function for hash operator %u",
- hashop);
-
- fmgr_info(left_hashfn, &mstate->hashfunctions[i]);
-
mstate->param_exprs[i] = ExecInitExpr(param_expr, (PlanState *) mstate);
- eqfuncoids[i] = get_opcode(hashop);
}
- mstate->cache_eq_expr = ExecBuildParamSetEqual(mstate->hashkeydesc,
- &TTSOpsMinimalTuple,
- &TTSOpsVirtual,
- eqfuncoids,
- node->collations,
- node->param_exprs,
- (PlanState *) mstate);
+ /*
+ * In binary mode, the cache keys are hashed and compared using
+ * datum_image_hash() and datum_image_eq(), so the hash functions and
+ * equality expression are only needed when not in binary mode.
+ */
+ if (!mstate->binary_mode)
+ {
+ mstate->hashfunctions = palloc_array(FmgrInfo, nkeys);
+ eqfuncoids = palloc_array(Oid, nkeys);
+
+ for (i = 0; i < nkeys; i++)
+ {
+ Oid hashop = node->hashOperators[i];
+ Oid left_hashfn;
+ Oid right_hashfn;
+
+ if (!get_op_hash_functions(hashop, &left_hashfn, &right_hashfn))
+ elog(ERROR, "could not find hash function for hash operator %u",
+ hashop);
+
+ fmgr_info(left_hashfn, &mstate->hashfunctions[i]);
+ eqfuncoids[i] = get_opcode(hashop);
+ }
+
+ mstate->cache_eq_expr = ExecBuildParamSetEqual(mstate->hashkeydesc,
+ &TTSOpsMinimalTuple,
+ &TTSOpsVirtual,
+ eqfuncoids,
+ node->collations,
+ node->param_exprs,
+ (PlanState *) mstate);
+
+ pfree(eqfuncoids);
+ }
- pfree(eqfuncoids);
mstate->mem_used = 0;
/* Limit the total memory consumed by the cache to this */
@@ -1096,12 +1115,6 @@ ExecInitMemoize(Memoize *node, EState *estate, int eflags)
mstate->singlerow = node->singlerow;
mstate->keyparamids = node->keyparamids;
- /*
- * Record if the cache keys should be compared bit by bit, or logically
- * using the type's hash equality operator
- */
- mstate->binary_mode = node->binary_mode;
-
/* Zero the statistics counters */
memset(&mstate->stats, 0, sizeof(MemoizeInstrumentation));
--
2.53.0
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #19853: Memoize returns wrong rows when the join operator is hashable but its equality semantics differ from
@ 2026-11-11 01:39 David Rowley <dgrowleyml@gmail.com>
parent: David Rowley <dgrowleyml@gmail.com>
0 siblings, 0 replies; 3+ messages in thread
From: David Rowley @ 2026-11-11 01:39 UTC (permalink / raw)
To: 303677365@qq.com; pgsql-bugs@lists.postgresql.org
On Mon, 9 Nov 2026 at 12:07, David Rowley <dgrowleyml@gmail.com> wrote:
> The attached is a lightly edited LLM-generated fix with my
> supervision. Its first choice was to switch to binary mode for this
> case, but I told it to only change check_memoizable() and use the
> joinoperator when the left and right types match, and then only check
> to see if there's another suitable operator when the types don't
> match.
I spent more human time reviewing this and it turns out there's
perfectly good get_compatible_hash_operators() function that does the
job of what the LLM churned out to do the same thing. I swapped to
using that function. The test remains the one written by the LLM.
Now fixed back to v15. I'll look at the 0002 change for master only.
David
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2026-11-11 01:39 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-08 04:40 BUG #19853: Memoize returns wrong rows when the join operator is hashable but its equality semantics differ from PG Bug reporting form <noreply@postgresql.org>
2026-11-08 23:07 ` David Rowley <dgrowleyml@gmail.com>
2026-11-11 01:39 ` David Rowley <dgrowleyml@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox