Skip to content

Commit 9b21b85

Browse files
D3Hunterti-chi-bot
authored andcommitted
This is an automated cherry-pick of pingcap#58113
Signed-off-by: ti-chi-bot <[email protected]>
1 parent b298e21 commit 9b21b85

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.4.1

pkg/ddl/tests/metadatalock/mdl_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,86 @@ func TestMDLPreparePlanCacheExecute2(t *testing.T) {
997997
tk.MustExec("admin check table t")
998998
}
999999

1000+
<<<<<<< HEAD
1001+
=======
1002+
// TestMDLPreparePlanCacheExecuteInsert makes sure the insert statement handle the schema correctly in plan cache.
1003+
func TestMDLPreparePlanCacheExecuteInsert(t *testing.T) {
1004+
store, dom := testkit.CreateMockStoreAndDomain(t)
1005+
defer ingesttestutil.InjectMockBackendMgr(t, store)()
1006+
1007+
sv := server.CreateMockServer(t, store)
1008+
1009+
sv.SetDomain(dom)
1010+
dom.InfoSyncer().SetSessionManager(sv)
1011+
defer sv.Close()
1012+
1013+
conn1 := server.CreateMockConn(t, sv)
1014+
tk := testkit.NewTestKitWithSession(t, store, conn1.Context().Session)
1015+
conn2 := server.CreateMockConn(t, sv)
1016+
tkDDL := testkit.NewTestKitWithSession(t, store, conn2.Context().Session)
1017+
tk.MustExec("use test")
1018+
tk.MustExec("set global tidb_enable_metadata_lock=1")
1019+
tk.MustExec("create table t(a int primary key, b int);")
1020+
tk.MustExec("create table t2(a int);")
1021+
tk.MustExec("insert into t values(1, 1), (2, 2), (3, 3), (4, 4);")
1022+
1023+
tk.MustExec(`prepare insert_stmt from 'insert into t values (?, ?)'`)
1024+
tk.MustExec(`set @a=4, @b=4;`)
1025+
1026+
ch := make(chan struct{})
1027+
1028+
first := true
1029+
testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/ddl/onJobUpdated", func(job *model.Job) {
1030+
switch job.SchemaState {
1031+
case model.StateWriteReorganization:
1032+
tbl, _ := dom.InfoSchema().TableByID(context.Background(), job.TableID)
1033+
idx := tbl.Meta().FindIndexByName("idx")
1034+
switch idx.BackfillState {
1035+
case model.BackfillStateRunning:
1036+
if first {
1037+
// generate plan, cache it, and make some row change to make
1038+
// sure backfill state 'merging' is not skipped.
1039+
tk.MustExec(`begin`)
1040+
tk.MustExec(`delete from t where a = 4;`)
1041+
tk.MustExec(`execute insert_stmt using @a, @b;`)
1042+
tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0"))
1043+
tk.MustExec(`commit`)
1044+
1045+
tk.MustExec("begin")
1046+
// Activate txn.
1047+
tk.MustExec("select * from t2")
1048+
first = false
1049+
return
1050+
}
1051+
}
1052+
}
1053+
})
1054+
1055+
ddl.MockDMLExecutionMerging = func() {
1056+
tk.MustExec(`delete from t where a = 4;`)
1057+
// we must generate a new plan here, because the schema has changed since
1058+
// the last plan was generated.
1059+
tk.MustExec(`execute insert_stmt using @a, @b;`)
1060+
tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0"))
1061+
tk.MustExec("commit")
1062+
}
1063+
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/ddl/mockDMLExecutionMerging", "1*return(true)->return(false)"))
1064+
1065+
var wg sync.WaitGroup
1066+
wg.Add(1)
1067+
go func() {
1068+
<-ch
1069+
tkDDL.MustExec("alter table test.t add index idx(a);")
1070+
wg.Done()
1071+
}()
1072+
1073+
ch <- struct{}{}
1074+
wg.Wait()
1075+
1076+
tk.MustExec("admin check table t")
1077+
}
1078+
1079+
>>>>>>> 93295c233a3 (ddl: simplify TestMDLPreparePlanCacheExecuteInsert (#58113))
10001080
func TestMDLDisable2Enable(t *testing.T) {
10011081
store, dom := testkit.CreateMockStoreAndDomain(t)
10021082
sv := server.CreateMockServer(t, store)

pkg/table/tables/index.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ func (c *index) Create(sctx sessionctx.Context, txn kv.Transaction, indexedValue
241241
tempVal := tablecodec.TempIndexValueElem{Value: idxVal, KeyVer: keyVer, Distinct: distinct}
242242
val = tempVal.Encode(nil)
243243
}
244+
// during some step of add-index, such as in write-reorg state, this
245+
// key is THE temp index key.
244246
err = txn.GetMemBuffer().Set(key, val)
245247
if err != nil {
246248
return nil, err

0 commit comments

Comments
 (0)