Optimizing the MySQL IN() Comparison Operations Which Include the Indexed Field – MySQL Diary
A 2010 MySQL tuning tip: when a query filters on an indexed column with IN() and also uses ORDER BY ... LIMIT, MySQL evaluates each IN value fully and unlimited before merging and trimming the results, which gets expensive on large tables. The fix is to rewrite the IN as a UNION ALL of per-value subqueries, each with its own ORDER BY and LIMIT, then sort and limit the combined result. The example uses a composite index on (b, c, a) with FORCE INDEX. Side notes: when selecting many columns, fetch only the primary key first and join back for the rest, and replacing IN with OR doesn't help.