Skip to content

Commit 1f194ed

Browse files
committed
Fix incorrect hash equality operator bug in Memoize
In v14, because we don't have a field in RestrictInfo to cache both the left and right type's hash equality operator, we just restrict the scope of Memoize to only when the left and right types of a RestrictInfo are the same. In master we add another field to RestrictInfo and cache both hash equality operators. Reported-by: Jaime Casanova Author: David Rowley Discussion: https://postgr.es/m/20210929185544.GB24346%40ahch-to Backpatch-through: 14
1 parent bb003ed commit 1f194ed

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/backend/optimizer/plan/initsplan.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,7 +2719,8 @@ check_memoizable(RestrictInfo *restrictinfo)
27192719
{
27202720
TypeCacheEntry *typentry;
27212721
Expr *clause = restrictinfo->clause;
2722-
Node *leftarg;
2722+
Oid lefttype;
2723+
Oid righttype;
27232724

27242725
if (restrictinfo->pseudoconstant)
27252726
return;
@@ -2728,10 +2729,20 @@ check_memoizable(RestrictInfo *restrictinfo)
27282729
if (list_length(((OpExpr *) clause)->args) != 2)
27292730
return;
27302731

2731-
leftarg = linitial(((OpExpr *) clause)->args);
2732+
lefttype = exprType(linitial(((OpExpr *) clause)->args));
2733+
righttype = exprType(lsecond(((OpExpr *) clause)->args));
2734+
2735+
/*
2736+
* Really there should be a field for both the left and right hash
2737+
* equality operator, however, in v14, there's only a single field in
2738+
* RestrictInfo to record the operator in, so we must insist that the left
2739+
* and right types match.
2740+
*/
2741+
if (lefttype != righttype)
2742+
return;
27322743

2733-
typentry = lookup_type_cache(exprType(leftarg), TYPECACHE_HASH_PROC |
2734-
TYPECACHE_EQ_OPR);
2744+
typentry = lookup_type_cache(lefttype, TYPECACHE_HASH_PROC |
2745+
TYPECACHE_EQ_OPR);
27352746

27362747
if (!OidIsValid(typentry->hash_proc) || !OidIsValid(typentry->eq_opr))
27372748
return;

0 commit comments

Comments
 (0)