[ Just for the archives' sake at this point, in case somebody has another go at this feature. ]
I wrote: > ... I'm now discovering that the code I'd hoped to salvage in > pathkeys.c (get_useful_group_keys_orderings and related) has its very own > bugs. It's imagining that it can rearrange a PathKeys list arbitrarily > and then rearrange the GROUP BY SortGroupClause list to match, but that's > easier said than done, for a couple of different reasons. It strikes me that the easy solution here is to *not* rearrange the SortGroupClause list at all. What that would be used for later is to generate a Unique node's list of columns to compare, but since Unique only cares about equality-or-not, there's no strong reason why it has to compare the columns in the same order they're sorted in. (Indeed, if anything we should prefer to compare them in the opposite order, since the least-significant column should be the most likely to be different from the previous row.) I'm fairly sure that the just-reverted code is buggy on its own terms, in that it might sometimes produce a clause list that's not ordered the same as the pathkeys; but there's no visible misbehavior, because that does not in fact matter. So this'd let us simplify the APIs here, in particular PathKeyInfo seems unnecessary, because we don't have to pass the SortGroupClause list into or out of the pathkey-reordering logic. regards, tom lane