Re: CLUSTER equivalent

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Kevin Murphy <murphy(at)genome(dot)chop(dot)edu>
Cc: PostgreSQL general <pgsql-general(at)postgresql(dot)org>
Subject: Re: CLUSTER equivalent
Date: 2005-08-02 16:08:18
Message-ID: 11337.1122998898@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Kevin Murphy <murphy(at)genome(dot)chop(dot)edu> writes:
> Are the two following options equivalent?
> OPTION A (ordered insert):

> CREATE TABLE table1 (cluster_col TEXT, col2 INTEGER);
> CREATE INDEX idx1 ON table1(cluster_col);
> INSERT INTO table1 (cluster_col, col2) SELECT cluster_col, col2 FROM
> table1 ORDER BY cluster_col;

> OPTION B (unordered insert followed by CLUSTER):

> CREATE TABLE table1 (cluster_col TEXT, col2 INTEGER);
> CREATE INDEX idx1 ON table1(cluster_col);
> INSERT INTO table1 (cluster_col, col2) SELECT cluster_col, col2 FROM table1;
> CLUSTER idx1 ON table1;

Pretty much, but the first is probably faster. CLUSTER is not the
speediest possible way of sorting data :-(

> P.S. On another topic, did I gather correctly from a recent thread that
> it would be more efficient to define the above table (if it were really
> only two columns) as:

> create table clustered_tagged_genes (integer pmid, text mention);

> i.e., with the integer field before the text field?

Yeah, putting fixed-width fields first is usually a (marginal) win.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dan Armbrust 2005-08-02 16:34:40 BUG #1552 followup
Previous Message Dan Armbrust 2005-08-02 16:05:48 Force PostgreSQL to use indexes on foreign key lookups - Was: Slow Inserts on 1 table?