Re: Backwards index scan

From: Dmitry Tkach <dmitry(at)openratings(dot)com>
To: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Backwards index scan
Date: 2003-07-08 14:15:57
Message-ID: 3F0AD21D.2030202@openratings.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-general pgsql-hackers

Stephan Szabo wrote:

>If you make an opclass that orders in the reverse order you can use that
>opclass in creating the index (which effectively can give you an index
>like x, y desc by using the new opclass on y). There was some talk
>recently about whether we should provide such opclasses as builtins or
>contrib items.
>
>
Actually, I just thought, it is not exactly equivalent, unless I am
missing something.
If I create this opclass and the index, and then make a query like
select * from huge_table where x=10 order by x,y desc

... it won't know to use the index for sorting, will it?
My understanding is that I'd have to get rid of the sort clause
completely, and just rely on the query plan, right?

In this situation, it will work... But it may be a problem when the
query is (a lot) more complicated, with several joins and a bunch of
different paths available to the planner - how can I guarantee then that
it will always choose this index and return the results in the right order?

Currently I just always use the sort clause, and that forces it to pick
the right index even if another path looks a little less expensive, but
with this custom opclass, I believe, having the sort clause will always
cause it to actually sort even if it does use the right index...

Or am I missing something here?

Thanks!

Dima

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Stephan Szabo 2003-07-08 15:12:02 Re: Backwards index scan
Previous Message Ivan Boscaino 2003-07-08 09:47:50 Out of memory

Browse pgsql-general by date

  From Date Subject
Next Message Stephan Szabo 2003-07-08 15:12:02 Re: Backwards index scan
Previous Message Richard Huxton 2003-07-08 10:27:37 Re: SQL Functions and plan time

Browse pgsql-hackers by date

  From Date Subject
Next Message Oleg Bartunov 2003-07-08 14:23:13 tsearch2 news
Previous Message ohp 2003-07-08 14:08:05 Re: dns problem?