mluebke mluebke - 9 months ago 36
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';


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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download