pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Rowley <drowley@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix possible bogus cache miss bug in Memoize nodes
Date: Thu, 12 Nov 2026 00:45:44 +0000
Message-ID: <E1xRIwi-00000000NM8-2ODG@gemulon.postgresql.org> (raw)

Fix possible bogus cache miss bug in Memoize nodes

When Memoize got a cache miss, it would create a new hash table entry
and execute its subnode to fetch the tuple to store in the cache.  When
storing that tuple, the cache may have needed to make space for the new
tuple, and that could have resulted in older, less recently used entries
to be removed from the cache.  The simplehash code, since it uses linear
probing to handle hash collisions, would shift subsequent elements back
towards their most optimal hash bucket when deleting items from the table.
This could result in the just-added entry being moved.  The Memoize code
would then accidentally proceed to assign the entry's "complete" flag, but
the entry being modified there could have become stale as a result of the
simplehash code moving things around.

This could happen regardless of singlerow mode.  In singlerow mode, it
could result in the entry being populated not correctly being marked as
complete, which could result in cache misses later that could have been
cache hits.  When not in singlerow mode, an unrelated entry could have
been unmarked as complete accidentally, which could also have resulted
in cache misses that could have been hits.  No wrong results were
possible from this.

Fix by using the entry pointer that's set in MemoizeState, which
cache_store_tuple() had so carefully rediscovered for that purpose.

Reported-by: Ilia Evdokimov <ilya.evdokimov@tantorlabs.com>
Author: Ilia Evdokimov <ilya.evdokimov@tantorlabs.com>
Reviewed-by: cca5507 <cca5507@qq.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/14118dd4-eefa-42e4-ada7-900d6845d704@tantorlabs.com
Backpatch-through: 15

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/75479d8d8ae9abf11989f7aa41ba82fcef77d22b

Modified Files
--------------
src/backend/executor/nodeMemoize.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)



view thread (6+ messages)

Message-ID: <E1xRIwi-00000000NM8-2ODG@gemulon.postgresql.org>
Permalink:  ../E1xRIwi-00000000NM8-2ODG@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xRIwi-00000000NM8-2ODG@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: drowley@postgresql.org
  Subject: Re: pgsql: Fix possible bogus cache miss bug in Memoize nodes
  In-Reply-To: <E1xRIwi-00000000NM8-2ODG@gemulon.postgresql.org>
  References: <E1xRIwi-00000000NM8-2ODG@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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