Joseph Shraibman <jks(at)selectacast(dot)net> writes:
> But why would group by need to sort it? To insert it into a tree to
> make lookups of distinct values faster?
No, to bring identical values together. GROUP BY and DISTINCT are both
implemented as basically a "sort | uniq" pipeline.
regards, tom lane