Every so often you need to perform sort results retrieved from MySQL when your WHERE clause goes beyound col=const values which would allow MySQL to still use second portion of the index for the order by. Ranges as well as IN lists make this optimization impossible, not even speaking about index merge optimization. Lets look at this example:
PLAIN TEXT SQL:
- CREATE TABLE `utest` (
- `c1` int(10) UNSIGNED NOT NULL,
- `c2` int(10) UNSIGNED NOT NULL,
- `ord` int(10) UNSIGNED NOT NULL,
- KEY `c1` (`c1`,`ord`),
- KEY `c2` (`c2`,`ord`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1
- mysql> EXPLAIN SELECT * FROM utest WHERE c1=5 OR c2=5 ORDER BY ord DESC LIMIT 10 \G
- *************************** 1. row ***************************
- …