pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexander Staubo <alex@purefiction.net>
To: Patrice Castet <pcastet@agematis.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Clustered tables improves perfs ?
Date: Thu, 13 Sep 2007 15:31:58 +0200
Message-ID: <88daf38c0709130631y13e8a185ufd9b9b4c1c9d1ee8@mail.gmail.com> (raw)
In-Reply-To: <46E9353A.9080602@agematis.com>
References: <46E9353A.9080602@agematis.com>

On 9/13/07, Patrice Castet <pcastet@agematis.com> wrote:
> I wonder if clustering a table improves perfs somehow ?

As I understand it, clustering will help cases where you are fetching
data in the same sequence as the clustering order, because adjacent
rows will be located in adjacent pages on disk; this is because hard
drives perform superbly with sequential reads, much less so with
random access.

For example, given a table foo (v integer) populated with a sequence
of integers [1, 2, 3, 4, ..., n], where the column v has an index, and
the table is clustered on that index, a query such as "select v from
foo order by v" will read the data sequentially from disk, since the
data will already be in the correct order.

On the other hand, a query such as "select v from foo order by
random()" will not be able to exploit the clustering. In other words,
clustering is only useful insofar as your access patterns follow the
clustering order.

Alexander.



view thread (3+ messages)  latest in thread

Message-ID: <88daf38c0709130631y13e8a185ufd9b9b4c1c9d1ee8@mail.gmail.com>
Permalink:  ../88daf38c0709130631y13e8a185ufd9b9b4c1c9d1ee8@mail.gmail.com/
Also on:    postgresql.org/message-id/88daf38c0709130631y13e8a185ufd9b9b4c1c9d1ee8@mail.gmail.com

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: alex@purefiction.net, pcastet@agematis.com
  Subject: Re: Clustered tables improves perfs ?
  In-Reply-To: <88daf38c0709130631y13e8a185ufd9b9b4c1c9d1ee8@mail.gmail.com>
  References: <46E9353A.9080602@agematis.com> <88daf38c0709130631y13e8a185ufd9b9b4c1c9d1ee8@mail.gmail.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