有没有办法停止在其中执行BENCHMARK功能?基本上,我希望做这样的事情:
SELECT BENCHMARK(1000000, if(somecondition, STOP_BENCHMARK_SOMEHOW, somequery))
这可能吗?
答案 0 :(得分:3)
我试图找出一种方法来抛出错误作为打破基准测试循环的一种方法,但它似乎将错误转化为警告,并继续循环。
mysql> SET SQL_MODE=ERROR_FOR_DIVISION_BY_ZERO;
mysql> SET @a:=0;
mysql> SELECT BENCHMARK(100, IF((@a:=@a+1)>10, 1/0, SLEEP(1));
1 row in set, 90 warnings (10.01 sec)
mysql> show warnings;
+---------+------+---------------+
| Level | Code | Message |
+---------+------+---------------+
| Warning | 1365 | Division by 0 |
| Warning | 1365 | Division by 0 |
| Warning | 1365 | Division by 0 |
| Warning | 1365 | Division by 0 |
| Warning | 1365 | Division by 0 |
| Warning | 1365 | Division by 0 |
| Warning | 1365 | Division by 0 |
| Warning | 1365 | Division by 0 |
| Warning | 1365 | Division by 0 |
| Warning | 1365 | Division by 0 |
. . .
循环变量@a
继续增加,表明基准测试已完成全部运行:
mysql> select @a;
+------+
| @a |
+------+
| 100 |
+------+
基准测试中的表达式必须是标量表达式,因此我们可以通过运行非标量子查询来停止基准测试。但这终止了基准,并没有给出时间结果。
mysql> SELECT BENCHMARK(100, if((@a:=@a+1)>10, (SELECT host FROM mysql.user), SLEEP(1)));
... about 10 seconds goes by ...
ERROR 1242 (21000): Subquery returns more than 1 row
我认为您必须使用真正的基准测试工具,而不是仅使用MySQL的内置BENCHMARK()
功能。