Allow a stats kind to use its own dshash in pgstats Variable-numbered pgstats entries currently all live in one shared dshash table. This works for stats kinds with each one having a rather "small" number of entries, but there are limits if a stats kind wants to allocate a large number of entries, especially if these need to be scanned on a periodic basis.
This commit adds a new own_hash option for variable-numbered stats kinds, allowing these to use an independent dshash table backed by its own DSA area. This gives a way for stats kind to leverage their efforts across more than one shared hashtable, splitting the load, with the same guarantees as the main hashtable. Fixed-sized stats kind cannot use this option. All the hashtables use the same key pattern, PgStat_HashKey. The motivation of this change is pg_stat_statements, to add it as a custom stats kind. Out-of-core custom stats kind, or even built-in stats kinds can also use this option. At startup, each stats kind that opts in creates one initial DSA area in shared memory at startup. At attach time, each registered variable-numbered stats kind is mapped to either the shared hash and DSA or its dedicated hash and DSA. The local references are extended to track which hash table to use on a per-kind basis, with arrays based on the kind ID. The test module test_custom_stats is extended and refactored to provide coverage for this new own_hash. The idea of being able to use more than one hash table for pgstats has been originally mentioned off-list during a conference by Robert Haas (note: if my memory does not fail me here). Author: Sami Imseih <[email protected]> Reviewed-by: Michael Paquier <[email protected]> Reviewed-by: Bertrand Drouvot <[email protected]> Discussion: https://postgr.es/m/CAA5RZ0supQBxSkh=CWB39=j+cl3hhclpki3tcbk0b1r4fes...@mail.gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/44539786b8296b6e73035142670e0d1ff2639078 Modified Files -------------- src/backend/utils/activity/pgstat.c | 254 ++++++++------- src/backend/utils/activity/pgstat_shmem.c | 360 +++++++++++++++------ src/include/utils/pgstat_internal.h | 69 ++-- .../test_custom_stats/t/001_custom_stats.pl | 232 +++++++------ .../test_custom_var_stats--1.0.sql | 5 + .../test_custom_stats/test_custom_var_stats.c | 59 +++- 6 files changed, 630 insertions(+), 349 deletions(-)
