From: Matt Clark <matt@ymogen.net>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: scott.marlowe <scott.marlowe@ihs.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: slow plan for min/max
Date: Wed, 10 Sep 2003 01:22:09 +0100
Message-ID: <LFEIJBEOKGPDHCEMDGNFOEHNCAAA.matt@ymogen.net> (raw)
In-Reply-To: <16728.1063074086@sss.pgh.pa.us>
> > Know what we (OK, I) need? An explicitly non-aggregate max() and min(),
> > implemented differently, so they can be optimised.
>
> Not per se. The way I've been visualizing this is that we add to
> pg_aggregate a column named, say, aggsortop, with the definition:
...snip of cunning potentially geralisable plan...
> How do you structure the resulting query plan, if it's at all complex
> (think multiple aggregate calls...)? I'm not clear on the answers to
> any of those questions, so I'm not volunteering to try to code it up ...
So, you're not going to code it, I'm not going to code it, I doubt anyone
else is soon.
The issue is going to remain then, that max() and min() are implemented in a
way that is grossly counterintuitively slow for 99% of uses. It's not bad,
or wrong, just a consequence of many higher level factors. This should
therefore be very prominently flagged in the docs until there is either a
general or specific solution.
FYI I have rewritten 4 queries today to work around this (with nice
performance benefits) as a result of this thread. Yeah, I should have
spotted the _silly_ seq scans beforehand, but if you're not looking, you
don't tend to see. Best improvement is 325msec to 0.60msec!
I'm happy to do the doc work.
M
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-performance@postgresql.org
Cc: matt@ymogen.net, tgl@sss.pgh.pa.us, scott.marlowe@ihs.com
Subject: Re: slow plan for min/max
In-Reply-To: <LFEIJBEOKGPDHCEMDGNFOEHNCAAA.matt@ymogen.net>
References: <16728.1063074086@sss.pgh.pa.us> <LFEIJBEOKGPDHCEMDGNFOEHNCAAA.matt@ymogen.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox