Re: Improve docs for n_distinct_inherited
David Rowley <dgrowleyml@gmail.com>
From: David Rowley <dgrowleyml@gmail.com>
To: Chao Li <li.evan.chao@gmail.com>
Cc: "David G. Johnston" <david.g.johnston@gmail.com>, PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2025-10-13T03:48:42Z
Lists: pgsql-hackers
Attachments
- doc_n_distinct_inherited_v4.patch (application/octet-stream) patch v4
On Mon, 13 Oct 2025 at 14:47, Chao Li <li.evan.chao@gmail.com> wrote:
>
> Hi David,
>
> I think your revision is good and accurate.
>
> On Oct 13, 2025, at 07:42, David Rowley <dgrowleyml@gmail.com> wrote:
> I wonder if ", since the multiplication by the number of rows in the
> table is not performed until query planning time" should be deleted
> since I modified the text earlier to talk about "the query planner”.
>
>
> Yeah, with your rewrite, that clause now feels a little redundant. I think it can be removed entirely.
I've now removed that part.
> The other thing that doesn’t belong to your change but as you are touching here:
>
> “When set to a negative value, which must be greater than or equal to -1"
>
> When I first time read the doc, I was confused. Because no easier sentence indicated “n_distinct” is of float type. I thought “greater than” was a typo. When I read through, the later example (0.5) resolved my confusion. To avoid the same confusion to other readers, maybe change to “when set to a negative value between -1 and 0 (inclusive of -1)” or “when set to a negative value, which must be in the range -1<= value < 0”.
I agree that part is a bit clumsy. Starting at this cold again today I
also thought it must mean less than -1, so rewording that seems like a
good idea.
It now reads:
Fractional values may also be specified by using values below 0 and above
or equal to -1. This instructs the query planner to estimate the number
of distinct values by multiplying the absolute value of the specified
number by the estimated number of rows in the table.
Updated patch attached.
David
Commits
-
Doc: clarify n_distinct_inherited setting
- c3b9e565137b 13.23 landed
- 715eb62e30ac 14.20 landed
- 46086fb6812f 15.15 landed
- 0a47f054ef8d 16.11 landed
- f428b1231ccf 17.7 landed
- f691e72585a3 18.1 landed
- 615a0fc2f1fd 19 (unreleased) landed