Re: column order in GROUP BY

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Neil Conway <neilc(at)samurai(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: column order in GROUP BY
Date: 2006-03-03 04:21:46
Message-ID: 26145.1141359706@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Neil Conway <neilc(at)samurai(dot)com> writes:
> A simple hack might help with a subset of this problem, though. For
> queries with both ORDER BY and GROUP BY clauses, we can sort the
> grouping columns according to their position in the ORDER BY list. So,
> given a query like:

> SELECT a, b, max(c) FROM t1 GROUP BY a, b ORDER BY b;

> We can avoid the redundant sort for the ORDER BY by grouping by (b, a)
> instead. Attached is a proof-of-concept patch that implements this,
> although it's an enormous kludge.

I think that's the wrong place. transformGroupClause is the right
place. It already does some hacking to try to make the GROUP BY
semantics match ORDER BY, but it doesn't think to try reordering
the GROUP BY items.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jaime Casanova 2006-03-03 04:55:44 Re: bug in 7.3.2
Previous Message Bruce Momjian 2006-03-03 04:08:45 Re: [PATCHES] Inherited Constraints