Re: Optimizing maximum/minimum queries (yet again)

From: Neil Conway <neilc(at)samurai(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Optimizing maximum/minimum queries (yet again)
Date: 2005-04-09 04:19:19
Message-ID: 425757C7.2010302@samurai.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote:
> Specifically, I'm imagining that we could convert
>
> SELECT min(x), max(y) FROM tab WHERE ...
>
> into sub-selects in a one-row outer query:
>
> SELECT (SELECT x FROM tab WHERE ... ORDER BY x LIMIT 1),
> (SELECT y FROM tab WHERE ... ORDER BY y DESC LIMIT 1);

Does this transformation work for a query of the form:

SELECT min(x), max(y) FROM tab WHERE random() > 0.5;

(which isn't a very useful query, but I'm sure you can imagine a more
realistic example involving volatile functions in the WHERE clause.)

-Neil

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2005-04-09 04:26:36 Re: Optimizing maximum/minimum queries (yet again)
Previous Message Bruce Momjian 2005-04-09 04:18:53 Re: [PATCHES] DELETE ... USING