From 93295c233a3b1df0efdf30c29d51b9703c952926 Mon Sep 17 00:00:00 2001 From: D3Hunter Date: Tue, 10 Dec 2024 13:43:03 +0800 Subject: [PATCH] ddl: simplify TestMDLPreparePlanCacheExecuteInsert (#58113) ref pingcap/tidb#56733 --- .bazelversion | 1 + pkg/ddl/tests/metadatalock/mdl_test.go | 36 ++++++-------------------- pkg/table/tables/index.go | 2 ++ 3 files changed, 11 insertions(+), 28 deletions(-) create mode 100644 .bazelversion diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 0000000000000..815da58b7a9ed --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +7.4.1 diff --git a/pkg/ddl/tests/metadatalock/mdl_test.go b/pkg/ddl/tests/metadatalock/mdl_test.go index 232f10383d7c6..93852d0d17842 100644 --- a/pkg/ddl/tests/metadatalock/mdl_test.go +++ b/pkg/ddl/tests/metadatalock/mdl_test.go @@ -1016,26 +1016,14 @@ func TestMDLPreparePlanCacheExecuteInsert(t *testing.T) { tk := testkit.NewTestKitWithSession(t, store, conn1.Context().Session) conn2 := server.CreateMockConn(t, sv) tkDDL := testkit.NewTestKitWithSession(t, store, conn2.Context().Session) - conn3 := server.CreateMockConn(t, sv) - tk3 := testkit.NewTestKitWithSession(t, store, conn3.Context().Session) tk.MustExec("use test") tk.MustExec("set global tidb_enable_metadata_lock=1") tk.MustExec("create table t(a int primary key, b int);") tk.MustExec("create table t2(a int);") tk.MustExec("insert into t values(1, 1), (2, 2), (3, 3), (4, 4);") - tk.MustExec(`begin`) - tk.MustExec(`prepare delete_stmt from 'delete from t where a = ?'`) tk.MustExec(`prepare insert_stmt from 'insert into t values (?, ?)'`) - tk.MustExec(`commit`) - - tk.MustExec(`begin`) - tk.MustExec(`set @a = 4, @b= 4;`) - tk.MustExec(`execute delete_stmt using @a;`) - tk.MustExec(`execute insert_stmt using @a, @b;`) - tk.MustExec(`commit`) - - tk.MustExec("begin") + tk.MustExec(`set @a=4, @b=4;`) ch := make(chan struct{}) @@ -1048,19 +1036,10 @@ func TestMDLPreparePlanCacheExecuteInsert(t *testing.T) { switch idx.BackfillState { case model.BackfillStateRunning: if first { + // generate plan, cache it, and make some row change to make + // sure backfill state 'merging' is not skipped. tk.MustExec(`begin`) - tk.MustExec(`set @a=9;`) - tk.MustExec(`execute delete_stmt using @a;`) - tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0")) - tk.MustExec(`set @a=6, @b=4;`) - tk.MustExec(`execute insert_stmt using @a, @b;`) - tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0")) - tk.MustExec(`commit`) - tk.MustExec(`begin`) - tk.MustExec(`set @a=4;`) - tk.MustExec(`execute delete_stmt using @a;`) - tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("1")) - tk.MustExec(`set @a=4, @b=4;`) + tk.MustExec(`delete from t where a = 4;`) tk.MustExec(`execute insert_stmt using @a, @b;`) tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0")) tk.MustExec(`commit`) @@ -1069,7 +1048,6 @@ func TestMDLPreparePlanCacheExecuteInsert(t *testing.T) { // Activate txn. tk.MustExec("select * from t2") first = false - tk3.MustExec("insert into test.t values(10000, 1000)") return } } @@ -1077,9 +1055,11 @@ func TestMDLPreparePlanCacheExecuteInsert(t *testing.T) { }) ddl.MockDMLExecutionMerging = func() { - tk.MustExec(`execute delete_stmt using @a;`) - tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0")) + tk.MustExec(`delete from t where a = 4;`) + // we must generate a new plan here, because the schema has changed since + // the last plan was generated. tk.MustExec(`execute insert_stmt using @a, @b;`) + tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0")) tk.MustExec("commit") } require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/ddl/mockDMLExecutionMerging", "1*return(true)->return(false)")) diff --git a/pkg/table/tables/index.go b/pkg/table/tables/index.go index cdf502ee2733f..e5436a6c1c78f 100644 --- a/pkg/table/tables/index.go +++ b/pkg/table/tables/index.go @@ -264,6 +264,8 @@ func (c *index) create(sctx table.MutateContext, txn kv.Transaction, indexedValu tempVal := tablecodec.TempIndexValueElem{Value: idxVal, KeyVer: keyVer, Distinct: distinct} val = tempVal.Encode(nil) } + // during some step of add-index, such as in write-reorg state, this + // key is THE temp index key. err = txn.GetMemBuffer().Set(key, val) if err != nil { return nil, err