At run time, 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:
Either a data scan or an existing index is preferred. This mode can be specified in two ways:
The optimizer uses 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.
This option is effective only if the OPTIMIZE FOR n ROWS was not specified.
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.
This option is effective only if the OPTIMIZE FOR n ROWS is not specified.
| Note: | If you specify ALWCPYDTA(*OPTIMIZE) and the query optimizer decides to use the sort routine, your query resolves according to the *ALLIO optimize parameter. |
Page faults and number of rows processed may be predicted by statistics the optimizer can obtain from the database objects, including:
Page faults can also be greatly affected if index only access can be performed, thus eliminating any random input and output to the data space.
A weighted measure of the expected number of rows to process 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 the optimizer uses to gain more accurate estimates of the number of expected rows 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 can then be further refined by the estimate based on the key range. If an index exists whose left-most keys match columns used in row selection predicates, that index can be used 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 and is done without actually accessing the keys. Full indexes over columns used in selection predicates can significantly help optimization.
Page faults and the number of rows processed are dependent on the type of access the optimizer chooses. Refer to Data access on DB2 UDB for AS/400: data access paths and methods for more information on access methods.