Can Mysql cache calls to same function with same arguments

☆樱花仙子☆ 提交于 2021-02-19 05:43:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!