How To Use Hints in Oracle SQL For Performance
How To Use Hints in Oracle SQL For Performance
How To Use Hints in Oracle SQL For Performance
The CHOOSE hint causes the optimizer to choose between the rule-
based approach and the cost-based approach for a SQL statement
CHOOSE
based on the presence of statistics for the tables accessed by the
statement
The ROWID hint explicitly chooses a table scan by ROWID for the
specified table. The syntax of the ROWID hint is ROWID(table) where
ROWID table specifies the name or alias of the table on which the table
access by ROWID is to be performed. (This hint depricated in Oracle
10g)
HASH The HASH hint explicitly chooses a hash scan to access the specified
table. The syntax of the HASH hint is HASH(table) where table
specifies the name or alias of the table to be accessed by a hash
1
2
scan.
The INDEX hint explicitly chooses an index scan for the specified
table. The syntax of the INDEX hint is INDEX(table index) where:table
INDEX specifies the name or alias of the table associated with the index to be
scanned and index specifies an index on which an index scan is to be
performed. This hint may optionally specify one or more indexes:
This hint causes a fast full index scan to be performed rather than a
INDEX_FFS
full table.
NO_INDEX_FFS Do not use fast full index scan (from Oracle 10g)
INDEX_SS Exclude range scan from query plan (from Oracle 10g)
INDEX_SS_ASC Exclude range scan from query plan (from Oracle 10g)
INDEX_SS_DESC Exclude range scan from query plan (from Oracle 10g)
2
3
The FACT hint indicated that the table should be considered as a fact
FACT
table. This is used in the context of the star transformation.
NO_UNNEST Use of the NO_UNNEST hint turns off unnesting for specific subquery
3
4
blocks.
The ORDERED hint causes Oracle to join tables in the order in which
they appear in the FROM clause. If you omit the ORDERED hint from
a SQL statement performing a join , the optimizer chooses the order in
which to join the tables. You may want to use the ORDERED hint to
ORDERED
specify a join order if you know something about the number of rows
selected from each table that the optimizer does not. Such information
would allow you to choose an inner and outer table better than the
optimizer could.
The USE_MERGE hint causes Oracle to join each specified table with
another row source with a sort-merge join. The syntax of the
USE_MERGE USE_MERGE hint is USE_MERGE(table table) where table is a table
to be joined to the row source resulting from joining the previous
tables in the join order using a sort-merge join.
The USE_HASH hint causes Oracle to join each specified table with
another row source with a hash join. The syntax of the USE_HASH
USE_HASH hint is USE_HASH(table table) where table is a table to be joined to
the row source resulting from joining the previous tables in the join
order using a hash join.
PARALLEL The PARALLEL hint allows you to specify the desired number of
concurrent query servers that can be used for the query. The syntax is
PARALLEL(table number number). The PARALLEL hint must use the
table alias if an alias is specified in the query. The PARALLEL hint can
then take two values separated by commas after the table name. The
4
5
first value specifies the degree of parallelism for the given table, the
second value specifies how the table is to be split among the
instances of a parallel server. Specifying DEFAULT or no value
signifies the query coordinator should examine the settings of the
initialization parameters (described in a later section) to determine the
default degree of parallelism.
Additional Hints
When the APPEND hint is used with the INSERT statement, data is
appended to the table. Existing free space in the block is not used. If a
APPEND table or an index is specified with nologging, this hint applied with an
insert statement produces a direct path insert which reduces
generation of redo.
The CACHE hint specifies that the blocks retrieved for the table in the
hint are placed at the most recently used end of the LRU list in the
CACHE buffer cache when a full table scan is performed. This option is useful
for small lookup tables. In the following example, the CACHE hint
overrides the table default caching specification.
The NOCACHE hint specifies that the blocks retrieved for this table
are placed at the least recently used end of the LRU list in the buffer
NOCACHE
cache when a full table scan is performed. This is the normal behavior
of blocks in the buffer cache.
PUSH_PRED The PUSH_PRED hint forces pushing of a join predicate into the view.
5
6
This hint omits some of the compile time optimizations of the rules,
mainly detailed dependency graph analysis, on spreadsheets. Some
SPREAD_MIN_ANALYSIS optimizations such as creating filters to selectively populate
spreadsheet access structures and limited rule pruning are still used.
(from Oracle 10g)
The STAR hint forces the large table to be joined last using a nested
STAR loops join on the index. The optimizer will consider different
permutations of the small tables. (depricated in Oracle 10g)
HASH_SJ Use a Hash Anti-Join to evaluate a NOT IN sub-query. Use this hint in
the sub-query, not in the main query. Use this when your high volume
NOT IN sub-query is using a FILTER or NESTED LOOPS join. Try
6
7