The order in which the conditions are placed may matter due to a MySQL short circuit. Here is an attempt to prove it:
http://rextester.com/HJGN96158
The following queries are executed here:
SELECT myint FROM mytable WHERE myint >= 3 AND myslowfunction('query #1', myint) = 1; SELECT myint FROM mytable WHERE myslowfunction('query #2', myint) = 1 AND myint >= 3;
The only difference between them is the order of the operands in the AND condition.
myslowfunction intentionally sleeps for a second and has the side effect of adding an entry to the log table every time it starts. Here are the results of what is recorded during the execution of the above two queries:
myslowfunction called for query #1 with value 3 myslowfunction called for query #1 with value 4 myslowfunction called for query #2 with value 1 myslowfunction called for query #2 with value 2 myslowfunction called for query #2 with value 3 myslowfunction called for query #2 with value 4
The above shows that a slow function is executed more times when it appears on the left side of the AND condition, when the other operand is not always false (due to a short circuit).
From this, I would advise putting the status = 1 check before checking LIKE as (pointers to the side), most likely, it will be evaluated faster.
source share