mirror of
https://github.com/postgres/postgres.git
synced 2025-11-22 12:22:45 +03:00
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@amazon.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://postgr.es/m/51bbf286-2b4a-8998-bd12-eaae4b765d99@amazon.com
Backpatch: 15-, like 8b1dccd37c, which introduced the bug
This commit is contained in:
@@ -2325,6 +2325,9 @@ index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode)
|
||||
if (RELKIND_HAS_STORAGE(userIndexRelation->rd_rel->relkind))
|
||||
RelationDropStorage(userIndexRelation);
|
||||
|
||||
/* ensure that stats are dropped if transaction commits */
|
||||
pgstat_drop_relation(userIndexRelation);
|
||||
|
||||
/*
|
||||
* Close and flush the index's relcache entry, to ensure relcache doesn't
|
||||
* try to rebuild it while we're deleting catalog entries. We keep the
|
||||
|
||||
Reference in New Issue
Block a user