Re: Multi ordered select and indexing

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Antal Attila <antal(dot)attila(at)ritek(dot)hu>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Multi ordered select and indexing
Date: 2004-04-23 17:37:16
Message-ID: 20040423173716.GA7767@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, Apr 23, 2004 at 16:33:14 +0200,
Antal Attila <antal(dot)attila(at)ritek(dot)hu> wrote:
>
> In our experience, postgres cannot use a multi-colum index on (col1,
> col2) in this situation, becouse there are different directions after
> ORDER BY. Is custom operator class the easiest solution, which can solve
> the reverse indexing on col2? Our problem with this solution, is that we
> have to replace "DESC" with "USING myoperator". Is it possible, that
> postgres can recognize "myoperator" without replacing "DESC"?

Another option you might have is using functional indexes. If you are using
7.4.x or greater and one of the columns has a reasonable - operator
(pretty much this is the numeric types) then you can have an index on
(col1, (-col2)) and then order by col1, -col2.

The main advantage is that this is simpler than making a new opclass.
If you have already gone to that trouble it may be better to stick with it.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Sumita Biswas 2004-04-23 18:10:41 Postgres DB
Previous Message Stephan Szabo 2004-04-23 16:41:21 Re: Multi ordered select and indexing