Detailed explanation of special phenomena examples of sleep function in MySQL

Detailed explanation of special phenomena examples of sleep function in MySQL

Preface

The sleep system function in MySQL has few practical application scenarios and is generally used for experimental testing. Yesterday, when testing, I accidentally discovered a special phenomenon of the sleep function. If the sleep function is used in a query statement, the sleep time is related to the records returned.

As shown in the following test:

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) 

Test summary:

If, select *, sleep(n) from table, if the table record is empty, there will be no sleep. If the table record is one, then the sleep time is 1*n. If the table record is 2, then the sleep time is: 2*n ............ and so on.

In the official documentation, 12.24 Miscellaneous Functions does not mention this phenomenon, and I really don't know how to explain this situation. I speculated on several scenarios, but all of them were denied. Let me record this issue for now.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Solution to the MySQL Sleep Connection Excessive Problem
  • Case and solution of mysql reading failure caused by using sleep in PHP

<<:  Tutorial on using portainer to connect to remote docker

>>:  js and jquery to achieve tab status bar switching effect

Recommend

Attributes in vue v-for loop object

Table of contents 1. Values ​​within loop objects...

Analysis of HTTP interface testing process based on postman

I accidentally discovered a great artificial inte...

How to add links to FLASH in HTML and make it compatible with all major browsers

Look at the code first Copy code The code is as fo...

Solve the problem of spring boot + jar packaging deployment tomcat 404 error

1. Spring boot does not support jsp jar package, ...

Record a troubleshooting record of high CPU usage of Tomcat process

This article mainly records a tomcat process, and...

7 skills that great graphic designers need to master

1》Be good at web design 2》Know how to design web p...

The most comprehensive collection of front-end interview questions

HTML+CSS 1. Understanding and knowledge of WEB st...

Steps for Vue3 to use mitt for component communication

Table of contents 1. Installation 2. Import into ...

How to use a field in one table to update a field in another table in MySQL

1. Modify 1 column update student s, city c set s...

Essential conditional query statements for MySQL database

Table of contents 1. Basic grammar 2. Filter by c...

JavaScript clicks the button to generate a 4-digit random verification code

This article example shares the specific code of ...