Re: Reverse Index ... how to ...

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Marc G(dot) Fournier" <scrappy(at)postgresql(dot)org>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Reverse Index ... how to ...
Date: 2006-04-05 19:06:03
Message-ID: 12527.1144263963@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Marc G. Fournier" <scrappy(at)postgresql(dot)org> writes:
> I'm still searching through Google and whatnot, but not finding anything
> off the bat ... is there some way of creating a 'REVERSE INDEX' on a
> column in a table?

> For instance, when I do a 'CLUSTER' to sort a table based on an INDEX, I'd
> like to sort it in reverse order, so would need the INDEX to go from
> 'GREATEST to LOWEST', vs 'LOWEST to GREATEST' ...

You shouldn't need to worry about that during CLUSTER, as the system is
perfectly capable of scanning an index in either forward or backward
order at runtime. For example,

regression=# explain select * from tenk1 order by unique1;
QUERY PLAN
------------------------------------------------------------------------------------
Index Scan using tenk1_unique1 on tenk1 (cost=0.00..1572.00 rows=10000 width=244)
(1 row)

regression=# explain select * from tenk1 order by unique1 desc;
QUERY PLAN
---------------------------------------------------------------------------------------------
Index Scan Backward using tenk1_unique1 on tenk1 (cost=0.00..1572.00 rows=10000 width=244)
(1 row)

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Marc G. Fournier 2006-04-05 19:14:44 Re: Reverse Index ... how to ...
Previous Message Oleg Bartunov 2006-04-05 18:20:51 Re: Reverse Index ... how to ...