diff options
| author | Andres Freund <andres@anarazel.de> | 2022-09-23 13:00:55 -0700 |
|---|---|---|
| committer | Andres Freund <andres@anarazel.de> | 2022-09-23 13:00:55 -0700 |
| commit | d811ce6ea343fa8a0b6b9cd7e9cddcbdaa27962b (patch) | |
| tree | 966b225f5c0b61d27c547c311607b9b6cf57c8f5 /src/backend | |
| parent | 0032a5456708811ca95bd80a538f4fb72ad0dd20 (diff) | |
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 8b1dccd37c71, which introduced the bug
Diffstat (limited to 'src/backend')
| -rw-r--r-- | src/backend/catalog/heap.c | 6 | ||||
| -rw-r--r-- | src/backend/catalog/index.c | 3 |
2 files changed, 6 insertions, 3 deletions
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 9b03579e6e0..9a80ccdccdf 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -403,6 +403,9 @@ heap_create(const char *relname, recordDependencyOnTablespace(RelationRelationId, relid, reltablespace); + /* ensure that stats are dropped if transaction aborts */ + pgstat_create_relation(rel); + return rel; } @@ -1477,9 +1480,6 @@ heap_create_with_catalog(const char *relname, if (oncommit != ONCOMMIT_NOOP) register_on_commit_action(relid, oncommit); - /* ensure that stats are dropped if transaction aborts */ - pgstat_create_relation(new_rel_desc); - /* * ok, the relation has been cataloged, so close our relations and return * the OID of the newly created relation. diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index d7192f35e3f..61f1d3926a9 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -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 |
