Re: pre-sroted table (w/ index)

From: Steve Atkins <steve(at)blighty(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: pre-sroted table (w/ index)
Date: 2004-10-07 17:30:46
Message-ID: 20041007173046.GB26611@gp.word-to-the-wise.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Oct 07, 2004 at 11:30:37AM -0500, Vic Cekvenich wrote:
> In TransacSQL, we used to have the tabled sorted by marking an index for
> example by create_date.
>
> This way we did not need to do an order by or at least it was faster.

You'll always need to do an order by, as there's no guarantee of the
order of the results received. It may work today, but it may not tomorrow.

> Is there a way to force the table to be physicaly stroed sorted by a
> certain index?

Look in the manual for the SQL command 'CLUSTER'. It doesn't keep a
table ordered on disk as new inserts happen (it's very inefficient to
do so) but it'll order the existing data, which will often speed up
queries that return quite a lot of data from an index scan.

Cheers,
Steve

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Francisco Reyes 2004-10-07 17:38:05 Re: Date variables in psql
Previous Message Scott Frankel 2004-10-07 17:29:45 Re: interfaces for python -- thanks