pg_stat_have_stats() returns true for dropped indexes (or for index creation transaction rolled back)
Drouvot, Bertrand <bdrouvot@amazon.com>
From: "Drouvot, Bertrand" <bdrouvot@amazon.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2022-08-22T16:39:07Z
Lists: pgsql-hackers
Attachments
- v1-0001-pgstat_drop_relation-for-indexes.patch (text/plain) patch v1-0001
Hi hackers,
While working on the relation stats split into table and index stats
[1], I noticed that currently pg_stat_have_stats() returns true for
dropped indexes (or for index creation transaction rolled back).
Example:
postgres=# create table bdt as select a from generate_series(1,1000) a;
SELECT 1000
postgres=# create index bdtidx on bdt(a);
CREATE INDEX
postgres=# select * from bdt where a = 30;
a
----
30
(1 row)
postgres=# SELECT 'bdtidx'::regclass::oid;
oid
-------
16395
(1 row)
postgres=# select pg_stat_have_stats('relation', 5, 16395);
pg_stat_have_stats
--------------------
t
(1 row)
postgres=# drop index bdtidx;
DROP INDEX
postgres=# select pg_stat_have_stats('relation', 5, 16395);
pg_stat_have_stats
--------------------
t
(1 row)
Please find attached a patch proposal to fix it.
It does contain additional calls to pgstat_create_relation() and
pgstat_drop_relation() as well as additional TAP tests.
[1]:
https://www.postgresql.org/message-id/5bfcf1a5-4224-9324-594b-725e704c95b1%40amazon.com
Regards,
--
Bertrand Drouvot
Amazon Web Services: https://aws.amazon.com
Commits
-
pgstat: Fix transactional stats dropping for indexes
- 43e496e24298 15.0 landed
- d811ce6ea343 16.0 landed