Re: Third thoughts about the DISTINCT MAX() problem

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Third thoughts about the DISTINCT MAX() problem
Date: 2008-03-29 01:28:53
Message-ID: 17874.1206754133@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Gurjeet Singh 2008-03-29 01:37:10 Re: Third thoughts about the DISTINCT MAX() problem
Previous Message Tom Lane 2008-03-28 21:51:43 Third thoughts about the DISTINCT MAX() problem