Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would LIKE be faster than =?

A co-worker recently ran into a situation where a query to look up security permissions was taking ~15 seconds to run using an = comparison on UserID (which is a UNIQUEIDENTIFIER). Needless to say, the users were less than impressed.

Out of frustration, my co-worker changed the = comparison to use a LIKE and the query sped up to under 1 second.

Without knowing anything about the data schema (I don't have access to the database or execution plans), what could potentially cause this change in performance?

(Broad and vague question, I know)

like image 863
Jeremiah Peschka Avatar asked Dec 03 '22 08:12

Jeremiah Peschka


1 Answers

It may have just been a poor execution plan that had been cached; Changing to the LIKE statement then just caused a new execution plan to be generated. The same speedup may have been noticed if the person had run sp_recompile on the table in question and then re-run the = query.

like image 106
Chris Shaffer Avatar answered Dec 28 '22 09:12

Chris Shaffer