Directives embedded in a SQL statement that instruct the query optimizer to use a specific join order, index, or execution strategy.
Directives embedded in comments that suggest a specific execution plan to the optimizer (e.g., FORCE ORDER, USE INDEX). Useful when the planner makes poor choices, but considered a code smell -- better to fix statistics or indexes. MySQL, SQL Server, and Oracle support hints.
| Database System | Support Status | Since Version | Notes |
|---|---|---|---|
| MySQL | ✓ Supported | 5.0 | Index hints: USE INDEX, FORCE INDEX, IGNORE INDEX in the FROM clause. Optimizer hints (/*+ ... */ comment syntax) added in 8.0, including JOIN_ORDER, NO_MERGE, MAX_EXECUTION_TIME, and more. |
| PostgreSQL | ✓ Supported | 7.4 | No dedicated hint syntax. Hints are applied indirectly via session-level planner configuration: enable_indexscan, enable_seqscan, enable_hashjoin, etc. The pg_hint_plan extension provides Oracle/SQL Server-style inline hints and is widely used in production. |
| SQL Server | ✓ Supported | 2000 | Rich hint vocabulary: table hints (WITH (NOLOCK), WITH (INDEX(...))), join hints (LOOP, HASH, MERGE in FROM clause), and query hints (OPTION clause: OPTION (RECOMPILE), OPTION (MAXDOP 1), OPTION (HASH JOIN)). NOLOCK is commonly overused — it produces dirty reads. |
| Oracle | ✓ Supported | 7 | Hints use the /*+ ... */ comment syntax. Extensive vocabulary including INDEX, NO_INDEX, FULL, LEADING, USE_NL, USE_HASH, PARALLEL, APPEND, and many more. Oracle's hint system is the most mature and granular among these engines. |
| SQLite | ✗ Not Supported | — | No query hint syntax. The INDEXED BY clause forces use of a named index but is not a general-purpose hint system. Use EXPLAIN QUERY PLAN to inspect the chosen strategy. |
Query hints are a last resort — the right response to a bad query plan is usually better statistics, updated indexes, or a query rewrite. That said, hints are invaluable when a known-good plan is being abandoned due to stale stats or parameter sniffing. Oracle and SQL Server have the most mature hint systems with the widest vocabulary. PostgreSQL deliberately omits inline hints to keep the optimizer honest, but the pg_hint_plan extension fills the gap for production use. MySQL's FORCE INDEX is deceptively aggressive — it tells the optimizer to use that index or do a full table scan, with no middle ground. SQL Server's WITH (NOLOCK) is the most commonly misused hint: it eliminates lock waits at the cost of dirty reads, phantom reads, and even rows appearing twice or not at all during a scan — not appropriate for financial or transactional queries.
Index hints: USE INDEX, FORCE INDEX, IGNORE INDEX in the FROM clause. Optimizer hints (/*+ ... */ comment syntax) added in 8.0, including JOIN_ORDER, NO_MERGE, MAX_EXECUTION_TIME, and more.
No dedicated hint syntax. Hints are applied indirectly via session-level planner configuration: enable_indexscan, enable_seqscan, enable_hashjoin, etc. The pg_hint_plan extension provides Oracle/SQL Server-style inline hints and is widely used in production.
Rich hint vocabulary: table hints (WITH (NOLOCK), WITH (INDEX(...))), join hints (LOOP, HASH, MERGE in FROM clause), and query hints (OPTION clause: OPTION (RECOMPILE), OPTION (MAXDOP 1), OPTION (HASH JOIN)). NOLOCK is commonly overused — it produces dirty reads.
Hints use the /*+ ... */ comment syntax. Extensive vocabulary including INDEX, NO_INDEX, FULL, LEADING, USE_NL, USE_HASH, PARALLEL, APPEND, and many more. Oracle's hint system is the most mature and granular among these engines.
No query hint syntax. The INDEXED BY clause forces use of a named index but is not a general-purpose hint system. Use EXPLAIN QUERY PLAN to inspect the chosen strategy.