The super dictionary of Oracle hints

When you work with Oracle, an important part of optimizing SQL query performance is understanding how to guide the optimizer toward certain execution plans. That is exactly what hints are for.

By adding hints directly to the query, we can influence the Cost Based Optimizer (CBO) to make better decisions in specific situations.


What are hints?

Hints are special instructions written as comments inside a SQL query that affect the execution plan Oracle chooses. The general format is:





SELECT /*+ HINT_EXEMPLO */ coluna1, coluna2
FROM tabela
WHERE condicao;

AND_EQUAL

APPEND

APPEND_VALUES

ALL_ROWS

BITMAP

CACHE / NOCACHE

CHOOSE

CLUSTER

CURSOR_SHARING_EXACT

CARDINALITY

DISTRIBUTE / DISTRIBUTE_JOIN

DRIVING_SITE

DYNAMIC_SAMPLING

EXPAND_GSET_TO_UNION

FACT / NO_FACT

FIRST_ROWS(n)

FULL

GATHER_PLAN_STATISTICS

HASH

HASH_AJ

HASH_SJ

INDEX

INDEX_ASC / INDEX_DESC

INDEX_COMBINE

INDEX_FFS

INDEX_JOIN

INDEX_SS / INDEX_SS_ASC / INDEX_SS_DESC

NO_INDEX / NO_INDEX_FFS / NO_INDEX_SS

INVISIBLE (NO_USE_INVISIBLE_INDEXES / USE_INVISIBLE_INDEXES)

LEADING

MERGE

MERGE_AJ

MONITOR / NO_MONITOR

NL_AJ / NL_SJ

NO_EXPAND

NO_MERGE

NO_PARALLEL / NOPARALLEL

NO_PARALLEL_INDEX

NO_PUSH_PRED / NO_PUSH_SUBQ

NO_QUERY_TRANSFORMATION

NO_REWRITE / NOREWRITE

NO_STAR_TRANSFORMATION

NO_USE_HASH / NO_USE_MERGE / NO_USE_NL

NOCACHE

NOAPPEND

OPT_PARAM

ORDERED

ORDERED_PREDICATES

PARALLEL

PQ_DISTRIBUTE

PUSH_PRED / PUSH_SUBQ

QB_NAME

REWRITE

RESULT_CACHE / NO_RESULT_CACHE

ROWID

RULE

SPREAD_MIN_ANALYSIS

STAR

STAR_TRANSFORMATION

SWAP_JOIN_INPUTS

SWAP_JOIN_INPUTS_AJ

UNNEST / NO_UNNEST

USE_SEMI

USE_CONCAT

USE_ANTI

USE_HASH / USE_MERGE / USE_NL


A hint about hints..

  1. Oracle version: Some hints appeared or were removed in specific releases. Always check the documentation for your exact version (10g, 11g, 12c, 18c, 19c, 21c, etc.).
  2. Exact syntax: A simple spelling mistake (for example, forgetting the “+” in /*+ ... */, or writing INDEXS instead of INDEX) makes Oracle ignore the hint entirely.
  3. Up-to-date statistics: The Cost Based Optimizer (CBO) works best with consistent table and index statistics. Without them, even hints can produce inconsistent results.
  4. Analysis tools:
    • Use EXPLAIN PLAN and DBMS_XPLAN.DISPLAY (or DBMS_XPLAN.DISPLAY_CURSOR) to check whether the hint was applied and what the execution plan was.
    • Also check columns such as NOTE, which can indicate an “unrecognized hint” or “hint ignored”.
  5. Relevance:
    • Some hints (especially those marked dep. or deprecated) may have no effect.
    • Many old hints have been replaced by automatic CBO improvements in recent releases.
  6. A/B testing: Always compare the execution plan with and without the hint. Sometimes the default optimizer can do better than forcing a specific path.
  7. Official documentation: See the “Hints” chapter of the Oracle Database SQL Tuning Guide for your release.

Happy querying and happy tuning!

Leave a Reply

Your email address will not be published. Required fields are marked *