CREATE INDEX vs. TOAST table stats

From: Nathan Bossart <nathandbossart(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: pgsql(at)j-davis(dot)com
Subject: CREATE INDEX vs. TOAST table stats
Date: 2026-08-11 17:25:01
Message-ID: anta7SkBl0iXdqlG@nathan
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Commit d611f8b158 taught CREATE INDEX to avoid updating table stats when
autovacuum = off so that restored stats weren't wiped out. It included
RELKIND_TOASTVALUE in the list of affected relkinds, which I think is
incorrect for the following reasons:

* You can't restore stats for TOAST tables.

* If toast.autovacuum_enabled is unset for the TOAST table, it should
inherit the main table's setting, and the code doesn't do that. Per the
above point, there's little point in teaching it to do so.

This bug probably doesn't have much impact, other than perhaps increasing
the TOAST table's autovacuum priority immediately after restore. I think
we should just back-patch something like the following down to v18:

diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 4c5da7e5db0..993a68fbc5e 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -2893,7 +2893,6 @@ index_update_stats(Relation rel,
* created, and we want to preserve the restored table statistics.
*/
if (rel->rd_rel->relkind == RELKIND_RELATION ||
- rel->rd_rel->relkind == RELKIND_TOASTVALUE ||
rel->rd_rel->relkind == RELKIND_MATVIEW)
{
if (AutoVacuumingActive())

--
nathan

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Corey Huinker 2026-08-11 17:30:51 Re: use of SPI by postgresImportForeignStatistics
Previous Message Tom Lane 2026-08-11 17:02:57 Re: Crash issue in PG18.5 regression