Hi,

Colin Martin wrote:
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)

I'd need more info to know for sure, but I'm guessing you're using pre-MySQL 5 or MySQL is deciding it's cheaper to scan the table. If it's too slow, try using an IN(8, 9) clause instead and see if that helps. Or try turning the query into a UNION.

Baron

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to