BC remote Oracle DBA - Call (800) 766-1884
Free Oracle Tips

Oracle Consulting Oracle Training Development

Remote DBA

 

Remote DBA Plans
Remote DBA Service

 
Remote DBA Oracle Home
Remote DBA Oracle Training
Remote DBA SQL Tuning Consulting
Remote DBA Oracle Tuning Consulting
Remote DBA Data Warehouse Consulting
Remote DBA Oracle Project Management
Remote DBA Oracle Security Assessment
Remote DBA Unix Consulting
Burleson Books
Burleson Articles
Burleson Web Courses
Burleson Qualifications
Oracle Internals Magazine
Oracle Links
Remote DBA Oracle Monitoring
Remote DBA Support Benefits
Remote DBA Plans & Prices
Our Automation Strategy
What We Monitor
Oracle Apps Support
Print Our Brochure
Contact Us (e-mail)
Oracle Job Opportunities
Oracle Consulting Prices





   

 

 

 

 

 

Index Predicates

Oracle Tips by Burleson Consulting

As a general rule, indexes will always increase the performance of a database query when it is able to utilize the index, and if there is a small subset of rows required by the query. For Oracle, indexes are recommended for two reasons: to speed the retrieval of a small set of rows from a table, and to “presort” result sets so that the SQL order by clause does not cause an internal sort.

In order to use an index, the SQL optimizer must recognize that the column has a valid value for index use. This is called a sargable predicate, and the data types in the column and the predicates must match to allow Oracle to use index access. The term sargable refers to the ability of the SQL optimizer to utilize the index.

Here are some examples of invalid predicates. Note that the data types are mixed, and numeric columns are compared to character strings, and vice versa.

select * from employee
where
   emp_no = "123";

Performing a math function in the where clause can also invalidate an index.

select * from employee
where
   salary * 2 < 50000;

Also, using the not equal operator (<>) will invalidate the index.

select * from employee
where
   dept_no <> 10;

Whenever a transformation to a field value takes place, the Oracle database will not be able to use the index for that column. In the examples that follow, the use of an Oracle built-in function invalidates the standard index:

select * from employee
where
   to_char(hire_date,’YYYY’)=1998;

Using a substring function can also invalidate an index.

select * from employee
where
   substr(last_name,1,4) = ‘FRED’;

Conversion of columns to uppercase or lowercase can also invalidate the index. This use of the upper function is very common on systems that perform row access on test strings, where the end-users do not want the end users to be concerned with case sensitivity:

select * from employee
where
   upper(last_name) = ‘JONES’;

select * from employee
where
   lower(book_title) = ‘war and peace’;

In these cases, a function-based index can be used to allow corresponding access to the columns.

create index
   emp_upper_last_name
on
   emp
   (
      upper(last_name)
   )
;

 

create index
   book_title_lower
on
   book
   (
      lower(book_title)
   )
;

You can also combine the use of function-based indexes with bitmap indexes. In the example that follows, we convert a low-cardinality column such as item_color (which has fewer than 20 distinct values) into a bitmap index. To ensure easy retrieval, we index on the color in lowercase:

create bitmap index
   item_color_lower
on
   book
   (
      lower(item_color)
   )
;

Oracle date datatypes are also problematical, and the to_char function is sometimes needed in SQL to select dates within specific ranges. For example, our SQL may use the to_char function to extract dates for specific years and months. Hence, we can index on the to_char function to specify years and month-year combinations:

select * from customer
where
   to_char(order_date,’YYYY’)=’1999’;

select * from customer
where
   to_char(order_date,’MON-YY’)=’JAN-01’
;

Here we match the function-based indexes with the date format string in the SQL statements:

create index
   cust_order_year
on
   customer
   (
      to_char(order_date,’YYYY’)
   )
;
create index
   cust_order_mon_year
on
   customer
   (
      to_char(order_date,’MON-YY’)
   )
;

Next, let’s look at issues surrounding the like parameter in SQL statements.

Problems with the like Parameter

You cannot create a function-based index using the like parameter, because you cannot create a function-based index on a column mask. Of course, using a like clause will invalidate the index if the high-order item is specified with the percent (%) wildcard:

select * from employee
where
   last_name like ‘%SON’;

The preceding query will not be able to use the index because it begins with the “%” mask. Next, let’s explore index usage within Oracle when a column has an uneven distribution of values.


This is an excerpt from "Oracle High-Performance SQL Tuning" by Donald K. Burleson, published by Oracle Press.


Expert Remote DBA

BC is America's oldest and largest Remote DBA Oracle support provider.  Get real Remote DBA experts, call
BC Remote DBA today.

 

 

Remote DBA Service
 

Oracle Tuning Book

Free Oracle dictionary reference poster

BC Oracle support

Oracle books by Rampant

Oracle monitoring software

North Carolina Oracle Users Group

 

 Arabian horse breeder

Seeing eye horses

 

 

Burleson is the American Team

American Flag

 

 

BC Remote Oracle Support
P.O. Box 511 • Kittrell, NC, 27544

Remote DBA

Remote DBA Services

 

Copyright © 1996 -  2011 by Burleson Enterprises. All rights reserved.

Oracle® is the registered trademark of Oracle Corporation.



Hit Counter