pg_stat_have_stats() returns true for dropped indexes (or for index creation transaction rolled back)

From: "Drouvot, Bertrand" <bdrouvot(at)amazon(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: pg_stat_have_stats() returns true for dropped indexes (or for index creation transaction rolled back)
Date: 2022-08-22 16:39:07
Message-ID: 51bbf286-2b4a-8998-bd12-eaae4b765d99@amazon.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

Attachment Content-Type Size
v1-0001-pgstat_drop_relation-for-indexes.patch text/plain 7.3 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2022-08-22 16:40:40 Re: CFM Manager
Previous Message Jacob Champion 2022-08-22 16:14:33 Re: CFM Manager