Compare an index hint with an unrestricted plan

Create a regular index, flush the table, and compare EXPLAIN with and without a hint. Hints influence plan selection; they do not change the query answer.

CREATE DATABASE cookbook_hint;
CREATE TABLE cookbook_hint.items(
  id INT PRIMARY KEY, category INT, amount INT,
  KEY idx_category_id(category,id));
INSERT INTO cookbook_hint.items VALUES(1,1,10),(2,2,20),(3,2,30);
SELECT MO_CTL('dn','flush','cookbook_hint.items');
SELECT SLEEP(1);
EXPLAIN SELECT id FROM cookbook_hint.items USE INDEX(idx_category_id)
WHERE category=2 ORDER BY id;
EXPLAIN SELECT id FROM cookbook_hint.items USE INDEX()
WHERE category=2 ORDER BY id;
SELECT id FROM cookbook_hint.items USE INDEX(idx_category_id)
WHERE category=2 ORDER BY id;
SELECT id FROM cookbook_hint.items USE INDEX()
WHERE category=2 ORDER BY id;
DROP DATABASE cookbook_hint;

Both result queries return IDs 2,3. Inspect whether the hinted plan references idx_category_id; the unrestricted plan can differ by table size and statistics. Remove hints after diagnosis unless measurement on production-sized data justifies them. See the v4.2.4 source test.