index suggestion for 7.4

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: pgsql-hackers(at)postgresql(dot)org
Subject: index suggestion for 7.4
Date: 2003-05-30 16:02:00
Message-ID: 20030530160200.GA22099@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.50 rows=10000 width=8)
(1 row)

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Oleg Bartunov 2003-05-30 16:06:26 XML and postgres
Previous Message Tom Lane 2003-05-30 15:34:10 Re: Practical sets of SQLSTATE values?