List:General Discussion« Previous MessageNext Message »
From:Colin Martin Date:October 25 2007 10:20am
Subject:Index usage for simple query
View as plain text  
Hi there,

Can someone please explain why when the query below uses one constant in 
the WHERE clause, MySQL decides to use the index on the 'source' column, 
and why in the second query where there are two constants, it decides 
not to?

Is there a way to get MySQL to use the index for the second query?

mysql> explain select * from data_total where source=8;

| id | select_type | table      | type | possible_keys | key    |
|  1 | SIMPLE      | data_total | ref  | source        | source |


mysql> explain select * from data_total where (source=8 or source=9);

| id | select_type | table      | type | possible_keys | key  |
|  1 | SIMPLE      | data_total | ALL  | source        | NULL |

(Output chopped for better formatting)

Thanks,

Colin Martin
Thread
Index usage for simple queryColin Martin25 Oct
  • Re: Index usage for simple queryBaron Schwartz25 Oct
    • Re: Index usage for simple queryColin Martin25 Oct
      • Re: Index usage for simple queryBaron Schwartz25 Oct
        • Re: Index usage for simple queryJoerg Bruehe25 Oct
          • Re: Index usage for simple queryBaron Schwartz25 Oct