Re: Clustering with enough work_mem: copy heap in mem? - Mailing list pgsql-general

From Scott Marlowe
Subject Re: Clustering with enough work_mem: copy heap in mem?
Date
Msg-id dcc563d10908200735o843e986sfbecc3990098d3b7@mail.gmail.com
Whole thread Raw
In response to Clustering with enough work_mem: copy heap in mem?  (Scara Maccai <m_lists@yahoo.it>)
Responses Re: Clustering with enough work_mem: copy heap in mem?
List pgsql-general
On Thu, Aug 20, 2009 at 8:28 AM, Scara Maccai<m_lists@yahoo.it> wrote:
> Hi,
>
> I have a table with 15M rows. Table is around 5GB on disk.
>
> Clustering the table takes 5 minutes.
>
> A seq scan takes 20 seconds.
>
> I guess clustering is done using a seq scan on the index and then fetching the proper rows in the heap.
> If that's the case, fetching random rows on disk is the cause of the enormous time it takes to cluster the table.

Yep.

> Since I can set work_mem > 5GB. couldn't postgres do something like:
>
> - read the whole table in memory
> - access the table in memory instead of the disk when reading the "indexed" data

I've found it easier to select everything into another table, truncate
the original table, then insert the rows as:

insert into orig_table select * from mytemptable order by field1,field2;

If needs be you can lock the original table to prevent modifications
while doing this.

pgsql-general by date:

Previous
From: Scara Maccai
Date:
Subject: Clustering with enough work_mem: copy heap in mem?
Next
From: Scara Maccai
Date:
Subject: Re: Clustering with enough work_mem: copy heap in mem?