"Matt Block" <matt@blockdev.net> writes:
> I've not yet looked at the rest of the problem, but doesn't
> ORDER BY make GROUP BY redundant? Just an extra sort?
No. In the first place, there's no extra sort: the planner is well
aware that our current GROUP BY implementation produces ordered output.
In the second place, there's no guarantee that GROUP BY will always
produce ordered output in the future --- we are thinking about changing
over to a hash-table-based implementation of grouping. If you want
ordered output, you should say ORDER BY, not try to outsmart the system.
regards, tom lane