Re: Third thoughts about the DISTINCT MAX() problem

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Third thoughts about the DISTINCT MAX() problem
Дата
Msg-id 17874.1206754133@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Third thoughts about the DISTINCT MAX() problem  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
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


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Third thoughts about the DISTINCT MAX() problem
Следующее
От: "Gurjeet Singh"
Дата:
Сообщение: Re: Third thoughts about the DISTINCT MAX() problem