Re: MAX/MIN optimization via rewrite (plus query rewrites generally)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruno Wolff III <bruno(at)wolff(dot)to>
Cc: Zeugswetter Andreas DAZ SD <ZeugswetterA(at)spardat(dot)at>, Mark Kirkwood <markir(at)coretech(dot)co(dot)nz>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: MAX/MIN optimization via rewrite (plus query rewrites generally)
Date: 2004-11-11 18:21:23
Message-ID: 9858.1100197283@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Bruno Wolff III <bruno(at)wolff(dot)to> writes:
> Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> We know how to determine that an index matches an ORDER BY clause.
>> But what has an aggregate called MAX() got to do with ORDER BY?

> Wouldn't knowing an opclass and direction associated with an aggregrate
> function allow you to do this?

That's one way you could do it. Another possibly cleaner way is to just
supply a sort operator (with the implication "the desired value is the
one ordered first by this operator") and then let the optimizer work out
which opclass(es) are relevant. This would win if the same operator
appears in different opclasses, which is uncommon at the moment but
would not be so if we start offering "reverse sort" opclasses.

I think we covered all this ground before, though --- have you checked
the archives from the last time this was discussed?

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Stark 2004-11-11 18:23:16 Re: MAX/MIN optimization via rewrite (plus query
Previous Message Greg Stark 2004-11-11 18:15:09 Re: MAX/MIN optimization via rewrite (plus query rewrites generally)