Proactive approach to tuning

Typically you will create an index for the most selective columns and create statistics for the least selective columns in a query. By creating an index, the optimizer knows that the column is selective and it also gives the optimizer the ability to use that index to implement the query.

In a perfect radix index, the order of the columns is important. In fact, it can make a difference as to whether the optimizer uses it for data retrieval at all. As a general rule, order the columns in an index in the following way:

In addition to the guidelines above, in general, the most selective key columns should be placed first in the index.

Consider the following SQL statement:

SELECT b.col1, b.col2, a.col1
   FROM table1 a, table2 b
   WHERE b.col1='some_value' AND
     b.col2=some_number AND
     a.join_col=b.join_col
   GROUP BY b.col1, b.col2, a.col1
   ORDER BY b.col1

With a query like this, the proactive index creation process can begin. The basic rules are: