TableDeltaMap is inaccuracy when SQL execution failed
- 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)
Add following test in `pkg/session/test/txn/txn_test.go`, and the test passes but failed currently.
```go
func TestTxnTableDeltaMap(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("create table t2 (id int, a int, unique index(id))")
tk.MustExec("insert into t2 values (1,1), (2,2)")
tk.MustExec("begin")
err := tk.ExecToErr("update t2 set id=id+1")
require.Error(t, err)
require.Equal(t, "[kv:1062]Duplicate entry '2' for key 't2.id'", err.Error())
is := domain.GetDomain(tk.Session()).InfoSchema()
tb, err := is.TableByName(context.Background(), ast.NewCIStr("test"), ast.NewCIStr("t2"))
require.NoError(t, err)
txnCtx := tk.Session().GetSessionVars().TxnCtx
require.NotNil(t, txnCtx.TableDeltaMap)
require.Equal(t, int64(0), txnCtx.TableDeltaMap[tb.Meta().ID].Count, "todo: fix me...")
tk.MustExec("rollback")
}
```
Following is the test running result:
```sh
txn_test.go:563:
Error Trace: /Users/cs/code/goread/src/github.com/pingcap/tidb/pkg/session/test/txn/txn_test.go:563
Error: Not equal:
expected: 0
actual : 2
Test: TestTxnTableDeltaMap
Messages: todo: fix me...
```
### 2. What did you expect to see? (Required)
### 3. What did you see instead (Required)
### 4. What is your TiDB version? (Required)
nightly: 11cddd586ab233f87868b450532ff06a3f3c660f
Contributor guide
Assessment
This issue has not been assessed yet.