index suggestion for 7.4 - Mailing list pgsql-hackers

From Bruno Wolff III
Subject index suggestion for 7.4
Date
Msg-id 20030530160200.GA22099@wolff.to
Whole thread Raw
Responses Re: index suggestion for 7.4
Re: index suggestion for 7.4
List pgsql-hackers
Now that expressions can be used in indexes in 7.4 you can have multicolumn
indexes that are ordered in different directions. However the planner
doesn't seem to understand that order by -col asc is the same as order by
col desc (for at least the normal -) so you have to be careful how you
write queries when doing this.

For example:

bruno=> \d test    Table "public.test"Column |  Type   | Modifiers 
--------+---------+-----------col1   | integer | col2   | integer | 
Indexes:   "test1" btree (col1, ((- col2)))

bruno=> explain select col1, col2 from test order by col1 asc, col2 desc;                          QUERY PLAN
               
 
----------------------------------------------------------------Sort  (cost=814.39..839.39 rows=10000 width=8)  Sort
Key:col1, col2  ->  Seq Scan on test  (cost=0.00..150.00 rows=10000 width=8)
 
(3 rows)

bruno=> explain select col1, col2 from test order by col1 asc, -col2 asc;                              QUERY PLAN
                       
 
------------------------------------------------------------------------Index Scan using test1 on test
(cost=0.00..337.50rows=10000 width=8)
 
(1 row)


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Practical sets of SQLSTATE values?
Next
From: Oleg Bartunov
Date:
Subject: XML and postgres