Re: [HACKERS] Need some help on code - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: [HACKERS] Need some help on code
Date
Msg-id 199806081516.LAA09082@candle.pha.pa.us
Whole thread Raw
In response to Re: [HACKERS] Need some help on code  (Maarten Boekhold <maartenb@dutepp0.et.tudelft.nl>)
List pgsql-hackers
> My thinking was that the reading from the table is very scattered, but
> that the writing to the new table could be done 'sequentially'. Therefore
> I thought it was interesting to see if it would help to cluster the writes.
>
> > Often the fastest way is to discard the index, and just read the table,
> > sorting each in pieces, and merging them in.  That is what psort does,
> > which is our sort code.  That is why I recommend the SELECT INTO
> > solution if you have enough disk space.
>
> A 'select into ... order by ...' you mean?

Yes.  See CLUSTER manual page:

       Another way is to use SELECT  ...  INTO  TABLE  temp  FROM
       ...ORDER  BY ...  This uses the PostgreSQL sorting code in
       ORDER BY to match  the  index,  and  is  much  faster  for
       unordered  data.   You  then drop the old table, use ALTER

--
Bruce Momjian                          |  830 Blythe Avenue
maillist@candle.pha.pa.us              |  Drexel Hill, Pennsylvania 19026
  +  If your life is a hard drive,     |  (610) 353-9879(w)
  +  Christ can be your backup.        |  (610) 853-3000(h)

pgsql-hackers by date:

Previous
From: Doug Lo
Date:
Subject: Re: [HACKERS] Re: [GENERAL] Should I run regression tests?
Next
From: Oleg Broytmann
Date:
Subject: Re: [HACKERS] backend now show status in 'ps'