Re: cluster index on a table

From: Scara Maccai <m_lists(at)yahoo(dot)it>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: cluster index on a table
Date: 2009-07-16 13:33:28
Message-ID: 66995.96754.qm@web24612.mail.ird.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance


>   +1 for index organized tables 

+1

I have a table:

CREATE TABLE mytab
(
"time" timestamp without time zone NOT NULL,
ne_id integer NOT NULL,
values integer,
CONSTRAINT mytab_pk PRIMARY KEY (ne_id, "time"),
CONSTRAINT mytab_ne_id_key UNIQUE ("time", ne_id)
}

The table is written every 15 minutes (that is, every 15 minutes all 20000 ne_ids get written), so the table is "naturally" clustered on ("time", ne_id).

Since I need it clustered on (ne_id, "time"), I tried to cluster on a day by day basis, since clustering the whole table would take too much time: that is, I'd "reorder" the table every day (say at 1:00 AM).

I've written a function (below) that re-insterts rows in the table ordered by ne_id,time; but it doesn't work! When I do a "select * from mytab" rows aren't ordered by (ne_id,time)....

What am I doing wrong?

CREATE OR REPLACE FUNCTION somefunc()
RETURNS void AS
$BODY$
DECLARE
t1 timestamp := '2006-10-01 00:00:00';
t2 timestamp := '2006-10-01 23:59:00';
BEGIN
lock table stscell60_60_13_2800_512_cell_0610_leo in ACCESS EXCLUSIVE MODE;
WHILE t1 < '2006-11-01 00:00:00' LOOP
insert into mytab select time,ne_id+100000, values from mytab where time between t1 and t2 order by ne_id,time;
DELETE from mytab where time between t1 and t2 and ne_id<100000;
update mytab set ne_id = ne_id - 100000 where time between t1 and t2;
t1 := t1 + interval '1 days';
t2 := t2 + interval '1 days';
END LOOP ;
END;
$BODY$
LANGUAGE 'plpgsql'

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Wayne Conrad 2009-07-16 15:00:43 Re: Poor overall performance unless regular VACUUM FULL
Previous Message Scott Mead 2009-07-16 12:34:42 Re: cluster index on a table