Why hints are ignored: aliases, inline views, global hints
A hint with a mistake raises no error; it is silently ignored. Look at why an alias must be used instead of the table name, at global hints that point from outside to a table inside an inline view, and at checking with the Hint Report.
SQL
Situation
A list of VIP customers' orders since June. Knowing that an NL join works well here (find only the 1,000 VIP customers first, then look up their orders through ORDERS_X1), hints were added. Yet the execution plan is still a hash join. No error is raised either.
Tables
| Table | Column | Type | Description |
|---|---|---|---|
CUSTOMERS | GRADE | VARCHAR2 | Grade (VIP 1%, 1,000 customers) |
ORDERS | CUST_ID, ORD_DT | Ordering customer, order date and time |
| Index | Columns |
|---|---|
CUSTOMERS_X1 | GRADE |
ORDERS_X1 | CUST_ID, ORD_DT |
① Hint written with table names
BEFORE · Specified by table name
SELECT /*+ LEADING(customers orders) USE_NL(orders) INDEX(orders orders_x1) */
c.cust_nm, o.ord_dt, o.amt
FROM orders o
JOIN customers c ON c.cust_id = o.cust_id
WHERE c.grade = 'VIP'
AND o.ord_dt >= DATE '2025-06-01'
② Hint written outside the inline view
BEFORE · Aliases inside the view specified from outside
SELECT /*+ LEADING(c o) USE_NL(o) INDEX(o orders_x1) */ v.cust_nm, v.ord_dt, v.amt
FROM (
SELECT /*+ NO_MERGE */ c.cust_nm, o.ord_dt, o.amt
FROM orders o
JOIN customers c ON c.cust_id = o.cust_id
WHERE c.grade = 'VIP'
AND o.ord_dt >= DATE '2025-06-01'
) v
After running, open the Raw tab below the result and look at the Hint Report below the execution plan.
Approach
1. First check whether the hint was applied
A hint is a comment, so a mistake raises no error. If the execution plan differs from the intent, look at the Hint Report (+HINT_REPORT of DBMS_XPLAN) first. Each hint shows as Used, Unused, or Unresolved (target not found).
2. Check the name the hint points to
A table in a hint is referenced by the name actually written in the FROM clause. If an alias was given, the alias is the only name of that table.
3. Check the query block the hint sits in
A hint can directly reference only tables inside the query block (a single SELECT) where it sits. Tables inside an inline view are not visible from the outer SELECT. Either put the hint inside the view or reference it from outside through the view (a global hint).
4. Check that the hints fit together
USE_NL(o) means "put o on the inner side of an NL join", so it must match the order set by LEADING. When one is ignored, the others often lose their meaning too.
Explanation
① Table name → alias
AFTER · Specified by alias
SELECT /*+ LEADING(c o) USE_NL(o) INDEX(o orders_x1) */
c.cust_nm, o.ord_dt, o.amt
FROM orders o
JOIN customers c ON c.cust_id = o.cust_id
WHERE c.grade = 'VIP'
AND o.ord_dt >= DATE '2025-06-01'
Why it got faster
- In Before #1, the Hint Report shows all three hints as
Unresolved. The FROM clause gives the aliasesoandc, so the namesordersandcustomersdo not exist in this query block. The execution plan is a hash join, with about 14,500 Buffers. - In After #1, all three hints are
Used. It finds the 1,000 VIPs throughCUSTOMERS_X1and, for each customer, looks up only the orders since June throughORDERS_X1. Buffers are about 4,900.
② Pointing inside the view with a global hint
AFTER · Global hint (view.alias)
SELECT /*+ LEADING(v.c v.o) USE_NL(v.o) INDEX(v.o orders_x1) */ v.cust_nm, v.ord_dt, v.amt
FROM (
SELECT /*+ NO_MERGE */ c.cust_nm, o.ord_dt, o.amt
FROM orders o
JOIN customers c ON c.cust_id = o.cust_id
WHERE c.grade = 'VIP'
AND o.ord_dt >= DATE '2025-06-01'
) v
Why it got faster
- In Before #2,
candoare invisible names in the outer SELECT (onlyvexists outside). The hints are ignored, and Buffers are about 14,500. - After #2 points to the tables inside the view as view alias.table alias, such as
v.candv.o. This is a global hint. Buffers are about 4,900, the same as After in ①. - If the view can be changed, the hint can go directly into the SELECT inside the view. A global hint is for when the view is shared and cannot be changed.
Why this is optimal
- It looks up only the orders since June for the 1,000 VIPs through the index, so it reads only in proportion to the result rows.
- Most of the remaining cost is the table access that reads order rows. Each customer's orders are scattered across the table, so each row reads a different block (clustering in scenario 14).
Variation: letting the view merge
TRY · Without NO_MERGE
SELECT /*+ LEADING(c o) USE_NL(o) INDEX(o orders_x1) */ v.cust_nm, v.ord_dt, v.amt
FROM (
SELECT c.cust_nm, o.ord_dt, o.amt
FROM orders o
JOIN customers c ON c.cust_id = o.cust_id
WHERE c.grade = 'VIP'
AND o.ord_dt >= DATE '2025-06-01'
) v
- When the view merges into the outer query (View Merging),
candomight seem visible from outside, but hints are resolved against the query blocks before transformation. So the hints are ignored here too, and Buffers are about 14,500. - Do not rely on optimizer transformations for a hint to apply; put it inside the view or point to it with a global hint.
Key points
- A hint raises no error when it is wrong. After adding a hint, always confirm it was applied with the Hint Report or the execution plan.
- If a table has an alias, use the alias in the hint too. A schema name (
tune.orders) must also match what is written in the FROM clause. - A hint points only inside the query block where it sits. Inside a view, point with a
view_alias.table_aliasglobal hint or@query_block_name(QB_NAME). - Differences by DB: Hint syntax is Oracle-specific. PostgreSQL has no hints (planner settings or the pg_hint_plan extension), and SQL Server uses
OPTION (...)and table hints.