Re: Performance on large, append-only tables - Mailing list pgsql-performance

From Merlin Moncure
Subject Re: Performance on large, append-only tables
Date
Msg-id CAHyXU0wVRgMW_cNwhvg51PT=Rb3Cbu0EEs_2t3QfVf1t33gd4g@mail.gmail.com
Whole thread Raw
In response to Performance on large, append-only tables  (David Yeu <david.yeu@skype.net>)
List pgsql-performance
On Wed, Feb 8, 2012 at 12:03 PM, David Yeu <david.yeu@skype.net> wrote:
> Hi there,
>
> We've got a pretty large table that sees millions of new rows a day, and
> we're trying our best to optimize queries against it. We're hoping to find
> some guidance on this list.
>
> Thankfully, the types of queries that we perform against this table are
> pretty constrained. We never update rows and we never join against other
> tables. The table essentially looks like this:
>
> | id | group_id | created_at | everything elseŠ
>
> Where `id' is the primary key, auto-incrementing, `group_id' is the
> foreign key that we always scope against, and `created_at' is the
> insertion time. We have indices against the primary key and the group_id.
> Our queries essentially fall into the following cases:
>
>  * Š WHERE group_id = ? ORDER BY created_at DESC LIMIT 20;
>  * Š WHERE group_id = ? AND id > ? ORDER BY created_at DESC;
>  * Š WHERE group_id = ? AND id < ? ORDER BY created_at DESC LIMIT 20;
>  * Š WHERE group_id = ? ORDER BY created_at DESC LIMIT 20 OFFSET ?;
>
> In human words, we're looking for:
>
>  * The most recent (20) rows.
>  * The most recent rows after a given `id'.
>  * Twenty rows before a given `id'.
>  * Pages of twenty rows.

You can probably significantly optimize this.  But first, can we see
some explain analyze for the affected queries?

merlin

pgsql-performance by date:

Previous
From: David Yeu
Date:
Subject: Performance on large, append-only tables
Next
From: Claudio Freire
Date:
Subject: Re: Performance on large, append-only tables