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