Re: Preserve index stats during ALTER TABLE ... TYPE ...

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Sami Imseih <samimseih(at)gmail(dot)com>
Cc: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Preserve index stats during ALTER TABLE ... TYPE ...
Date: 2025-10-16 05:06:01
Message-ID: aPB9Odd4Kwz78F2q@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Oct 10, 2025 at 07:37:59AM -0500, Sami Imseih wrote:
>> As you can see, the index stats (linked to the column that has been altered) are
>> not preserved. I think that they should be preserved (like a REINDEX does).
>
> I agree.

Hmm. Why should it be always OK to preserve the stats of an index
when one of its attributes is changed so as a relation is rewritten?
A REINDEX (including CONCURRENTLY), while it initiates a rewrite of
the index, does not change the definition of the underlying index. A
type alteration, on the contrary, does. Hence, the planner may decide
to treat a given index differently (doesn't it? Tuple width or
whole-row references come into mind). Keeping the past stats may
actually lead to confusing conclusions when overlapping them with some
of the new number generated under the new type? Could there be more
benefits in always resetting them as we do now?

Any thoughts from others?
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2025-10-16 05:17:15 Re: Add mode column to pg_stat_progress_vacuum
Previous Message Chao Li 2025-10-16 04:24:51 Re: Checkpointer write combining