postgres.git / summary / log / commit / refs

commit    bd811277c90a6a29980d664da02e8bddccbe622a
Author:   David Rowley <drowley@postgresql.org>
Date:     Wed Oct 14 09:09:10 2026 +0000
First released in: 14.25, 15.20, 16.16, 17.12, 18.7, 19.0

    Accumulate Memoize parallel worker stats across rescans
    
    When a Gather or Gather Merge node is rescanned, it starts a new set of
    workers, which write their Memoize stats into the same shared memory
    slots as the previous worker.  ExecEndMemoize() used memcpy() for this,
    so EXPLAIN ANALYZE showed only the stats for the final scan.
    
    Here we adjust ExecEndMemoize() to accumulate the counters so that we
    gather up the totals over all rescans.
    
    Author: Tatsuya Kawata <kawatatatsuya0913@gmail.com>
    Reviewed-by: David Rowley <dgrowleyml@gmail.com>
    Discussion: https://postgr.es/m/CAHza6qeA-4vB355co-2yAxDMRTpEneY0rg9CD2zMLYscYvv2UA@mail.gmail.com
    Backpatch-through: 14


src/backend/executor/nodeMemoize.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/backend/executor/nodeMemoize.c b/src/backend/executor/nodeMemoize.c index 1da0600999d..523550b5083 100644 --- a/src/backend/executor/nodeMemoize.c +++ b/src/backend/executor/nodeMemoize.c @@ -1111,7 +1111,16 @@ ExecEndMemoize(MemoizeState *node) Assert(ParallelWorkerNumber < node->shared_info->num_workers); si = &node->shared_info->sinstrument[ParallelWorkerNumber]; - memcpy(si, &node->stats, sizeof(MemoizeInstrumentation)); + + /* + * Gather and GatherMerge spin up new workers on rescan, so add these + * counters to accumulate the values over all scans. + */ + si->cache_hits += node->stats.cache_hits; + si->cache_misses += node->stats.cache_misses; + si->cache_evictions += node->stats.cache_evictions; + si->cache_overflows += node->stats.cache_overflows; + si->mem_peak = Max(si->mem_peak, node->stats.mem_peak); } /* Remove the cache context */ [parent: 6161b2c3d162]