MySQL Performance - "IN" Clause vs. Equals (=) for a Single Value [duplicate]

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 <code>= 1</code>


EXPLAIN for a query with IN(1):

Explain for a query with <code>IN(1)</code>


EXPLAIN for a query with IN(1,2,3):

Explain for a query with <code>IN(1,2,3)</code>


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. :-)


There is no difference between the MySQL statements, and the MySQL optimiser will transform the IN to the = when IN is just one element. Don't bother.