title: Very simple mysql query not using index
body: <p>Sorting of my mySQL table does not use the index and I don't know why.</p>
  
  <p>I've got:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `test` (
    `a` int(11) NOT NULL,
    `b` int(11) NOT NULL,
    KEY `kk` (`a`)
  ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
  </code></pre>
  
  <p>and this:</p>
  
  <pre><code>EXPLAIN SELECT * 
  FROM test
  ORDER BY a
  </code></pre>
  
  <p>as well as this</p>
  
  <pre><code>EXPLAIN SELECT * 
  FROM test
  USE INDEX ( kk ) 
  ORDER BY a
  </code></pre>
  
  <p>gives me this:</p>
  
  <pre><code>id select_type table type possible_keys key  key_len ref  rows  Extra
  1  SIMPLE      test  ALL  NULL          NULL NULL    NULL 10009 Using filesort
  </code></pre>
  
  <p>I'd like not to see this filesort, and use the key kk to sort my table. What am I doing wrong?</p>
  
  <hr>
  
  <p>Thank you for your posts guys, they answer my question! However, now I do not undestand what is meant by "table scan" and "filesort"? Even if I am selecting all fields and all rows of a table, isn't it faster to sort that table by one column by walking in O(n) the internal tree of the index of that column (and then looking up in the table file the extra columns requested, in O(1) for each row => the index file stores each row's physical position in the table file, or?), than to sort e.g. by quick sort in O(n * log n) the (potentially) randomly stored rows in the table file, without touching the index? I guess my understanding of how indexes work in mySQL is wrong.</p>