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

Example analysis of MySQL startup and connection methods

Table of contents How to start mysqld Method 1: m...

Implementation of Nginx forwarding matching rules

1. Regular expression matching ~ for case-sensiti...

Solution to Linux QT Kit missing and Version empty problem

Currently encountering such a problem My situatio...

jQuery uses the canvas tag to draw the verification code

The <canvas> element is designed for client...

Example of how to increase swap in CentOS7 system

Preface Swap is a special file (or partition) loc...

How to use firewall iptables strategy to forward ports on Linux servers

Forwarding between two different servers Enable p...

Discussion on more reasonable creation rules for MySQL string indexes

Preface Regarding the use of MySQL indexes, we ha...

JavaScript offsetParent case study

1. Definition of offsetParent: offsetParent is th...

HTML Nine-grid Layout Implementation Method

Diversifying website layouts is our front-end spe...

How to use Tencent slider verification code in Vue3+Vue-cli4 project

Introduction: Compared with traditional image ver...

How to use linux commands to convert and splice audio formats

Install FFmpeg flac eric@ray:~$ sudo apt install ...

Using js to achieve waterfall effect

This article example shares the specific code of ...

HTML table markup tutorial (37): background image attribute BACKGROUND

Set the background image for the table header. Yo...

Detailed explanation of hosts file configuration on Linux server

Linux server hosts file configuration The hosts f...

Use of Linux passwd command

1. Command Introduction The passwd command is use...