MySQL: how to index an "OR" clause
Posted
by JoséMi
on Stack Overflow
See other posts from Stack Overflow
or by JoséMi
Published on 2010-05-13T19:09:47Z
Indexed on
2010/05/13
19:14 UTC
Read the original article
Hit count: 157
I'm executing the following query
SELECT COUNT(*) FROM table WHERE field1='value' AND (field2 >= 1000 OR field3 >= 2000)
There is one index over field1 and another composited over field2&field3.
I see MySQL always selects the field1 index and then makes a join using the other two fields which is quite bad because it needs to join 146.000 rows.
Suggestions on how to improve this? Thanks
© Stack Overflow or respective owner