"=?utf-8?B?Wml6aHVhbkxpdSBYLU1BTg==?=" <[email protected]> writes:
> While reviewing CF6397(https://commitfest.postgresql.org/patch/6397/), I
> noticed that
> the function `var_eq_const()` located at `backend/utils/adt/selfuncs.c`
> consumes statistical
> data from the `most_common_vals` and `most_common_freqs` columns in the system
> catalog `pg_catalog.pg_stats`. Currently, the function terminates iteration
> immediately
> after finding the first matching entry and adopts the selectivity of this
> single matched value.
> I believe this estimation logic is inaccurate. Instead, we should traverse
> all entries in
> `most_common_vals`, check for matches against each entry, and sum up the
> selectivities
> of all matching items.
That would double the function's runtime on average, without changing
the results at all in most cases (it could only be different if the
given operator has different semantics from the equality operator used
while building the statistics list). I think you need a far stronger
argument for changing the existing tradeoff than "I believe".
regards, tom lane