Over Indexing


In case the concept of function based indexing is new to you, you might be tempted to index everything. But this is the very last thing you should do. Every index causes ongoing maintenance. Function based indexes are particularly troublesome because they make it very easy to create redundant indexes.

Coaching by the Author
Faster, easier and more memorable than reading.

The case insensitive search from above can be implemented with the LOWER function as well:

SELECT first_name, last_name, phone_number
  FROM employees
 WHERE LOWER(last_name) = LOWER('winand');

The query cannot use the EMP_UP_NAME index because it uses a different function. We could, of course, create a second index on LOWER(last_name) for this query. But the better solution is to use the same function for all case-insensitive searches on LAST_NAME.

Tweet this tip

Tip

Unify the access path so that less indexes can achieve more.

Warning

Sometimes, ORM-Tools use UPPER and LOWER without developer’s knowledge. Hibernate, for example, injects an implicit LOWER to implement case-insensitive searches.

Besides the effort for the initial index creation, the create index statement requires the database to consider the index for every SQL statement executed in the future. For insert, update, and delete it means to apply all table changes to the index too. Chapter 8, “Insert, Delete and Update describes this process in more detail.

Tweet this tip

Tip

Always aim to index the original data. That is often the most useful information you can put into an index.

Recent Questions at Ask.Use-The-Index-Luke.com

0
votes
1
answer
229
views

query regd the CBO decision

Apr 17 at 10:27 Hulda(suspended)
index-choice optimizer
0
votes
3
answers
2.0k
views

Examples for Function Based Indexes?

Mar 25 at 15:52 Castorp 1
function-based
0
votes
1
answer
610
views

Updating multiple rows using a subquery in SQL

Jan 08 at 09:52 Jan 26
subquery update sql