MySQL中的系統函式sleep,實際應用的場景不多,一般用來做實驗測驗,昨天在測驗的時候,意外發現sleep函式的一個特殊現象,如果在查詢陳述句中使用sleep函式,那么休眠的時間跟回傳的記錄有關,如下測驗所示:
mysql> create table test(id int);
Query OK, 0 rows affected (0.03 sec)mysql> select *, sleep(6) from test;
Empty set (0.00 sec)mysql> insert into test values(1);
Query OK, 1 row affected (0.00 sec)mysql> select * ,sleep(6) from test;
+------+----------+
| id | sleep(6) |
+------+----------+
| 1 | 0 |
+------+----------+
1 row in set (6.00 sec)
mysql> insert into test value(2);
Query OK, 1 row affected (0.01 sec)mysql> select * ,sleep(6) from test;
+------+----------+
| id | sleep(6) |
+------+----------+
| 1 | 0 |
| 2 | 0 |
+------+----------+
2 rows in set (12.00 sec)
![clip_image001[8] clip_image001[8]](https://img.uj5u.com/2020/09/24/98877240213461.png)
測驗總結:
如果,select *, sleep(n) from table, 如果表記錄為空,不會休眠,如果表記錄一條,那么休眠時間為1*n,如果表記錄為2,那休眠時間為:2*n ............依此類推,
官方檔案中,12.24 Miscellaneous Functions沒有提及這個現象,實在不知如何解釋這種情況,推測了幾種情況,都一一否定了,暫時先記錄一下這個問題,
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/115814.html
標籤:MySQL
下一篇:表查詢操作
