From 2031d56bd5fcc5f5217ca8361192982887b620ab Mon Sep 17 00:00:00 2001
From: Evdokimov Ilia <ilya.evdokimov@tantorlabs.com>
Date: Wed, 11 Nov 2026 15:12:24 +0300
Subject: [PATCH v1] Fix stale entry pointer in Memoize after cache eviction

Storing a tuple can trigger cache eviction, which may move the current
hash table entry to another bucket. cache_store_tuple() updates
node->entry when this happens, but ExecMemoize() still uses its local
entry pointer to set the complete flag.

Use node->entry instead, so that singlerow entries are correctly marked
complete. Otherwise, subsequent lookups can unnecessarily discard the
cached tuples and rescan the inner plan.
---
 src/backend/executor/nodeMemoize.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/backend/executor/nodeMemoize.c b/src/backend/executor/nodeMemoize.c
index 74f79260fc3..42287c19514 100644
--- a/src/backend/executor/nodeMemoize.c
+++ b/src/backend/executor/nodeMemoize.c
@@ -868,7 +868,7 @@ ExecMemoize(PlanState *pstate)
 					 * cache lookups to work even when the scan has not been
 					 * executed to completion.
 					 */
-					entry->complete = node->singlerow;
+					node->entry->complete = node->singlerow;
 					node->mstatus = MEMO_FILLING_CACHE;
 				}
 
-- 
2.53.0

