1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

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
This commit is contained in:
David Rowley
2026-10-14 22:06:30 +13:00
parent 857340b026
commit 8b9ffcb110

View File

@@ -1162,7 +1162,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 */