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.
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.
-- 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;
Use hints as a last resort — optimizer fixes or schema changes are usually better.