From: David Rowley <drowley@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Reduce memory overheads for storing a Memoize tuple
Date: Fri, 21 Aug 2026 02:50:42 +0000
Message-ID: <E1wxFL7-00000001Rru-0kfV@gemulon.postgresql.org> (raw)
Reduce memory overheads for storing a Memoize tuple
This uses 16 fewer bytes per tuple stored in each MemoizeEntry. 24 bytes
can be saved by not doing palloc_object(MemoizeTuple), and instead we
can store the pointer to the next tuple by requesting that
ExecCopySlotMinimalTupleExtra() allocate an extra 8 bytes per
MinimalTuple, a net saving of 16 bytes per cached tuple, which equates
to 33% less memory in the most extreme case (assuming very few entries
with many tuples and the narrowest possible MinimalTuple). Real-world
cases will save less, as we're not saving anything on the MemoizeEntry
itself, only tuples stored within it.
Saving memory in Memoize allows more entries to exist concurrently and
reduces the chances that an entry will be evicted from the cache due to
memory pressure. That increases the chances of getting cache hits.
Author: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://postgr.es/m/CAApHDvoNurQzpR2nZ4aLq1v_4gstsSdimZP-m34PMTBPptn+zQ@mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/609f969f61bbe0cab817a12c4b9f2c1c0fa3297f
Modified Files
--------------
src/backend/executor/nodeMemoize.c | 106 +++++++++++++++++++++++++------------
src/include/nodes/execnodes.h | 8 ++-
src/tools/pgindent/typedefs.list | 1 -
3 files changed, 75 insertions(+), 40 deletions(-)
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 using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: drowley@postgresql.org, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Reduce memory overheads for storing a Memoize tuple
In-Reply-To: <E1wxFL7-00000001Rru-0kfV@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