views:

218

answers:

3

If I create a reverse index in Oracle on a VARCHAR2 column do I also need to reverse the value used in the WHERE clause?

CREATE INDEX myindex ON myTable(name) REVERSE;

SELECT name FROM myTable WHERE name='Peter';

or

SELECT name FROM myTable WHERE name='reteP';
A: 

No you don't - see Burleson for the full skinny.

Greg Reynolds
+2  A: 

You need it to improve the data distribution.

Like, many movie names begin with The which would degrade the index performance.

You don't need to reverse the condition: Oracle will do it for you automatically.

However, you cannot do range queries anymore:

SELECT name FROM myTable WHERE name BETWEEN 'A' AND 'C'

will result in a full scan

Quassnoi
Thanks - that's kind of what I figured.
Gandalf
+5  A: 

The value you are searching for is 'Peter'. If you search for 'reteP' you will return zero rows (or at least not the rows you're looking for).

APC