SyntaxStudy
Sign Up
MySQL Advanced 4 min read

Query Hints

Query Hints

MySQL hints let you override the optimizer's choices. Use USE INDEX, FORCE INDEX, or STRAIGHT_JOIN to guide the optimizer when it makes poor decisions.

Example
-- Force a specific index
SELECT * FROM orders
USE INDEX (idx_status)
WHERE status = 'pending';

-- Force join order
SELECT STRAIGHT_JOIN o.id, c.name
FROM orders o
JOIN customers c ON c.id = o.customer_id;
Pro Tip

Use hints as a last resort — optimizer fixes or schema changes are usually better.