Re: MAX/MIN optimization via rewrite (plus query rewrites - Mailing list pgsql-hackers

From Dawid Kuroczko
Subject Re: MAX/MIN optimization via rewrite (plus query rewrites
Date
Msg-id 758d5e7f04111423557f06ce01@mail.gmail.com
Whole thread Raw
In response to Re: MAX/MIN optimization via rewrite (plus query rewrites  (Greg Stark <gsstark@mit.edu>)
List pgsql-hackers
On 15 Nov 2004 02:00:37 -0500, Greg Stark <gsstark@mit.edu> wrote:
> I think people should get away from thinking about "order by + limit". That
> isn't going to work for anything with a GROUP BY. And it isn't going to work
> for anything more complex than a single min() or max().
> 
> min() only needs the first record from whatever set of records it's operating
> on as long as they're provided in a specified order. This is just as true for
> a min() applied to only a single GROUP as it is for a min() applied to an
> entire table.

But as far as I can tell there is no way of forcing such order, at least
ORDER BY queries are doomed to fail:

select max(val) from test_max order by val desc;
ERROR:  column "test_max.val" must appear in the GROUP BY clause or be
used in an aggregate function

Anyway I think that any optimization (supposedly "imlicit" order by
when min() or max() is the only requested column) would at least stop
people from using
awkward syntax for performance reasons...
   Regards,       Dawid


pgsql-hackers by date:

Previous
From: Christopher Kings-Lynne
Date:
Subject: Odd plpgsql behaviour
Next
From: "Zeugswetter Andreas DAZ SD"
Date:
Subject: Re: psql \e broken again