Re: seq scan in the case of max() on the primary key column

From: Marti Raudsepp <marti(at)juffo(dot)org>
To: sthomas(at)peak6(dot)com
Cc: Magnus Hagander <magnus(at)hagander(dot)net>, Svetlin Manavski <svetlin(dot)manavski(at)gmail(dot)com>, pgsql-performance(at)postgresql(dot)org
Subject: Re: seq scan in the case of max() on the primary key column
Date: 2011-06-22 09:55:46
Message-ID: BANLkTim5saGCxhLCAx4nEUQ4tZuOSy65fg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Thu, Jun 16, 2011 at 21:36, Shaun Thomas <sthomas(at)peak6(dot)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

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Shaun Thomas 2011-06-22 13:12:45 Re: seq scan in the case of max() on the primary key column
Previous Message Craig Ringer 2011-06-22 07:05:14 Re: Improve the Postgres Query performance