Is there any performance difference between the two following queries:
SELECT foo,bar FROM table WHERE id IN (1,2,3);
and
SELECT foo,bar FROM table WHERE id = 1 OR id = 2 OR id = 3;
I’m sure the difference in negligible in a small example like this, but what about when the number of valid IDs is much larger?
The optimizer is more likely to be able to optimize
WHERE id IN (1,2,3)thanid = 1 OR id = 2 OR id = 3. I also think that usingINis more readable here.Use
WHERE id IN (1,2,3).