Most of the other answers don't provide anything conclusive, just speculation. So, based on the good advice from @Namphibian's answer, I ran an EXPLAIN
on some queries similar to the ones in the OP.
The results are below:
EXPLAIN
for a query with = 1
:
EXPLAIN
for a query with IN(1)
:
EXPLAIN
for a query with IN(1,2,3)
:
As you can see, MySQL does optimize IN(1)
to be the same as = 1
in this sort of query. @mes's answer seems to indicate that this might not always be the case with more complex queries, however.
So, for those who were too lazy to run the EXPLAIN
themselves, now you know. And yes, you may want to run the EXPLAIN
on your own query to be sure that it is handled this way. :-)