mirror of
https://git.postgresql.org/git/postgresql.git
synced 2026-02-25 07:47:03 +08:00
This commit changes stats kinds to have the following bounds, making their handling in core cheaper by default: - PGSTAT_KIND_CUSTOM_MIN 128 -> 24 - PGSTAT_KIND_MAX 256 -> 32 The original numbers were rather high, and showed an impact on performance in pgstat_report_stat() for the case of simple queries with its early-exit path if there are no pending statistics to flush. This logic will be improved more in a follow-up commit to bring the performance of pgstat_report_stat() on par with v17 and older versions. Lowering the bounds is a change worth doing on its own, independently of the other improvement. These new numbers should be enough to leave some room for the following years for built-in and custom stats kinds, with stable ID numbers. At least that should be enough to start with this facility for extension developers. It can be always increased in the tree depending on the requirements wanted. Per discussion with Andres Freund and Bertrand Drouvot. Discussion: https://postgr.es/m/eb224uegsga2hgq7dfq3ps5cduhpqej7ir2hjxzzozjthrekx5@dysei6buqthe Backpatch-through: 18
73 lines
2.2 KiB
C
73 lines
2.2 KiB
C
/* ----------
|
|
* pgstat_kind.h
|
|
*
|
|
* Definitions related to the statistics kinds for the PostgreSQL
|
|
* cumulative statistics system. Can be included in backend or
|
|
* frontend code.
|
|
*
|
|
* Copyright (c) 2001-2025, PostgreSQL Global Development Group
|
|
*
|
|
* src/include/utils/pgstat_kind.h
|
|
* ----------
|
|
*/
|
|
#ifndef PGSTAT_KIND_H
|
|
#define PGSTAT_KIND_H
|
|
|
|
/* The types of statistics entries */
|
|
#define PgStat_Kind uint32
|
|
|
|
/* Range of IDs allowed, for built-in and custom kinds */
|
|
#define PGSTAT_KIND_MIN 1 /* Minimum ID allowed */
|
|
#define PGSTAT_KIND_MAX 32 /* Maximum ID allowed */
|
|
|
|
/* use 0 for INVALID, to catch zero-initialized data */
|
|
#define PGSTAT_KIND_INVALID 0
|
|
|
|
/* stats for variable-numbered objects */
|
|
#define PGSTAT_KIND_DATABASE 1 /* database-wide statistics */
|
|
#define PGSTAT_KIND_RELATION 2 /* per-table statistics */
|
|
#define PGSTAT_KIND_FUNCTION 3 /* per-function statistics */
|
|
#define PGSTAT_KIND_REPLSLOT 4 /* per-slot statistics */
|
|
#define PGSTAT_KIND_SUBSCRIPTION 5 /* per-subscription statistics */
|
|
#define PGSTAT_KIND_BACKEND 6 /* per-backend statistics */
|
|
|
|
/* stats for fixed-numbered objects */
|
|
#define PGSTAT_KIND_ARCHIVER 7
|
|
#define PGSTAT_KIND_BGWRITER 8
|
|
#define PGSTAT_KIND_CHECKPOINTER 9
|
|
#define PGSTAT_KIND_IO 10
|
|
#define PGSTAT_KIND_SLRU 11
|
|
#define PGSTAT_KIND_WAL 12
|
|
|
|
#define PGSTAT_KIND_BUILTIN_MIN PGSTAT_KIND_DATABASE
|
|
#define PGSTAT_KIND_BUILTIN_MAX PGSTAT_KIND_WAL
|
|
#define PGSTAT_KIND_BUILTIN_SIZE (PGSTAT_KIND_BUILTIN_MAX + 1)
|
|
|
|
/* Custom stats kinds */
|
|
|
|
/* Range of IDs allowed for custom stats kinds */
|
|
#define PGSTAT_KIND_CUSTOM_MIN 24
|
|
#define PGSTAT_KIND_CUSTOM_MAX PGSTAT_KIND_MAX
|
|
#define PGSTAT_KIND_CUSTOM_SIZE (PGSTAT_KIND_CUSTOM_MAX - PGSTAT_KIND_CUSTOM_MIN + 1)
|
|
|
|
/*
|
|
* PgStat_Kind to use for extensions that require an ID, but are still in
|
|
* development and have not reserved their own unique kind ID yet. See:
|
|
* https://wiki.postgresql.org/wiki/CustomCumulativeStats
|
|
*/
|
|
#define PGSTAT_KIND_EXPERIMENTAL 24
|
|
|
|
static inline bool
|
|
pgstat_is_kind_builtin(PgStat_Kind kind)
|
|
{
|
|
return kind >= PGSTAT_KIND_BUILTIN_MIN && kind <= PGSTAT_KIND_BUILTIN_MAX;
|
|
}
|
|
|
|
static inline bool
|
|
pgstat_is_kind_custom(PgStat_Kind kind)
|
|
{
|
|
return kind >= PGSTAT_KIND_CUSTOM_MIN && kind <= PGSTAT_KIND_CUSTOM_MAX;
|
|
}
|
|
|
|
#endif /* PGSTAT_KIND_H */
|