Re: sorting problem

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Greg Stark <gsstark(at)mit(dot)edu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: sorting problem
Date: 2004-12-17 14:26:13
Message-ID: 20041217142613.GA21935@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Dec 16, 2004 at 23:33:00 -0500,
Greg Stark <gsstark(at)mit(dot)edu> wrote:
>
> Chris Smith <chris(at)interspire(dot)com> writes:
>
> > Would doing it this way require an index:
> >
> > create index lower_lastname on table x lower(lastname);
>
> Well it doesn't *require* but it may be a good idea. It depends on your
> queries. It will NOT be useful for a query like:
>
> select * from x order by lower(lastname)
>
> where postgres won't bother with the index since it will be slower than just
> resorting the entire table. The way this index is useful is if you have
> queries of the form:

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. The index will slow down write operations, so it may still be
a bad idea in some cases.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message ON.KG 2004-12-17 14:51:05 Re: Check if table exists
Previous Message ON.KG 2004-12-17 14:16:16 Check if table exists