reorder GROUP BY list - Mailing list pgsql-patches

From Neil Conway
Subject reorder GROUP BY list
Date
Msg-id 1141523094.24513.60.camel@localhost.localdomain
Whole thread Raw
Responses Re: reorder GROUP BY list  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-patches
Per recent discussion on -hackers, we should sometimes try to reorder
the columns of the grouping clause to avoid redundant sorts. The
optimizer is not currently capable of doing this, so this patch
implements a simple hack in the analysis phase (transformGroupClause):
if any subset of the GROUP BY clause matches a prefix of the ORDER BY
list, that prefix is moved to the front of the GROUP BY clause. This
shouldn't change the semantics of the query, and allows a redundant sort
to be avoided for queries like "GROUP BY a, b ORDER BY b".

One question about the implementation: to avoid redundant and
potentially expensive calls to findTargetlistEntry(), I constructed a
temporary list of TLEs. I think that's probably a good tradeoff, but
suggestions for improvement are welcome. Also, I released the list via
list_free() when finished with it -- is that a waste of cycles?

Barring any objections, I'll apply this to HEAD tomorrow.

-Neil


Attachment

pgsql-patches by date:

Previous
From: Tom Lane
Date:
Subject: Re: LDAP auth
Next
From: Tom Lane
Date:
Subject: Re: reorder GROUP BY list