pgsql: pgstat: Fix transactional stats dropping for indexes

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: pgstat: Fix transactional stats dropping for indexes
Date: 2022-09-23 20:43:20
Message-ID: E1obpW3-001hn7-I3@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

pgstat: Fix transactional stats dropping for indexes

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" <bdrouvot(at)amazon(dot)com>
Reviewed-by: Andres Freund <andres(at)anarazel(dot)de>
Reviewed-by: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
Discussion: https://postgr.es/m/51bbf286-2b4a-8998-bd12-eaae4b765d99@amazon.com
Backpatch: 15-, like 8b1dccd37c71, which introduced the bug

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/d811ce6ea343fa8a0b6b9cd7e9cddcbdaa27962b

Modified Files
--------------
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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2022-09-23 22:22:37 pgsql: Doc: minor cleanups.
Previous Message Tom Lane 2022-09-23 18:44:51 Re: pgsql: Doc: update v15 release notes through today.