Re: sorting problem

From: Lincoln Yeoh <lyeoh(at)pop(dot)jaring(dot)my>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruno Wolff III <bruno(at)wolff(dot)to>
Cc: Greg Stark <gsstark(at)mit(dot)edu>, pgsql-general(at)postgresql(dot)org
Subject: Re: sorting problem
Date: 2004-12-17 20:09:52
Message-ID: 5.2.1.1.1.20041218040359.02c973c8@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

--=======6C297FEF=======
Content-Type: text/plain; x-avg-checked=avg-ok-43C64EFF; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 8bit

At 12:14 PM 12/17/2004 -0500, Tom Lane wrote:

>Bruno Wolff III <bruno(at)wolff(dot)to> writes:
> > Greg Stark <gsstark(at)mit(dot)edu> wrote:
> >> where postgres won't bother with the index since it will be slower
> than just
> >> resorting the entire table.
>
> > Using an index to do an order by is an order N operation. Doing a sort
> > is an order N log N operation. For large values of N, a index will be
> > faster.
>
>Unfortunately not ... the constant factors are such that the index
>solution isn't very competitive at large N, unless the table is already
>well ordered (ie clustered). The sort code is a lot better at avoiding
>random-seeks-all-over-the-disk syndrome.

Which would involve reading less data?

In some cases I'd like to use the method that is more likely to fit within RAM.

Also if there are multiple parallel queries, one could end up with
something similar to random-seeks, so reading/writing less data could still
be better.

Regards,
Link.

--=======6C297FEF=======--

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Greg Stark 2004-12-17 20:36:58 Re: sorting problem
Previous Message Christopher Browne 2004-12-17 19:05:55 Re: Scheduler in Postgres