CodeClerks

MySQL: WHERE LIKE '%%' is faster than WHERE =



Write the reason you're deleting this FAQ

MySQL: WHERE LIKE '%%' is faster than WHERE =

I was optimizing some queries today and I discovered that WHERE LIKE %% is much faster than WHERE = on a text based row. Here is an example of what I mean:

0.002 second execution time:

WHERE tbl LIKE '%joe%'


6.8 second execution time:
WHERE tbl='joe'


I have no idea why and it didn't make much sense if MySQL had to search for a value vs. finding an exact. It would seem an exact value would be faster than a searched like value.

Anyone care to explain why?

Comments

Please login or sign up to leave a comment

Join