Functional indexes

djberg96 on 2004-07-20T15:12:16

You know a book is good when you find yourself saying, "Oh, cool!" often. Today was another one from Guy's book.

Let's say you've got a web form that lets people search on a field in a database, and you want to allow folks to search in a case insensitive way. You could use UPPER(), but then you would lose any benefit of an index on that column. So, how do you deal with this?

Answer: create a functional index, which is simply an index that can include functions within their definition, e.g.

create_index index_foo on bar
(upper(some_column_a), upper(some_column_b))

With that you can still use upper and retain the benefit of the index.