I have this query:
SELECT * FROM article
WHERE (state = 2 OR state = 3) AND category_id = 100
ORDER BY mod_date DESC
And I have defined this index:
category_id_idx:
state
category_id
mod_date
When I run the query with an EXPLAIN, it returns this:
id: 1
select_type: SIMPLE
table: article
type: range
possible_keys: category_id_idx
key: category_id_idx
key_len: 3
ref: (NULL)
rows: 4
Extra: Using where; Using filesort
So... it's using a filesort. But if I change the WHERE removing the OR and letting only one field, this way:
SELECT * FROM article
WHERE state = 2 AND category_id = 100
ORDER BY mod_date DESC
Then the EXPLAIN returns NO filesort:
id: 1
select_type: SIMPLE
table: article
type: ref
possible_keys: category_id_idx
key: category_id_idx
key_len: 3
ref: const,const
rows: 3
Extra: Using where
Anyone knows why? I need that OR, is there a workaround?