Re: Index Problem

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Kim Yunhan" <spbear(at)hanmail(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Index Problem
Date: 2001-02-09 06:22:54
Message-ID: 17660.981699774@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Kim Yunhan" <spbear(at)hanmail(dot)net> writes:
> I want to query this...
> --> SELECT * FROM bbs ORDER BY ref desc, step ASC LIMIT 12;

> this query doesn't refer the index that made by this query.
> --> CREATE INDEX idx_bbs ON bbs (ref, step);

Well, no. The ordering the query is asking for has nothing to do with
the ordering of the index, so the index is no help.

The simplest answer would be to restructure your data so that the order
you are interested in corresponds to the natural index order. If you
don't like that answer, you could consider making a "reverse" operator
class that sorts the datatype of "ref" in reverse order, and then
building an index on (ref reverse_ops, step). I think the planner would
be smart enough to realize that it could use such an index for your
query ... but it's a sufficiently off-the-wall case that I doubt
anyone's ever tried it. Lemme know if it works ;-)

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message mark proctor 2001-02-09 12:02:33 PL/PGSQL Cook Book
Previous Message Ian Harding 2001-02-09 02:00:45 Re: plpgsql grief