As far as I know, mysql doesn’t use index if using IN(1, 2…n) queries. Am I wrong? Or is there anything I could do to make mysql use it? I don’t mean IN() subquery optimization, because this is clearly explained in the manual.
Example (assuming there is an index on all fields, named index_abc):
WHERE a = 1 AND b = 2 AND c = 3 – then it uses index_abc
WHERE a = 2 AND b IN (2, 4, 5) AND C = 3 – then it doesn’t
Thanks in advance for your help.
What determines where the values in your
INexpression come from? Odds are it’s either user input, or something that should be in a table somewhere. Examples of things that should be in a table include hard-coded lookup values. Even user input could first be inserted in a table somewhere. Then you can use aJOINrather than anINand your indexes will work just fine.