pingcap / pingcap/tidb

Sleep in subquery not executed correctly

Open
#45,292 3 comments 0 reactions 1 assignee Assigned to @guo-shaoge View on GitHub
compatibility-mysql80 severity/minor sig/execution type/bug type/compatibility
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

When calling `SLEEP()` multiple times in separate subqueries the execution time is not the expected execution time.

### 1. Minimal reproduce step (Required)

```
SELECT SLEEP(2) UNION ALL SELECT SLEEP(3);
SELECT SLEEP(2),SLEEP(3);
```

### 2. What did you expect to see? (Required)

Both statements taking 5s each.

### 3. What did you see instead (Required)

TiDB:
```
mysql> SELECT SLEEP(2) UNION ALL SELECT SLEEP(3);
+----------+
| SLEEP(2) |
+----------+
| 0 |
| 0 |
+----------+
2 rows in set (3.00 sec)

mysql> SELECT SLEEP(2),SLEEP(3);
+----------+----------+
| SLEEP(2) | SLEEP(3) |
+----------+----------+
| 0 | 0 |
+----------+----------+
1 row in set (5.00 sec)
```

MySQL 8.0:
```
mysql> SELECT SLEEP(2) UNION ALL SELECT SLEEP(3);
+----------+
| SLEEP(2) |
+----------+
| 0 |
| 0 |
+----------+
2 rows in set (5.00 sec)

mysql> SELECT SLEEP(2),SLEEP(3);
+----------+----------+
| SLEEP(2) | SLEEP(3) |
+----------+----------+
| 0 | 0 |
+----------+----------+
1 row in set (5.00 sec)

mysql> SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 8.0.33 |
+-----------+
1 row in set (0.00 sec)
```
### 4. What is your TiDB version? (Required)

```
Release Version: v7.3.0-alpha-160-g90dabc0433
Edition: Community
Git Commit Hash: 90dabc0433a75db650ac683897d264ef58d63a73
Git Branch: master
UTC Build Time: 2023-07-11 07:57:57
GoVersion: go1.20.5
Race Enabled: false
Check Table Before Drop: false
Store: unistore
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.