Re: table partitioning and select max(id)

From: Ken Cox <kenstir(at)gmail(dot)com>
To: Tobias Brox <tobixen(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: table partitioning and select max(id)
Date: 2011-02-05 03:38:04
Message-ID: AANLkTimtBN9UF2ExHTF=Q9Y+nbZO1d+Z6wsK5D-vK=9t@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

This is a known limitation of partitioning. One solution is to use a
recursive stored proc, which can use indexes. Such a solution is
discussed here:
http://archives.postgresql.org/pgsql-performance/2009-09/msg00036.php

Regards,
Ken

http://archives.postgresql.org/pgsql-performance/2009-09/msg00036.php

On Fri, Feb 4, 2011 at 6:24 PM, Tobias Brox <tobixen(at)gmail(dot)com> wrote:
> I implemented table partitioning, and it caused havoc with a "select
> max(id)" on the parent table - the query plan has changed from a
> lightningly fast backwards index scan to a deadly seq scan.  Both
> partitions are set up with primary key index and draws new IDs from
> the same sequence ... "select max(id)" on both partitions are fast.
> Are there any tricks I can do to speed up this query?  I can't add the
> ID to the table constraints, we may still get in "old" data causing
> rows with fresh IDs to get into the old table.
>
> (I decided to keep this short rather than include lots of details -
> but at least worth mentioning that we're using PG9)
>
> --
> Sent via pgsql-performance mailing list (pgsql-performance(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-performance
>

--
-Ken

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Scott Marlowe 2011-02-05 04:45:05 Re: [HACKERS] Slow count(*) again...
Previous Message Ivan Voras 2011-02-05 02:50:50 Re: Query performance with disabled hashjoin and mergejoin