At runtime, the Optimizer chooses an optimal access method for the query by calculating an implementation cost based on the current state of the database.
The Optimizer models the access cost of each of the following:
The cost of a particular method is the sum of:
The Optimizer using this value to determine the percentage of rows that will be returned and optimizes accordingly. A small value instructs the Optimizer to minimize the time required to retrieve the first n rows.
The Optimizer uses this value to determine the percentage of rows that will be returned and optimizes accordingly. A value greater than or equal to the expected number of resulting rows instructs the Optimizer to minimize the time required to run the entire query.
Page faults and number of rows processed may be predicted by statistics the Optimizer obtains from the database objects, including:
A weighted measure of the expected number of rows to process. This is based on what the relational operators in the row selection predicates (default filter factors) are likely to retrieve:
Key range estimate is a method that the Optimizer uses to gain more accurate estimates of the number of expected rows that are selected from one or more selection predicates. The Optimizer estimates by applying the selection predicates against the left-most keys of an existing index. The default filter factors then can be further refined by the estimate based on the key range. If the left-most keys in an index match columns that are used in row-selection predicates, use that index to estimate the number of keys that match the selection criteria. The estimate of the number of keys is based on the number of pages and key density of the machine index. It is performed without actually accessing the keys. Full indexes over columns that are used in selection predicates can significantly help optimization.