Mysql 可以缓存对具有相同参数的相同函数的调用吗 [英] Can Mysql cache calls to same function with same arguments

查看:48
本文介绍了Mysql 可以缓存对具有相同参数的相同函数的调用吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如我有这个条件

WHERE f1=CONCAT(v1,v2) OR f2=CONCAT(v1,v2) -- /*...

其中 v1,v1 是静态的,那么 Mysql 必须在第一次调用后缓存 concat 的结果.如果 v1 是字段,那么 Mysql 必须在第一次调用后缓存 concat 的结果,但仅限于当前行.

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.

那么,Mysql 这样做了吗?

So, Mysql doing this?

推荐答案

不,MySQL 不缓存函数调用.

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.

但是,您可以使用@variables 自己进行缓存.同样,您不会获得太多速度(如果有的话).(但是,您可能会在代码中获得简单性.)

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.)

这篇关于Mysql 可以缓存对具有相同参数的相同函数的调用吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆