On Thu, Aug 16, 2018 at 4:10 PM, Thomas Munro <thomas.mu...@enterprisedb.com> wrote: > Can you give an example of problematic ndistinct underestimation?
Yes. See https://postgr.es/m/cakuk5j12qokfh88tqz-ojmsibg2qyjm7k7hlnbyi3ze+y5b...@mail.gmail.com, for example. That's a complaint about an underestimation specifically. This seems to come up about once every 3 years, at least from my perspective. I'm always surprised that ndistinct doesn't get implicated in bad query plans more frequently. > I suppose you might be able to defend against that in the executor: if > you find that you've done an unexpectedly high number of skips, you > could fall back to regular next-tuple mode. Unfortunately that's > require the parent plan node to tolerate non-unique results. I like the idea of dynamic fallback in certain situations, but the details always seem complicated. -- Peter Geoghegan