Enterprise Edition Home | Express Edition Home | Previous Page | Next Page   Improving Individual Query Performance > Improving Performance with Indexes >

Using Composite Indexes

The optimizer can use a composite index (one that covers more than one column) in several ways. The database server can use an index on columns a, b, and c (in that order) in the following ways:

Execution is most efficient when you create a composite index with the columns in order from most to least distinct. In other words, the column that returns the highest count of distinct rows when queried with the DISTINCT keyword in the SELECT statement should come first in the composite index.

If your application performs several long queries, each of which contains ORDER BY or GROUP BY clauses, you can sometimes improve performance by adding indexes that produce these orderings without requiring a sort. For example, the following query sorts each column in the ORDER BY clause in a different direction:

SELECT * FROM t1 ORDER BY a, b DESC;

To avoid using temporary tables to sort column a in ascending order and column b in descending order, you must create a composite index on (a, b DESC) or on (a DESC, b). You need to create only one of these indexes because of the bidirectional-traverse capability of the database server. For more information on bidirectional traverse, see the IBM Informix: Guide to SQL Syntax.

On the other hand, it can be less expensive to perform a table scan and sort the results instead of using the composite index when the following criteria are met:

Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]