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

From: Greg Stark <gsstark(at)mit(dot)edu>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: MAX/MIN optimization via rewrite (plus query rewrites
Date: 2004-11-11 08:08:33
Message-ID: 87fz3gg64e.fsf@stark.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Bruno Wolff III <bruno(at)wolff(dot)to> writes:

> I don't think you should be rewriting queries as much as providing
> alternate plans and letting the rest of the optimizer decided which
> plan to use. If you just rewrite a query you might lock yourself into
> using a poor plan.

Moreover, none of these rewritten queries would work properly for

select min(foo) from tab group by bar

This should still be aware it can use an index on <bar,foo> and get much
better performance. Well it can't know, but it should be able to. All it
should really need to know is that min() only needs a particular subset of the
dataset -- namely the first record, as long as the records are provided in a
particular order.

Also, the same code ought to be able to handle

select first(foo) from tab group by bar

Which is exactly equivalent to the min() case except that no particular
ordering is required.

--
greg

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2004-11-11 09:29:14 Re: MAX/MIN optimization via rewrite (plus query
Previous Message Mark Kirkwood 2004-11-11 08:01:46 Re: MAX/MIN optimization via rewrite (plus query rewrites