Is MySQL's SLEEP() function a busy-wait? How to implement it?



No, MySQL sleep function is not busy-wait. Let us first create a table and implement the SLEEP() function −

mysql> create table DemoTable(FirstName varchar(100)); Query OK, 0 rows affected (0.57 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Adam'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('Bob'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.16 sec)

Display all records from the table using select statement. We have also set the SLEEP() function here −

mysql> select sleep(10),FirstName from DemoTable;

This will produce the following output −

+-----------+-----------+ | sleep(10) | FirstName | +-----------+-----------+ |         0 | John     | | 0 | Adam | | 0 | Bob | | 0 | Chris | | 0 | Robert | +-----------+-----------+ 5 rows in set (50.00 sec)
Updated on: 2019-08-22T11:22:45+05:30

332 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements