"Lost connection to MySQL server during query" after UPDATE statement
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
Please answer these questions before submitting your issue. Thanks!
### 1. Minimal reproduce step (Required)
**Setup the environment:**
```
tiup playground --db.binpath /path/to/latest/tidb-server &
mysql -h "127.0.0.1" -u root -P 4000 -D testdb < mysql_bk.sql
```
_mysql_bk.sql:_
[mysql_bk.txt](https://github.com/pingcap/tidb/files/8553372/mysql_bk.txt)
**Testcase**
```
mysql -h "127.0.0.1" -u root -P 4000 -D testdb
mysql> update t__ti1_d set
wkey = 37
where (case when 0 <> 0 then abs(
case when t__ti1_d.wkey > (
select
t__ti1_d.c_azzk8c as c0
from
t_yexe_d as ref_0
where 10 >= (select count(c_vqpj9c) from t_yexe_d)
window w_80pxn as ( partition by t__ti1_d.pkey order by ref_0.c_px23g desc)
order by c0 desc
) then 1 else 20 end
) else 1 end * 53) > 1;
mysql> select * from t__ti1_d;
```
### 2. What did you expect to see? (Required)
The connection will not be lost.
### 3. What did you see instead (Required)
**UPDATE statement**
```
ERROR 1105 (HY000): runtime error: index out of range [0] with length 0
```
**SELECT statement**
```
ERROR 2013 (HY000): Lost connection to MySQL server during query
No connection. Trying to reconnect...
Connection id: 136645
Current database: testdb
+------+--------+---------+----------+--------------------+----------+----------+----------+----------+
| wkey | pkey | c_l3pcj | c_ksp1hc | c_5vhjk | c_azzk8c | c_g0jc6d | c_jqg9yd | c__qdjic |
+------+--------+---------+----------+--------------------+----------+----------+----------+----------+
| 107 | 130000 | NULL | _dry8b | 19.798874920631782 | NULL | NULL | NULL | NULL |
+------+--------+---------+----------+--------------------+----------+----------+----------+----------+
1 row in set (0.01 sec)
```
### 4. What is your TiDB version? (Required)
```
Release Version: v6.1.0-alpha-173-g32b9c1477
Edition: Community
Git Commit Hash: 32b9c14779c2a7dd73003667d81bb42f67a33385
Git Branch: master
UTC Build Time: 2022-04-11 17:53:15
GoVersion: go1.18
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
```
Contributor guide
Assessment
This issue has not been assessed yet.