From: Marti Raudsepp <marti@juffo.org>
To: sthomas@peak6.com
Cc: Magnus Hagander <magnus@hagander.net>
Cc: Svetlin Manavski <svetlin.manavski@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: seq scan in the case of max() on the primary key column
Date: Wed, 22 Jun 2011 12:55:46 +0300
Message-ID: <BANLkTim5saGCxhLCAx4nEUQ4tZuOSy65fg@mail.gmail.com> (raw)
In-Reply-To: <4DFA4D2F.8020101@peak6.com>
References: <BANLkTikntdSrhneCPzPutY9T-sAQpFXTMw@mail.gmail.com>
<BANLkTikuFEyOse=sUoH0BXYrpUW=7Pp_tw@mail.gmail.com>
<4DFA4D2F.8020101@peak6.com>
On Thu, Jun 16, 2011 at 21:36, Shaun Thomas <sthomas@peak6.com> wrote:
> You can call that instead of max, and it'll be much faster. You can create
> an analog for min if you need it. So for this, you'd call:
Cool, I've needed this function sometimes but never bothered enough to
write it myself. Now I created a wiki snippet page for this handy
feature here:
https://wiki.postgresql.org/wiki/Efficient_min/max_over_partitioned_table
With Jim Nasby's idea to use regclass instead of relation names, the
function is now half its length and probably more reliable. There's no
need to touch pg_class directly at all.
I also changed it to return bigint instead of integer, as that's more
versatile, and the performance loss is probably negligible.
Regards,
Marti
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 using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: marti@juffo.org, sthomas@peak6.com, magnus@hagander.net, svetlin.manavski@gmail.com
Subject: Re: seq scan in the case of max() on the primary key column
In-Reply-To: <BANLkTim5saGCxhLCAx4nEUQ4tZuOSy65fg@mail.gmail.com>
* 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