Skip to content

Commit 8ff1fac

Browse files
wjhuang2016ti-chi-bot
authored andcommitted
This is an automated cherry-pick of #57964
Signed-off-by: ti-chi-bot <[email protected]>
1 parent 858ba74 commit 8ff1fac

File tree

3 files changed

+530
-0
lines changed

3 files changed

+530
-0
lines changed

ddl/metadatalocktest/mdl_test.go

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,28 @@
1717
package metadatalocktest
1818

1919
import (
20+
"context"
2021
"fmt"
2122
"strings"
2223
"sync"
2324
"testing"
2425
"time"
2526

2627
"github.com/pingcap/failpoint"
28+
<<<<<<< HEAD:ddl/metadatalocktest/mdl_test.go
2729
mysql "github.com/pingcap/tidb/errno"
2830
"github.com/pingcap/tidb/server"
2931
"github.com/pingcap/tidb/testkit"
3032
"github.com/pingcap/tidb/util/logutil"
33+
=======
34+
"github.com/pingcap/tidb/pkg/ddl"
35+
ingesttestutil "github.com/pingcap/tidb/pkg/ddl/ingest/testutil"
36+
mysql "github.com/pingcap/tidb/pkg/errno"
37+
"github.com/pingcap/tidb/pkg/meta/model"
38+
"github.com/pingcap/tidb/pkg/server"
39+
"github.com/pingcap/tidb/pkg/testkit"
40+
"github.com/pingcap/tidb/pkg/testkit/testfailpoint"
41+
>>>>>>> 6b17068d75f (planner: fix incorrectly using the schema for plan cache (#57964)):pkg/ddl/tests/metadatalock/mdl_test.go
3142
"github.com/stretchr/testify/require"
3243
"go.uber.org/zap"
3344
)
@@ -971,6 +982,103 @@ func TestMDLPreparePlanCacheExecute2(t *testing.T) {
971982
tk.MustExec("admin check table t")
972983
}
973984

985+
// TestMDLPreparePlanCacheExecuteInsert makes sure the insert statement handle the schema correctly in plan cache.
986+
func TestMDLPreparePlanCacheExecuteInsert(t *testing.T) {
987+
store, dom := testkit.CreateMockStoreAndDomain(t)
988+
defer ingesttestutil.InjectMockBackendMgr(t, store)()
989+
990+
sv := server.CreateMockServer(t, store)
991+
992+
sv.SetDomain(dom)
993+
dom.InfoSyncer().SetSessionManager(sv)
994+
defer sv.Close()
995+
996+
conn1 := server.CreateMockConn(t, sv)
997+
tk := testkit.NewTestKitWithSession(t, store, conn1.Context().Session)
998+
conn2 := server.CreateMockConn(t, sv)
999+
tkDDL := testkit.NewTestKitWithSession(t, store, conn2.Context().Session)
1000+
conn3 := server.CreateMockConn(t, sv)
1001+
tk3 := testkit.NewTestKitWithSession(t, store, conn3.Context().Session)
1002+
tk.MustExec("use test")
1003+
tk.MustExec("set global tidb_enable_metadata_lock=1")
1004+
tk.MustExec("create table t(a int primary key, b int);")
1005+
tk.MustExec("create table t2(a int);")
1006+
tk.MustExec("insert into t values(1, 1), (2, 2), (3, 3), (4, 4);")
1007+
1008+
tk.MustExec(`begin`)
1009+
tk.MustExec(`prepare delete_stmt from 'delete from t where a = ?'`)
1010+
tk.MustExec(`prepare insert_stmt from 'insert into t values (?, ?)'`)
1011+
tk.MustExec(`commit`)
1012+
1013+
tk.MustExec(`begin`)
1014+
tk.MustExec(`set @a = 4, @b= 4;`)
1015+
tk.MustExec(`execute delete_stmt using @a;`)
1016+
tk.MustExec(`execute insert_stmt using @a, @b;`)
1017+
tk.MustExec(`commit`)
1018+
1019+
tk.MustExec("begin")
1020+
1021+
ch := make(chan struct{})
1022+
1023+
first := true
1024+
testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/ddl/onJobUpdated", func(job *model.Job) {
1025+
switch job.SchemaState {
1026+
case model.StateWriteReorganization:
1027+
tbl, _ := dom.InfoSchema().TableByID(context.Background(), job.TableID)
1028+
idx := tbl.Meta().FindIndexByName("idx")
1029+
switch idx.BackfillState {
1030+
case model.BackfillStateRunning:
1031+
if first {
1032+
tk.MustExec(`begin`)
1033+
tk.MustExec(`set @a=9;`)
1034+
tk.MustExec(`execute delete_stmt using @a;`)
1035+
tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0"))
1036+
tk.MustExec(`set @a=6, @b=4;`)
1037+
tk.MustExec(`execute insert_stmt using @a, @b;`)
1038+
tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0"))
1039+
tk.MustExec(`commit`)
1040+
tk.MustExec(`begin`)
1041+
tk.MustExec(`set @a=4;`)
1042+
tk.MustExec(`execute delete_stmt using @a;`)
1043+
tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("1"))
1044+
tk.MustExec(`set @a=4, @b=4;`)
1045+
tk.MustExec(`execute insert_stmt using @a, @b;`)
1046+
tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0"))
1047+
tk.MustExec(`commit`)
1048+
1049+
tk.MustExec("begin")
1050+
// Activate txn.
1051+
tk.MustExec("select * from t2")
1052+
first = false
1053+
tk3.MustExec("insert into test.t values(10000, 1000)")
1054+
return
1055+
}
1056+
}
1057+
}
1058+
})
1059+
1060+
ddl.MockDMLExecutionMerging = func() {
1061+
tk.MustExec(`execute delete_stmt using @a;`)
1062+
tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0"))
1063+
tk.MustExec(`execute insert_stmt using @a, @b;`)
1064+
tk.MustExec("commit")
1065+
}
1066+
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/ddl/mockDMLExecutionMerging", "1*return(true)->return(false)"))
1067+
1068+
var wg sync.WaitGroup
1069+
wg.Add(1)
1070+
go func() {
1071+
<-ch
1072+
tkDDL.MustExec("alter table test.t add index idx(a);")
1073+
wg.Done()
1074+
}()
1075+
1076+
ch <- struct{}{}
1077+
wg.Wait()
1078+
1079+
tk.MustExec("admin check table t")
1080+
}
1081+
9741082
func TestMDLDisable2Enable(t *testing.T) {
9751083
store, dom := testkit.CreateMockStoreAndDomain(t)
9761084
sv := server.CreateMockServer(t, store)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_test")
2+
3+
go_test(
4+
name = "metadatalock_test",
5+
timeout = "short",
6+
srcs = [
7+
"main_test.go",
8+
"mdl_test.go",
9+
],
10+
flaky = True,
11+
shard_count = 37,
12+
deps = [
13+
"//pkg/config",
14+
"//pkg/ddl",
15+
"//pkg/ddl/ingest/testutil",
16+
"//pkg/errno",
17+
"//pkg/meta/model",
18+
"//pkg/server",
19+
"//pkg/testkit",
20+
"//pkg/testkit/testfailpoint",
21+
"//pkg/testkit/testsetup",
22+
"@com_github_pingcap_failpoint//:failpoint",
23+
"@com_github_stretchr_testify//require",
24+
"@org_uber_go_goleak//:goleak",
25+
],
26+
)

0 commit comments

Comments
 (0)