要测量特定 MySQL 表达式或函数的速度,可以使用 BENCHMARK() 函数,通过 mysql 客户端程序调用。其语法为 BENCHMARK(。返回值总是零,但 mysql 会打印一行,大致显示语句执行所花费的时间。例如:To measure the speed of a specific MySQL expression or function,
invoke the loop_count,expr)BENCHMARK() function
using the mysql client program. Its syntax is
BENCHMARK(.
The return value is always zero, but mysql
prints a line displaying approximately how long the statement
took to execute. For example:loop_count,expr)
mysql> SELECT BENCHMARK(1000000,1+1);
+------------------------+
| BENCHMARK(1000000,1+1) |
+------------------------+
| 0 |
+------------------------+
1 row in set (0.32 sec)
这个结果是在一台 Pentium II 400MHz 系统上获得的。它显示 MySQL 在该系统上可以在 0.32 秒内执行 1,000,000 个简单的加法表达式。This result was obtained on a Pentium II 400MHz system. It shows that MySQL can execute 1,000,000 simple addition expressions in 0.32 seconds on that system.
内置的 MySQL 函数通常经过高度优化,但可能有一些例外。BENCHMARK() 是一个很好的工具,用于判断某些函数是否会影响你的查询性能。The built-in MySQL functions are typically highly optimized, but
there may be some exceptions.
BENCHMARK() is an excellent tool
for finding out if some function is a problem for your queries.