Thread: pgsql: Per recent discussion on -hackers, we should sometimes reorder

pgsql: Per recent discussion on -hackers, we should sometimes reorder

From
neilc@postgresql.org (Neil Conway)
Date:
Log Message:
-----------
Per recent discussion on -hackers, we should sometimes 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".

Modified Files:
--------------
    pgsql/src/backend/parser:
        parse_clause.c (r1.146 -> r1.147)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/parser/parse_clause.c.diff?r1=1.146&r2=1.147)