Re: seq scan in the case of max() on the primary key column - Mailing list pgsql-performance

From Marti Raudsepp
Subject Re: seq scan in the case of max() on the primary key column
Date
Msg-id BANLkTim5saGCxhLCAx4nEUQ4tZuOSy65fg@mail.gmail.com
Whole thread Raw
In response to Re: seq scan in the case of max() on the primary key column  (Shaun Thomas <sthomas@peak6.com>)
Responses Re: seq scan in the case of max() on the primary key column  (Shaun Thomas <sthomas@peak6.com>)
Re: seq scan in the case of max() on the primary key column  (Greg Smith <greg@2ndQuadrant.com>)
List pgsql-performance
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

pgsql-performance by date:

Previous
From: Craig Ringer
Date:
Subject: Re: Improve the Postgres Query performance
Next
From: Shaun Thomas
Date:
Subject: Re: seq scan in the case of max() on the primary key column