Use the access-method directive to specify the manner in which the optimizer should search the tables.
Access-Method Directives: (1) |--+-+--------INDEX_ALL-+-(-| Table Reference |-+-----------------+-+--> | '-INDEX------------' | .-,-----------. | | | | V | | | | '---+-index---+-+-' | | '-"index"-' | | .-,-----------. | | V | | +-AVOID_INDEX--(-| Table Reference |----+-index---+-+------------+ | '-"index"-' | '-+-FULL-------+--(-| Table Reference |--------------------------' '-AVOID_FULL-' >--)--+----------+----------------------------------------------| '-comments-' Table Reference: |--+-alias---+--------------------------------------------------| +-synonym-+ '-table---'
Element | Description | Restrictions | Syntax |
---|---|---|---|
alias | Temporary alternative table name declared in the FROM clause | If an alias is declared, it must be used in the optimizer directive | Identifier |
comments | Text that documents the optimizer directive | Must be outside the parenthesis but inside the comment symbols | Character string |
index | Index for which to specify a query plan directive | Must exist. With AVOID _INDEX, at least one index is required | Database Object Name |
synonym, table | Synonym or table in a query for which to specify a directive | Synonym and the table to which it points must exist | Database Object Name |
Use commas or blank spaces to separate elements within the parentheses.
The following table describes each of the access-method directives and indicates how it affects the query plan of the optimize.
Both the AVOID_FULL and INDEX keywords specify that the optimizer should avoid a full scan of a table. It is recommended, however, that you use the AVOID_FULL keyword to specify the intent to avoid a full scan on the table. In addition to specifying that the optimizer not use a full-table scan, the negative directive allows the optimizer to use indexes that are created after the access-method directive is specified.
In general, you can specify only one access-method directive per table. You can, however, specify both AVOID_FULL and AVOID_INDEX for the same table. When you specify both of these access-method directives, the optimizer avoids performing a full scan of the table and it avoids using the specified index or indexes.
This combination of negative directives allows the optimizer to use indexes that are created after the access-method directives are specified.
Suppose that you have a table named emp that contains the following indexes: loc_no, dept_no, and job_no. When you perform a SELECT that uses the table in the FROM clause, you might direct the optimizer to access the table in one of the following ways:
SELECT {+INDEX(emp dept_no)}
In this example the access-method directive forces the optimizer to scan the index on the dept_no column.
SELECT {+AVOID_INDEX(emp loc_no, job_no), AVOID_FULL(emp)}
This example includes multiple access-method directives. These access-method directives also force the optimizer to scan the index on the dept_no column. If a new index, emp_no is created for table emp, however, the optimizer can consider it.