TiDB crashes when preprocessing `UPDATE` statement.
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
## Bug Report
### 1. Minimal reproduce step (Required)
1. Compile the TiDB using the source repository: [link](https://github.com/pingcap/tidb)
2. Check out with the latest master version: 0c3bbc127c, also tested with released version: v7.4.0-alpha (d43359a55705).
3. Compile the TiDB server using go1.21.0. Use `make` in the repo root directory.
4. Launch TiDB server using command:
```bash
./tidb-server -P 8000 -socket /tmp/mysql_0.sql -path $(pwd)/db_data
```
5. Connect to the server using mysql client:
```bash
mysql -h 127.0.0.1 -P 8000 -u root --socket /tmp/mysql_0.sql
```
6. Input the PoC Query to trigger the crash of the server.
```sql
create databse test;
use test;
WITH RECURSIVE ta1 AS (SELECT 'anyText' ) UPDATE ta0 AS OF TIMESTAMP ? IN (SELECT TRUE ) SET ta0.random_iden = DEFAULT;
```
### 2. What did you expect to see? (Required)
The TiDB Server should continue running.
### 3. What did you see instead (Required)
The TiDB-server crashes and then returns error:
```
ERROR 1105 (HY000): runtime error: invalid memory address or nil pointer dereference
```
Here is a more detailed stack trace from the v7.4.0-alpha (d43359a55705):
```
"github.com/pingcap/tidb/server.(*clientConn).Run.func1
\t/home/tidb/go_projects/src/github.com/tidb/tidb/server/conn.go:966
runtime.gopanic
\t/usr/local/go/src/runtime/panic.go:914
github.com/pingcap/tidb/executor.(*Compiler).Compile.func1
\t/home/tidb/go_projects/src/github.com/tidb/tidb/executor/compiler.go:54
runtime.gopanic
\t/usr/local/go/src/runtime/panic.go:914
runtime.panicmem
\t/usr/local/go/src/runtime/panic.go:261
runtime.sigpanic
\t/usr/local/go/src/runtime/signal_unix.go:861
github.com/pingcap/tidb/util/chunk.Row.IsNull
\t/home/tidb/go_projects/src/github.com/tidb/tidb/util/chunk/row.go:218
github.com/pingcap/tidb/util/chunk.Row.GetDatumWithBuffer
\t/home/tidb/go_projects/src/github.com/tidb/tidb/util/chunk/row.go:141
github.com/pingcap/tidb/util/chunk.Row.GetDatum
\t/home/tidb/go_projects/src/github.com/tidb/tidb/util/chunk/row.go:133
github.com/pingcap/tidb/expression.(*Column).Eval
\t/home/tidb/go_projects/src/github.com/tidb/tidb/expression/column.go:413
github.com/pingcap/tidb/planner/core.evalAstExpr
\t/home/tidb/go_projects/src/github.com/tidb/tidb/planner/core/expression_rewriter.go:62
github.com/pingcap/tidb/sessiontxn/staleread.CalculateAsOfTsExpr
\t/home/tidb/go_projects/src/github.com/tidb/tidb/sessiontxn/staleread/util.go:43
github.com/pingcap/tidb/sessiontxn/staleread.parseAndValidateAsOf
\t/home/tidb/go_projects/src/github.com/tidb/tidb/sessiontxn/staleread/processor.go:283
github.com/pingcap/tidb/sessiontxn/staleread.(*staleReadProcessor).OnSelectTable.func1
\t/home/tidb/go_projects/src/github.com/tidb/tidb/sessiontxn/staleread/processor.go:171
github.com/pingcap/tidb/sessiontxn/staleread.(*staleReadProcessor).OnSelectTable
\t/home/tidb/go_projects/src/github.com/tidb/tidb/sessiontxn/staleread/processor.go:173
github.com/pingcap/tidb/planner/core.(*preprocessor).handleTableName
\t/home/tidb/go_projects/src/github.com/tidb/tidb/planner/core/preprocess.go:1556
github.com/pingcap/tidb/planner/core.(*preprocessor).Leave
\t/home/tidb/go_projects/src/github.com/tidb/tidb/planner/core/preprocess.go:584
github.com/pingcap/tidb/parser/ast.(*TableName).Accept
\t/home/tidb/go_projects/src/github.com/tidb/tidb/parser/ast/dml.go:452
github.com/pingcap/tidb/parser/ast.(*TableSource).Accept
\t/home/tidb/go_projects/src/github.com/tidb/tidb/parser/ast/dml.go:604
github.com/pingcap/tidb/parser/ast.(*Join).Accept
\t/home/tidb/go_projects/src/github.com/tidb/tidb/parser/ast/dml.go:244
github.com/pingcap/tidb/parser/ast.(*TableRefsClause).Accept
\t/home/tidb/go_projects/src/github.com/tidb/tidb/parser/ast/dml.go:805
github.com/pingcap/tidb/parser/ast.(*UpdateStmt).Accept
\t/home/tidb/go_projects/src/github.com/tidb/tidb/parser/ast/dml.go:2814
github.com/pingcap/tidb/planner/core.Preprocess
\t/home/tidb/go_projects/src/github.com/tidb/tidb/planner/core/preprocess.go:136
github.com/pingcap/tidb/executor.(*Compiler).Compile
\t/home/tidb/go_projects/src/github.com/tidb/tidb/executor/compiler.go:63
github.com/pingcap/tidb/session.(*session).ExecuteStmt
\t/home/tidb/go_projects/src/github.com/tidb/tidb/session/session.go:2225
github.com/pingcap/tidb/server.(*TiDBContext).ExecuteStmt
\t/home/tidb/go_projects/src/github.com/tidb/tidb/server/driver_tidb.go:291
github.com/pingcap/tidb/server.(*clientConn).handleStmt
\t/home/tidb/go_projects/src/github.com/tidb/tidb/server/conn.go:1994
github.com/pingcap/tidb/server.(*clientConn).handleQuery
\t/home/tidb/go_projects/src/github.com/tidb/tidb/server/conn.go:1785
github.com/pingcap/tidb/server.(*clientConn).dispatch
\t/home/tidb/go_projects/src/github.com/tidb/tidb/server/conn.go:1272
github.com/pingcap/tidb/server.(*clientConn).Run
\t/home/tidb/go_projects/src/github.com/tidb/tidb/server/conn.go:1051
github.com/pingcap/tidb/server.(*Server).onConn
\t/home/tidb/go_projects/src/github.com/tidb/tidb/server/server.go:699"
```
### 4. What is your TiDB version? (Required)
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v7.4.0-alpha
Edition: Community
Git Commit Hash: d43359a5570590d4892332ad0ad4b152cb12b3e1
Git Branch: HEAD
UTC Build Time: 2023-08-21 18:58:32
GoVersion: go1.21.0
Race Enabled: false
Check Table Before Drop: false
Store: unistore |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
Contributor guide
Assessment
This issue has not been assessed yet.