On Sun, Jul 7, 2024 at 2:32 AM Konstantin Knizhnik <knizh...@garret.ru> wrote: > If mksort really provides advantage only when there are a lot of > duplicates (for prefix keys?) and of small fraction of duplicates there > is even some (small) regression > then IMHO taking in account in planner information about estimated > number of distinct values seems to be really important.
I don't think we can rely on the planner's n_distinct estimates for this at all. That information tends to be massively unreliable when we have it at all. If we rely on it for good performance, it will be easy to find cases where it's wrong and performance is bad. -- Robert Haas EDB: http://www.enterprisedb.com