pingcap / pingcap/tidb

TiDB produces different results for SELECT statements (runtime error: index out of range [0] with length 0)

Open
#38,209 0 comments 0 reactions 0 assignees View on GitHub
affects-5.1 affects-5.2 affects-5.3 affects-5.4 affects-6.0 affects-6.1 affects-6.2 affects-6.3 affects-6.4 affects-6.5 affects-6.6 affects-7.0 affects-7.1 affects-7.5 affects-8.1 affects-8.5 severity/major sig/execution type/bug
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/9659635/mysql_bk.txt)

**Testcase 1**
```
mysql -h "127.0.0.1" -u root -P 4000 -D testdb

mysql> update t_smmcv set wkey = 501;
mysql> select *
from
t_kb1xh
where 100 <= case when t_kb1xh.c_bihued = (
select distinct
'1kkruc' as c0
from
t_smmcv as ref_13
) then 101 else 57 end;
```

**Testcase 2**
```
mysql -h "127.0.0.1" -u root -P 4000 -D testdb

mysql> start transaction;
mysql> update t_smmcv set wkey = 501;
mysql> select *
from
t_kb1xh
where 100 <= case when t_kb1xh.c_bihued = (
select distinct
'1kkruc' as c0
from
t_smmcv as ref_13
) then 101 else 57 end;
mysql> commit;
```

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

The execution result of SELECT statements in Testcase 1 and Testcase 2 are the same.

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

**Output of SELECT statement in Testcase 1**
```
ERROR 1105 (HY000): runtime error: index out of range [0] with length 0
```

**Output of SELECT statement in Testcase 2**
```
Empty set (0.01 sec)
```

Their results are different.

**Information of tidb.log when test case 1 triggers runtime errors**

```
[2022/09/27 21:12:01.779 +00:00] [INFO] [conn.go:1137]
["command dispatched failed"]
[conn=5830617803119407401]
[connInfo="id:5830617803119407401, addr:127.0.0.1:56480 status:10, collation:latin1_swedish_ci, user:root"]
[command=Query] [status="inTxn:0, autocommit:1"]
[sql="select *from t_kb1xhwhere 100 <= case when t_kb1xh.c_bihued = ( select distinct '1kkruc' as c0 from t_smmcv as ref_13 ) then 101 else 57 end"]
[txn_mode=PESSIMISTIC] [timestamp=436289698969944066]
[err="runtime error: index out of range [0] with length 0
github.com/pingcap/tidb/executor.recoveryHashAgg
/home/zuming/tidb/executor/aggregate.go:451
github.com/pingcap/tidb/executor.(*HashAggPartialWorker).run.func1
/home/zuming/tidb/executor/aggregate.go:460
runtime.gopanic
/usr/local/go/src/runtime/panic.go:884
runtime.goPanicIndex
/usr/local/go/src/runtime/panic.go:113
github.com/pingcap/tidb/util/chunk.(*Column).GetString
/home/zuming/tidb/util/chunk/column.go:577
github.com/pingcap/tidb/util/chunk.Row.GetString
/home/zuming/tidb/util/chunk/row.go:72
github.com/pingcap/tidb/expression.(*Column).EvalString
/home/zuming/tidb/expression/column.go:434
github.com/pingcap/tidb/executor/aggfuncs.(*firstRow4String).UpdatePartialResult
/home/zuming/tidb/executor/aggfuncs/func_first_row.go:277
github.com/pingcap/tidb/executor.(*HashAggPartialWorker).updatePartialResult
/home/zuming/tidb/executor/aggregate.go:520
github.com/pingcap/tidb/executor.(*HashAggPartialWorker).run
/home/zuming/tidb/executor/aggregate.go:481
runtime.goexit
/usr/local/go/src/runtime/asm_amd64.s:1594"]
```

### 4. What is your TiDB version? (Required)

```
Release Version: v6.3.0-20220913
Edition: Community
Git Commit Hash: 95e09ba33c0bdb629c4d4a7a31a2e4bc1212ad2a
Git Branch: HEAD
UTC Build Time: 2022-09-24 12:55:50
GoVersion: go1.19.1
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: tikv
```

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.