On Mon, Jun 3, 2019 at 12:18 AM Tomas Vondra <tomas.von...@2ndquadrant.com> wrote: > For a moment I thought we could/should look at the histogram, becase that > could tell us if there are groups "before" the first MCV one, but I don't > think we should do that, for two reasons. Firstly, rare values may not get > to the histogram anyway, which makes this rather unreliable and might > introduce sudden plan changes, because the cost would vary wildly > depending on whether we happened to sample the rare row or not. And > secondly, the rare row may be easily filtered out by a WHERE condition or > something, at which point we'll have to deal with the large group anyway.
If first MCV is in the middle of first histogram bin, then it's reasonable to think that it would fit to first group. But if first MCV is in the middle of histogram, such assumption would be ridiculous. Also, I'd like to note that with our default_statistics_target == 100, non MCV values are not so rare. So, I'm +1 for taking histogram into account. ------ Alexander Korotkov Postgres Professional: http://www.postgrespro.com The Russian Postgres Company