| From: | Michael Paquier <michael(at)paquier(dot)xyz> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Move index statistics into their own stats kind |
| Date: | 2026-08-12 03:09:34 |
| Message-ID: | E1wtzLR-00000000CNZ-0W2F@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
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(dot)pg(at)gmail(dot)com>
Author: Michael Paquier <michael(at)paquier(dot)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(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Fujii Masao | 2026-08-12 05:44:35 | pgsql: Avoid unnecessary matview populated-state updates |
| Previous Message | Michael Paquier | 2026-08-12 00:56:44 | pgsql: Fix unlink() error report in KeepFileRestoredFromArchive() |