pgstat: Fix transactional stats dropping for indexes

Enterprise / PostgreSQL - Andres Freund [] - 23 September 2022 20:00 UTC

Because index creation does not go through heap_create_with_catalog() we didn't call pgstat_create_relation(), leading to index stats of a newly created realtion not getting dropped during rollback. To fix, move the pgstat_create_relation() to heap_create(), which indexes do use.

Similarly, because dropping an index does not go through heap_drop_with_catalog(), we didn't drop index stats when the transaction dropping an index committed. Here there's no convenient common path for indexes and relations, so index_drop() now calls pgstat_drop_relation().

Add tests for transactional index stats handling.

Author: "Drouvot, Bertrand"

d811ce6ea3 pgstat: Fix transactional stats dropping for indexes
src/backend/catalog/heap.c | 6 +-
src/backend/catalog/index.c | 3 +
src/test/regress/expected/stats.out | 109 +++++++++++++++++++++++++++++++++++-
src/test/regress/sql/stats.sql | 50 ++++++++++++++++-
4 files changed, 161 insertions(+), 7 deletions(-)


  • Share