title: Optimizing MySql query (IN) to avoid using “Using filesort”
body: <p>I need your help to optimize the query to avoid using "Using filesort". The query is:</p>
  
  <pre><code>SELECT name
  FROM actor
  WHERE actor_id IN (3333,1452,2587,3003,3044,3524,3700,7087,7088)
  ORDER BY name ASC
  </code></pre>
  
  <p>The Explain results:</p>
  
  <pre><code>1   SIMPLE  actor   range   PRIMARY PRIMARY 2       9   Using where; Using filesort
  </code></pre>
  
  <p>============================================================</p>
  
  <h1>SQL Fiddle <strong><a href="http://sqlfiddle.com/#!2/50c4d/1/0" rel="nofollow">http://sqlfiddle.com/#!2/50c4d/1/0</a></strong></h1>
  
  <p>Table:</p>
  
  <pre><code>CREATE TABLE `actor` (
  `actor_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(45) NOT NULL,  
  PRIMARY KEY (`actor_id`),
  UNIQUE KEY `name_UNIQUE` (`name`)
  ) ENGINE=InnoDB;
  </code></pre>
  
  <p>Sample data:</p>
  
  <pre><code>INSERT INTO `actor` VALUES (7087, 'Brill');
  INSERT INTO `actor` VALUES (3333, 'Rey');
  INSERT INTO `actor` VALUES (7088, 'Graves');
  INSERT INTO `actor` VALUES (1452, 'Phoenix');
  INSERT INTO `actor` VALUES (2587, 'Segal');
  INSERT INTO `actor` VALUES (3003, 'Taylor');
  INSERT INTO `actor` VALUES (3044, 'Daniels');
  INSERT INTO `actor` VALUES (3524, 'Michaels');
  INSERT INTO `actor` VALUES (3700, 'Tryme');
  </code></pre>
  
  <p>Index:</p>
  
  <pre><code>ADD INDEX idx_test (actor_id, name) -&gt; EXTRA: Using where; Using index; Using filesort
  </code></pre>