agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Add new pgstats routine to split pending data setup
Date: Tue, 21 Jul 2026 23:15:59 +0000
Message-ID: <E1wmJgt-00000000EDa-13GH@gemulon.postgresql.org> (raw)

Add new pgstats routine to split pending data setup

This commit adds pgstat_prep_pending_from_entry_ref(), a new pgstats
routine that is able to prepare an existing PgStat_EntryRef to receive
pending stats.  This split gives a way for callers to obtain first a
reference via pgstat_get_entry_ref(), then set up pending data as two
separate, distinctive, steps.

Previously, the only way to get an entry reference with pending data
ready was pgstat_prep_pending_entry(), which bundles lookup, creation,
and pending setup in a single call.  Callers that need finer control
over the entry creation had no way to attach pending data to an
already-obtained entry reference.  One case where this has shown to
matter for a stats kind is where one wants to check some capacity (for
example where a GUC bounds the maximum numer of entries allowed) before
deciding if a new entry should be created.  So this split can help in
reducing calls to pgstat_get_entry_ref(), meaning less shmem hash table
lookups.

The only logical ordering change is that pgStatPendingContext is
initialized after calling pgstat_get_entry_ref() in
pgstat_prep_pending_entry().  This does not matter in practice.

pgstat_prep_pending_entry() is refactored to use the new function
internally.  All the existing callers are unchanged.  Existing
out-of-core custom stats kinds should see no impact.

Author: Sami Imseih <samimseih@gmail.com>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAA5RZ0sV+TsLejUMhAM=PJoOm8u-t8ru7B67KvyLCy=19sM87g@mail.gmail.com

Branch
------
master

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

Modified Files
--------------
src/backend/utils/activity/pgstat.c | 55 +++++++++++++++++++++++--------------
src/include/utils/pgstat_internal.h |  1 +
2 files changed, 36 insertions(+), 20 deletions(-)



Message-ID: <E1wmJgt-00000000EDa-13GH@gemulon.postgresql.org>
Permalink:  ../E1wmJgt-00000000EDa-13GH@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wmJgt-00000000EDa-13GH@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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: michael@paquier.xyz, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Add new pgstats routine to split pending data setup
  In-Reply-To: <E1wmJgt-00000000EDa-13GH@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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox