Skip site navigation (1) Skip section navigation (2)

reorder GROUP BY list

From: Neil Conway <neilc(at)samurai(dot)com>
To: pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: reorder GROUP BY list
Date: 2006-03-05 01:44:54
Message-ID: 1141523094.24513.60.camel@localhost.localdomain (view raw, whole thread or download thread mbox)
Lists: 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.


Attachment: group_by_reorder-4.patch
Description: text/x-patch (5.1 KB)


pgsql-patches by date

Next:From: Tom LaneDate: 2006-03-05 02:21:45
Subject: Re: reorder GROUP BY list
Previous:From: Tom LaneDate: 2006-03-04 19:53:57
Subject: Re: LDAP auth

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group