mluebke mluebke - 2 months ago 12
MySQL Question

Using LIKE vs. = for exact string match

First off, I recognize the differences between the two:

- Like makes available the wildcards % and _

- significant trailing whitespace

- colation issues

All other things being equal, for an exact string match which is more efficient:

SELECT field WHERE 'a' = 'a';


Or:

SELECT field WHERE 'a' LIKE 'a';


Or: Is the difference so insignificant that it doesn't matter?

Answer Source

I would say that the = comparator would be faster. The lexical doesn't send the comparison to another lexical system to do general matches. Instead the engine is able to just match or move on. Our db at work has millions of rows and an = is always faster.