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

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Sami Imseih <samimseih(at)gmail(dot)com>, 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 06:09:24
Message-ID: aPCMFGpqUrGOzKf_@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Oct 16, 2025 at 01:38:19AM -0400, Tom Lane wrote:
> Michael Paquier <michael(at)paquier(dot)xyz> writes:
>> 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?
>
> Right offhand, this proposal seems utterly unsafe, to the point of
> maybe introducing security-grade bugs. I see that the patch compares
> opfamilies but that seems insufficient, since "same opfamily" does not
> mean "binary compatible". We could easily be restoring stats whose
> binary content is incompatible with the new column type.

The point of the thread is about copying the aggregated numbers stored
in pgstats. These numbers have a fixed size, for contents in
PgStat_StatTabEntry. The point of the patch is about copying these
entries in the pgstats hash table across rewrites, so I am not sure to
follow your argument.

My point was slightly different: I am questioning if a reset does not
make more sense in most cases as an attribute type change may cause
the planner to choose a different Path, making the new stats generated
leading to decisions that are inconsistent when aggregated with the
numbers copied across the rewrites.
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2025-10-16 06:19:21 Re: Add RESPECT/IGNORE NULLS and FROM FIRST/LAST options
Previous Message Renzo Dani 2025-10-16 06:07:42 Re: Extend documentation for pg_stat_replication.backend_xmin