title: My simple MySql query doesn't use index
body: <p>I have a very simple query:</p>
  
  <pre><code>  SELECT   comments.*
    FROM comments 
    WHERE comments.imageid=46
  </code></pre>
  
  <p>And this is my table:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `comments` (
    `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
    `imageid` int(10) unsigned NOT NULL DEFAULT '0',
    `uid` bigint(20) unsigned NOT NULL DEFAULT '0',
    `content` text CHARACTER SET utf8,
    `adate` datetime DEFAULT NULL,
    `ip` int(10) unsigned DEFAULT NULL,
    PRIMARY KEY (`id`),
    KEY `ids` (`imageid`) USING BTREE,
    KEY `dt` (`adate`) USING BTREE
  ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;
  </code></pre>
  
  <p>But MySql can't use index on this simple query. here is the explain result:</p>
  
  <pre><code>id  select_type     table   type    possible_keys   key     key_len     ref     rows    filtered    Extra
  1   SIMPLE  comments    ALL     ids     NULL    NULL    NULL    4   75.00   Using where
  </code></pre>
  
  <p>while I change the query to this, Mysql can use index. Why? :</p>
  
  <pre><code>  SELECT   comments.id
    FROM comments 
    WHERE comments.imageid=46
  </code></pre>
  
  <p>here is the explain:</p>
  
  <pre><code>id  select_type     table   type    possible_keys   key     key_len     ref     rows    filtered    Extra
  1   SIMPLE  comments    ref     ids     ids     4   const   4   100.00  Using index
  </code></pre>