On 20/7/2023 18:46, Tomas Vondra wrote:
> 2) estimating quicksort comparisons - This relies on ndistinct
> estimates, and I'm not sure how much more reliable we can make those.
> Probably not much :-( Not sure what to do about this, the only thing I
> can think of is to track "reliability" of the estimates and only do the
> reordering if we have high confidence in the estimates. That means we'll
> miss some optimization opportunities, but it should limit the risk.
According to this issue, I see two options:
1. Go through the grouping column list and find the most reliable one.
If we have a unique column or column with statistics on the number of
distinct values, which is significantly more than ndistincts for other
grouping columns, we can place this column as the first in the grouping.
It should guarantee the reliability of such a decision, isn't it?
2. If we have extended statistics on distinct values and these
statistics cover some set of first columns in the grouping list, we can
optimize these positions. It also looks reliable.
Any thoughts?
--
regards,
Andrey Lepikhov
Postgres Professional