Skip to content

Commit 93295c2

Browse files
authored
ddl: simplify TestMDLPreparePlanCacheExecuteInsert (pingcap#58113)
ref pingcap#56733
1 parent 0082d58 commit 93295c2

File tree

3 files changed

+11
-28
lines changed

3 files changed

+11
-28
lines changed

.bazelversion

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.4.1

pkg/ddl/tests/metadatalock/mdl_test.go

+8-28
Original file line numberDiff line numberDiff line change
@@ -1016,26 +1016,14 @@ func TestMDLPreparePlanCacheExecuteInsert(t *testing.T) {
10161016
tk := testkit.NewTestKitWithSession(t, store, conn1.Context().Session)
10171017
conn2 := server.CreateMockConn(t, sv)
10181018
tkDDL := testkit.NewTestKitWithSession(t, store, conn2.Context().Session)
1019-
conn3 := server.CreateMockConn(t, sv)
1020-
tk3 := testkit.NewTestKitWithSession(t, store, conn3.Context().Session)
10211019
tk.MustExec("use test")
10221020
tk.MustExec("set global tidb_enable_metadata_lock=1")
10231021
tk.MustExec("create table t(a int primary key, b int);")
10241022
tk.MustExec("create table t2(a int);")
10251023
tk.MustExec("insert into t values(1, 1), (2, 2), (3, 3), (4, 4);")
10261024

1027-
tk.MustExec(`begin`)
1028-
tk.MustExec(`prepare delete_stmt from 'delete from t where a = ?'`)
10291025
tk.MustExec(`prepare insert_stmt from 'insert into t values (?, ?)'`)
1030-
tk.MustExec(`commit`)
1031-
1032-
tk.MustExec(`begin`)
1033-
tk.MustExec(`set @a = 4, @b= 4;`)
1034-
tk.MustExec(`execute delete_stmt using @a;`)
1035-
tk.MustExec(`execute insert_stmt using @a, @b;`)
1036-
tk.MustExec(`commit`)
1037-
1038-
tk.MustExec("begin")
1026+
tk.MustExec(`set @a=4, @b=4;`)
10391027

10401028
ch := make(chan struct{})
10411029

@@ -1048,19 +1036,10 @@ func TestMDLPreparePlanCacheExecuteInsert(t *testing.T) {
10481036
switch idx.BackfillState {
10491037
case model.BackfillStateRunning:
10501038
if first {
1039+
// generate plan, cache it, and make some row change to make
1040+
// sure backfill state 'merging' is not skipped.
10511041
tk.MustExec(`begin`)
1052-
tk.MustExec(`set @a=9;`)
1053-
tk.MustExec(`execute delete_stmt using @a;`)
1054-
tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0"))
1055-
tk.MustExec(`set @a=6, @b=4;`)
1056-
tk.MustExec(`execute insert_stmt using @a, @b;`)
1057-
tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0"))
1058-
tk.MustExec(`commit`)
1059-
tk.MustExec(`begin`)
1060-
tk.MustExec(`set @a=4;`)
1061-
tk.MustExec(`execute delete_stmt using @a;`)
1062-
tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("1"))
1063-
tk.MustExec(`set @a=4, @b=4;`)
1042+
tk.MustExec(`delete from t where a = 4;`)
10641043
tk.MustExec(`execute insert_stmt using @a, @b;`)
10651044
tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0"))
10661045
tk.MustExec(`commit`)
@@ -1069,17 +1048,18 @@ func TestMDLPreparePlanCacheExecuteInsert(t *testing.T) {
10691048
// Activate txn.
10701049
tk.MustExec("select * from t2")
10711050
first = false
1072-
tk3.MustExec("insert into test.t values(10000, 1000)")
10731051
return
10741052
}
10751053
}
10761054
}
10771055
})
10781056

10791057
ddl.MockDMLExecutionMerging = func() {
1080-
tk.MustExec(`execute delete_stmt using @a;`)
1081-
tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0"))
1058+
tk.MustExec(`delete from t where a = 4;`)
1059+
// we must generate a new plan here, because the schema has changed since
1060+
// the last plan was generated.
10821061
tk.MustExec(`execute insert_stmt using @a, @b;`)
1062+
tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0"))
10831063
tk.MustExec("commit")
10841064
}
10851065
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/ddl/mockDMLExecutionMerging", "1*return(true)->return(false)"))

pkg/table/tables/index.go

+2
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ func (c *index) create(sctx table.MutateContext, txn kv.Transaction, indexedValu
264264
tempVal := tablecodec.TempIndexValueElem{Value: idxVal, KeyVer: keyVer, Distinct: distinct}
265265
val = tempVal.Encode(nil)
266266
}
267+
// during some step of add-index, such as in write-reorg state, this
268+
// key is THE temp index key.
267269
err = txn.GetMemBuffer().Set(key, val)
268270
if err != nil {
269271
return nil, err

0 commit comments

Comments
 (0)