Does using the in
operator affect the use of indexes? For example, is it possible for WHERE id IN (10)
to cause the optimizer to ignore an index?
Specifically, I'm trying to understand this answer from StackOverflow. The question asks why an index is not being utilized (in MySQL), and the answer suggests that it could be due to the use of in
with only one value. Eg WHERE id IN (10)
might get the index ignored, while WHERE id=10
would be fine.
I've briefly looked around on Google, and skimmed through some MySQL docs, but I can't find any reference to in
affecting the optimizer's decision to use an index. Neither with a single value, nor multiple values.
Assuming that the IN
values are the same datatype as the column they are comparing, can they affect the index usage?
The question that I linked to was for MySQL, but I work in other DBs, so I'd be interested in knowing if this is a universal thing to note about indexes, or if it's a quirk with MySQL.