Indexes for evaluating a filter
The query optimizer notes whether an index can be used to evaluate a filter. For this purpose, an indexed column is any single column with an index or the first column named in a composite index.
If the values contained in the index are all that is required, the database server does not read the rows. It is faster to omit the page lookups for data pages whenever the database server can read values directly from the index.
- When the column is indexed and a value to be compared is a literal,
a host variable, or an uncorrelated subquery
The database server can locate relevant rows in the table by first finding the row in an appropriate index. If an appropriate index is not available, the database server must scan each table in its entirety.
- When the column is indexed and the value to be compared is a column
in another table (a join expression)
The database server can use the index to find matching values. The following join expression shows such an example:
WHERE customer.customer_num = orders.customer_num
If rows of customer are read first, values of customer_num can be applied to an index on orders.customer_num.
- When processing an ORDER BY clause
If all the columns in the clause appear in the required sequence within a single index, the database server can use the index to read the rows in their ordered sequence, thus avoiding a sort.
- When processing a GROUP BY clause
If all the columns in the clause appear in one index, the database server can read groups with equal keys from the index without requiring additional processing after the rows are retrieved from their tables.