| From: | Mark Kirkwood <markir(at)paradise(dot)net(dot)nz> |
|---|---|
| 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 03:18:43 |
| Message-ID: | 42574993.20101@paradise.net.nz |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Looks great! I had been slowly thinking along similar lines via the
equivalence:
SELECT min(x) FROM tab WHERE...
SELECT min(x) FROM (SELECT x FROM tab WHERE ... ORDER BY x LIMIT 1) AS t
However, it looks like your approach is more flexible than this :-)
best wishes
Mark
Tom Lane wrote:
>
> I realized today that this may not be as hard as I thought.
> 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);
>
> Breaking it down like that means we can consider each aggregate
> independently, which definitely simplifies matters.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2005-04-09 03:36:15 | Re: Optimizing maximum/minimum queries (yet again) |
| Previous Message | Bruno Wolff III | 2005-04-09 02:44:32 | Re: Optimizing maximum/minimum queries (yet again) |