pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix possible bogus cache miss bug in Memoize nodes
6+ messages / 1 participants
[nested] [flat]

* pgsql: Fix possible bogus cache miss bug in Memoize nodes
@ 2026-11-12 00:44 David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: David Rowley @ 2026-11-12 00:44 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/3f67ce4819ff6199165431941463dd9d0f6e5a5a

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



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix possible bogus cache miss bug in Memoize nodes
@ 2026-11-12 00:44 David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: David Rowley @ 2026-11-12 00:44 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/156cb88f9232062bc4813a1c21f5f6ae6d5cce55

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



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix possible bogus cache miss bug in Memoize nodes
@ 2026-11-12 00:45 David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: David Rowley @ 2026-11-12 00:45 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/a3b7084138cb0aa9102826c893d892a8ff4c23f7

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



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix possible bogus cache miss bug in Memoize nodes
@ 2026-11-12 00:45 David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: David Rowley @ 2026-11-12 00:45 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/da643e9e1a62f6d885f82fddfd8a77ee0930e47b

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



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix possible bogus cache miss bug in Memoize nodes
@ 2026-11-12 00:45 David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: David Rowley @ 2026-11-12 00:45 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/aa2cfd0c5ccb8a256d98b6cd85d5332cc61c0ca2

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



^ permalink  raw  reply  [nested|flat] 6+ messages in thread

* pgsql: Fix possible bogus cache miss bug in Memoize nodes
@ 2026-11-12 00:45 David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 6+ messages in thread

From: David Rowley @ 2026-11-12 00:45 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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(-)



^ permalink  raw  reply  [nested|flat] 6+ messages in thread


end of thread, other threads:[~2026-11-12 00:45 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-12 00:44 pgsql: Fix possible bogus cache miss bug in Memoize nodes David Rowley <drowley@postgresql.org>
2026-11-12 00:44 pgsql: Fix possible bogus cache miss bug in Memoize nodes David Rowley <drowley@postgresql.org>
2026-11-12 00:45 pgsql: Fix possible bogus cache miss bug in Memoize nodes David Rowley <drowley@postgresql.org>
2026-11-12 00:45 pgsql: Fix possible bogus cache miss bug in Memoize nodes David Rowley <drowley@postgresql.org>
2026-11-12 00:45 pgsql: Fix possible bogus cache miss bug in Memoize nodes David Rowley <drowley@postgresql.org>
2026-11-12 00:45 pgsql: Fix possible bogus cache miss bug in Memoize nodes David Rowley <drowley@postgresql.org>

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