I have a query that goes something like this:
SELECT t1, t2,
IF(MATCH(t2) AGAINST ('input*' IN BOOLEAN MODE), 10, 0) AS matches,
IF(t2 LIKE '%input%', 2, 0) AS similar
FROM tbl
WHERE t2 LIKE '%input%'
ORDER BY (matches + similar) DESC
LIMIT 5
The query works fine, but the part I’m concerned about is whether or not MySQL is checking whether t2 is LIKE ‘%input%’ twice, or if it caches the first result (which would be cool!).
Thanks
Sorry, it does not.
As a poor man’s test, consider:
While one can argue that this is a special case, since we’re invoking a stored routine, as opposed to built-in function, there is no difference at the moment. Everything is re-evaluated.
This may change in the future — there’s nothing to strictly prevent this optimization from happening on well known, deterministic functions. But sometimes this may be hard to diagnose by the optimizer.