How do I get a mysql query to use a specific index?
1 answer
If the index is appropriate, it will be used without explicitly specifying it.
Given what you are using SELECT *
, I would not expect your index to be used (even if the INDEX hint had the correct syntax). The choice depends on the heuristic of the query optimizer.
The correct syntax is:
SELECT * FROM orders USE INDEX(idx);
Reference: Pointing Hints
Also note : 99 times out of 100, specifying an index hint should not be done. Let the optimizer do its job.
+1
source to share