]> git.ipfire.org Git - thirdparty/postgresql.git/commit
pgstat: Fix transactional stats dropping for indexes
authorAndres Freund <andres@anarazel.de>
Fri, 23 Sep 2022 20:00:55 +0000 (13:00 -0700)
committerAndres Freund <andres@anarazel.de>
Fri, 23 Sep 2022 20:00:55 +0000 (13:00 -0700)
commitd811ce6ea343fa8a0b6b9cd7e9cddcbdaa27962b
tree966b225f5c0b61d27c547c311607b9b6cf57c8f5
parent0032a5456708811ca95bd80a538f4fb72ad0dd20
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
src/backend/catalog/heap.c
src/backend/catalog/index.c
src/test/regress/expected/stats.out
src/test/regress/sql/stats.sql