From: Shaun Thomas <sthomas@peak6.com>
To: Svetlin Manavski <svetlin.manavski@gmail.com>
Cc: Magnus Hagander <magnus@hagander.net>
Cc: pgsql-performance@postgresql.org
Subject: Re: seq scan in the case of max() on the primary key column
Date: Fri, 17 Jun 2011 07:43:46 -0500
Message-ID: <4DFB4C02.3020505@peak6.com> (raw)
In-Reply-To: <BANLkTikohJ71z=Q0XmEwME6YRD8ev33mwQ@mail.gmail.com>
References: <BANLkTikntdSrhneCPzPutY9T-sAQpFXTMw@mail.gmail.com>
<BANLkTikuFEyOse=sUoH0BXYrpUW=7Pp_tw@mail.gmail.com>
<4DFA4D2F.8020101@peak6.com>
<BANLkTikohJ71z=Q0XmEwME6YRD8ev33mwQ@mail.gmail.com>
On 06/17/2011 06:22 AM, Svetlin Manavski wrote:
> Shaun, that solution is brilliant.
Don't thank me. I actually got the basic idea from a post here a couple
years ago. The only difference is I formalized it somewhat and put it in
our utility schema, where I put lots of other random useful stored procs
I've accumulated over the years. I have another one that works with
dates. :)
I assume you already modified it by removing the 'utility' schema prefix
from the recursive call. The recursive call is in case the child tables
are themselves used as a template for further inheritance. It's rare,
but possible. This function will always get you the max value on a
column in a series of partitioned tables, and quickly so long as it's
indexed.
It's a bit of a hack, but it's worked fine for us while we wait for the
planner to catch up. :)
--
Shaun Thomas
OptionsHouse | 141 W. Jackson Blvd. | Suite 800 | Chicago IL, 60604
312-676-8870
sthomas@peak6.com
______________________________________________
See http://www.peak6.com/email_disclaimer.php
for terms and conditions related to this email
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: sthomas@peak6.com, svetlin.manavski@gmail.com, magnus@hagander.net
Subject: Re: seq scan in the case of max() on the primary key column
In-Reply-To: <4DFB4C02.3020505@peak6.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