问题
For example I have this condition
WHERE f1=CONCAT(v1,v2) OR f2=CONCAT(v1,v2) -- /*...
where v1,v1 are static, then Mysql must cache result of concat after first call. If v1 is field, then Mysql must cache result of concat after first call, but only for current row.
So, Mysql doing this?
回答1:
No, MySQL does not cache function calls.
Furthermore, such an optimization would not be worth doing. Note the tiny difference:
mysql> SELECT city, country, CONCAT(city, country) FROM cities LIMIT 263000,5
+----------+---------+-----------------------+
| city | country | CONCAT(city, country) |
+----------+---------+-----------------------+
| Kitanzi | cg | Kitanzicg |
| Masend | cg | Masendcg |
| Chilute | ao | Chiluteao |
| Khilule | ao | Khiluleao |
| Tchibuti | ao | Tchibutiao |
+----------+---------+-----------------------+
5 rows in set (0.10 sec)
mysql> SELECT city, country FROM cities LIMIT 263000, 5;
+----------+---------+
| city | country |
+----------+---------+
| Kitanzi | cg |
| Masend | cg |
| Chilute | ao |
| Khilule | ao |
| Tchibuti | ao |
+----------+---------+
5 rows in set (0.09 sec)
Fetching the rows is more costly than any function calls in the expressions.
You can, however, use @variables to do the caching yourself. Again, you won't gain much, if any, speed. (However, you might gain simplicity in your code.)
来源:https://stackoverflow.com/questions/32800131/can-mysql-cache-calls-to-same-function-with-same-arguments