I wrote: > Plan B was to try to revert to the way sort clause matching was > done pre-8.3, that is have make_sort_from_pathkeys check first > for a matching ressortgroupref tag before it goes looking for equal() > expressions. I had actually tried to do that first but got hung > up on the problem of identifying the correct sort operator --- > just taking the exposed type of the targetlist entry doesn't always > work, because of binary-compatible cases (eg, tlist entry may say > it yields varchar but we need to find the text opclass). Perhaps > thinking a bit harder would yield a solution though.
Ah, got it. I had previously attached a sortref to EquivalenceClasses (ec_sortref) to deal properly with multiple textually-identical but volatile expressions. But that's really the wrong thing: sortrefs should be attached to individual EquivalenceMembers, instead. If we do that then the existing logic in make_sort_from_pathkeys can be made to use the sortref as a preferred (and faster) way of identifying which tlist member matches a pathkey. This implies a change in the EquivalenceClass data structures, but those are never dumped to disk so it's not a problem to back-patch. Note: we still need to be able to match on equal() since we may have to deal with sort keys that are not any of the explicit ORDER BY expressions and hence don't have a sortref. But that's not a problem for the MIN/MAX optimization since the only things left to do after planagg.c are apply explicit ORDER BY or DISTINCT operations. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers