Subject Re: [firebird-support] Composite index question
Author Ivan Prenosil
> CREATE TABLE T (Foo VARCHAR(20), Bar INTEGER);
>
> SELECT * FROM T
> ORDER BY Foo DESC, Bar
>
> How can I create an index for this query? (yes, I want that Foos are
> descending order and Bars are ascending order)
>
> CREATE INDEX IDX_1 ON T (Foo DESC, Bar)
>
> Statement failed. :(

Right, DESC can't be specified for individual fields.

> But,
>
> CREATE INDEX IDX_1 ON T (Foo DESC)
> CREATE INDEX IDX_2 ON T (Bar)
>
> Statements are OK, but the query is don`t use these indexes. :(

Right, if the index should be used for ordering, then single index
must exist for _all_ fields in ORDER BY clause.

The only workaround I can think of is to store values in Bar with
changed sign.

Ivan
http://www.volny.cz/iprenosil/interbase/