Re: BUG #18916: alter table ... set (n_distinct=) completely ignored on partition head and/or individual partitions

David Rowley <dgrowleyml@gmail.com>

From: David Rowley <dgrowleyml@gmail.com>
To: maxim.boguk@gmail.com, pgsql-bugs@lists.postgresql.org
Date: 2025-05-07T22:49:24Z
Lists: pgsql-bugs
On Thu, 8 May 2025 at 10:40, PG Bug reporting form
<noreply@postgresql.org> wrote:
> I don't know it's missing feature or actual bug in case of native
> partitioning
> alter table partition_head alter somefield set (n_distinct=...)
> and/or alter table individual_paritition alter somefield set
> (n_distinct=...)
> simple have no effect in distinct somefield estimations, thus leading to
> very bad plans.

You'll need to use n_distinct_inherited since partitioned tables use
the inheritance statistics.

The documentation in [1] does not seem to highlight this very well.

David

[1] https://www.postgresql.org/docs/17/sql-altertable.html