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: Move index statistics into their own stats kind
Date: Wed, 12 Aug 2026 03:09:34 +0000
Message-ID: <E1wtzLR-00000000CNZ-0W2F@gemulon.postgresql.org> (raw)

Move index statistics into their own stats kind

This commit splits the relation and index stats data, where the index
data is now moved to a new kind called PGSTAT_KIND_INDEX.  A benefit of
this refactoring is a reduction of the shared memory required for each
index, the new PgStat_StatIdxEntry including only the fields required
for indexes.  This leads to less data flushed to disk on shutdown.
Another benefit is that the addition of new fields for relation-level
stats is easier to think about.  Note that indexes have no need for most
of the xact-level fields that relations care about, clarifying the role
of each counter for each relkind.

System views are updated to use the index-level functions.  Note this
split means a possible break for tools that had the idea to call the
SQL functions for relation stats (not documented), as now these would
return 0 when queried for an index.  These tools can use the new index
functions to achieve the same result.

As of this change, the pending statistics are still controlled by
PgStat_TableStatus for both relation and index kinds.  This is left as a
follow-up piece, this one being good enough on its own.  This commit is
focused on the changes required for the SQL interface, shared memory
management and the on-disk format.

Bump catalog version.
Bump PGSTAT_FILE_FORMAT_ID.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Author: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/f572abe7-a1bb-e13b-48c7-2ca150546822@gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/72a6dad1c9119c5ddebdb16d218213f4201f52a2

Modified Files
--------------
doc/src/sgml/monitoring.sgml                 |  20 +++-
src/backend/catalog/system_views.sql         |  40 ++++----
src/backend/utils/activity/Makefile          |   1 +
src/backend/utils/activity/meson.build       |   1 +
src/backend/utils/activity/pgstat.c          |  16 ++++
src/backend/utils/activity/pgstat_index.c    | 131 +++++++++++++++++++++++++++
src/backend/utils/activity/pgstat_relation.c | 111 +++++++++++++++++------
src/backend/utils/adt/pgstatfuncs.c          | 108 ++++++++++++++++++++++
src/include/catalog/catversion.h             |   2 +-
src/include/catalog/pg_proc.dat              |  69 +++++++++++++-
src/include/pgstat.h                         |  22 ++++-
src/include/utils/pgstat_internal.h          |  15 +++
src/include/utils/pgstat_kind.h              |  23 ++---
src/test/regress/expected/rules.out          |  34 +++----
src/test/regress/expected/stats.out          |  49 +++++-----
src/test/regress/sql/stats.sql               |  22 ++---
src/tools/pgindent/typedefs.list             |   2 +
17 files changed, 547 insertions(+), 119 deletions(-)



Message-ID: <E1wtzLR-00000000CNZ-0W2F@gemulon.postgresql.org>
Permalink:  ../E1wtzLR-00000000CNZ-0W2F@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wtzLR-00000000CNZ-0W2F@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: Move index statistics into their own stats kind
  In-Reply-To: <E1wtzLR-00000000CNZ-0W2F@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