Oracle Hints

/*+ ALL_ROWS */

Explicitly chooses the cost-based approach to optimize a statement block with a goal of best throughput (that is, minimum total resource consumption)

/*+ CHOOSE */

Causes the optimizer to choose between the rule-based approach and the cost-based approach for a SQL statement based on the presence of statistics for the tables accessed by the statement

/*+ FIRST_ROWS */

Explicitly chooses the cost-based approach to optimize a statement block with a goal of best response time (minimum resource usage to return first row). It will also force the optimizer to make use of index, if available. There are other versions of FIRST_ROWS hints. This hint is useful in an OLTP environment when the user cannot wait till the last row is fetched. This is mainly used in Java lookup screens. If there are some calculations then this hint should not be used.

Test your PL/SQL knowledge, Which code runs faster?
/*+ RULE */

Explicitly chooses rule-based optimization for a statement block

/*+ AND_EQUAL(table index) */

Explicitly chooses an execution plan that uses an access path that merges the scans on several single-column indexes

/*+ CLUSTER(table) */

Explicitly chooses a cluster scan to access the specified table

/*+ FULL(table) */

Explicitly chooses a full table scan for the specified table

/*+ HASH(table) */

Explicitly chooses a hash scan to access the specified table

/*+ HASH_AJ(table) */

Transforms a NOT IN sub query into a hash anti join to access the specified table

/*+ HASH_SJ (table) */

Transforms a NOT IN sub query into a hash anti-join to access the specified table

/*+ INDEX(table index) */

Explicitly chooses an index scan for the specified table

/*+ INDEX_ASC(table index) */

Explicitly chooses an ascending-range index scan for the specified table

/*+ INDEX_COMBINE(table index) */

If no indexes are given as arguments for the INDEX_COMBINE hint, the optimizer uses whatever Boolean combination of bitmap indexes has the best cost estimate. If particular indexes are given as arguments, the optimizer tries to use some Boolean combination of those particular bitmap indexes.

/*+ INDEX_DESC(table index) */

Explicitly chooses a descending-range index scan for the specified table

/*+ INDEX_FFS(table index) */

Causes a fast full index scan to be performed rather than a full table scan

/*+ MERGE_AJ (table) */

Transforms a NOT IN sub query into a merge anti-join to access the specified table

/*+ MERGE_SJ (table) */

Transforms a correlated EXISTS sub query into a merge semi-join to access the specified table

/*+ ROWID(table) */

Explicitly chooses a table scan by ROWID for the specified table

/*+ USE_CONCAT */

Forces combined OR conditions in the WHERE clause of a query to be transformed into a compound query using the

UNION ALL set operator

/*+ ORDERED */

Causes Oracle to join tables in the order in which they appear in the FROM clause

/*+ STAR */

Forces the large table to be joined using a nested-loop join on the index

/*+ DRIVING_SITE (table) */

Forces query execution to be done at a different site from that selected by Oracle

/*+ USE_HASH (table) */

Causes Oracle to join each specified table with another row source with a hash join

/*+ USE_MERGE (table) */

Causes Oracle to join each specified table with another row source with a sort-merge join

/*+ USE_NL (table) */

Causes Oracle to join each specified table to another row source with a nested-loops join using the specified table as the inner table

/*+ APPEND */ , /*+ NOAPPEND */

Specifies that data is simply appended (or not) to a table; existing free space is not used. Use these hints only following the INSERT keyword.

/*+ NOPARALLEL(table) */

Disables parallel scanning of a table, even if the table was created with a PARALLEL clause

/*+ PARALLEL(table, instances) */

This allows you to specify the desired number of concurrent slave processes that can be used for the operation. DELETE, INSERT, and UPDATE operations are considered for parallelization only if the session is in a PARALLEL DML enabled mode. (Use ALTER SESSION PARALLEL DML to enter this mode.)

/*+ PARALLEL_INDEX */

Allows you to parallelize fast full index scan for partitioned and non-partitioned indexes that have the PARALLEL attribute

/*+ NOPARALLEL_INDEX */

Overrides a PARALLEL attribute setting on an index

/*+ CACHE */

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 buffer cache when a full table scan is performed

/*+ NOCACHE */

Specifies that the blocks retrieved for this table are placed at the least recently used end of the LRU list in the buffer cache when a full table scan is performed

/*+ MERGE (table) */

Causes Oracle to evaluate complex views or sub queries before the surrounding query

/*+ NO_MERGE (table) */

Causes Oracle not to merge mergeable views

/*+ PUSH_JOIN_PRED (table) */

Causes the optimizer to evaluate, on a cost basis, whether or not to push individual join predicates into the view

/*+ NO_PUSH_JOIN_PRED (table) */

Prevents pushing of a join predicate into the view

/*+ PUSH_SUBQ */

Causes non merged sub queries to be evaluated at the earliest possible place in the execution plan

/*+ STAR_TRANSFORMATION */

Makes the optimizer use the best plan in which the transformation has been used.

7 comments :

  1. nice summary.. thanks

    ReplyDelete
  2. Thanks for providing the details about all the clauses and parameters that are present in Oracle. This post not only enhanced my knowledge but I got a chance to verify my understanding too. I even learnt so many new points from this article.

    ReplyDelete
  3. Hi I have a doubt for a particular case, lets say I am suppose to use the index hint in my query but I can do the same by altering the table & making that column indexed. Whats the diff?

    ReplyDelete
  4. Not all hints can be created as indexes. Say for ex: /*+ FULL(table) */ hint can be processed only if indexes are dropped from the table. In some cases full table scan also helps. The same way for testing purposes there is no good way rather than hints.

    ReplyDelete
  5. Thanks for giving an overview.

    ReplyDelete
  6. When to Use Hints and When not to use Hints?

    ReplyDelete