Skip to content

Commit

Permalink
executor: fix plan replay cannot deal with placement mode (#56774) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Nov 1, 2024
1 parent f92493d commit 2f2bf22
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions pkg/executor/plan_replayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,12 +523,15 @@ func (e *PlanReplayerLoadInfo) Update(data []byte) error {
}

func (e *PlanReplayerLoadInfo) createTable(z *zip.Reader) error {
origin := e.Ctx.GetSessionVars().ForeignKeyChecks
originForeignKeyChecks := e.Ctx.GetSessionVars().ForeignKeyChecks
originPlacementMode := e.Ctx.GetSessionVars().PlacementMode
// We need to disable foreign key check when we create schema and tables.
// because the order of creating schema and tables is not guaranteed.
e.Ctx.GetSessionVars().ForeignKeyChecks = false
e.Ctx.GetSessionVars().PlacementMode = variable.PlacementModeIgnore
defer func() {
e.Ctx.GetSessionVars().ForeignKeyChecks = origin
e.Ctx.GetSessionVars().ForeignKeyChecks = originForeignKeyChecks
e.Ctx.GetSessionVars().PlacementMode = originPlacementMode
}()
for _, zipFile := range z.File {
if zipFile.Name == fmt.Sprintf("schema/%v", domain.PlanReplayerSchemaMetaFile) {
Expand Down
8 changes: 6 additions & 2 deletions pkg/server/handler/optimizor/plan_replayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,14 +449,18 @@ func prepareData4Issue56458(t *testing.T, client *testserverclient.TestServerCli
tk.MustExec("create database planReplayer")
tk.MustExec("create database planReplayer2")
tk.MustExec("use planReplayer")

tk.MustExec("create placement policy p " +
"LEARNERS=1 " +
"LEARNER_CONSTRAINTS=\"[+region=cn-west-1]\" " +
"FOLLOWERS=3 " +
"FOLLOWER_CONSTRAINTS=\"[+disk=ssd]\"")
tk.MustExec("CREATE TABLE v(id INT PRIMARY KEY AUTO_INCREMENT);")
err = h.HandleDDLEvent(<-h.DDLEventCh())
require.NoError(t, err)
tk.MustExec("create table planReplayer2.t(a int, b int, INDEX ia (a), INDEX ib (b), author_id int, FOREIGN KEY (author_id) REFERENCES planReplayer.v(id) ON DELETE CASCADE);")
err = h.HandleDDLEvent(<-h.DDLEventCh())
require.NoError(t, err)
tk.MustExec("create table t(a int, b int, INDEX ia (a), INDEX ib (b), author_id int, FOREIGN KEY (author_id) REFERENCES planReplayer2.t(a) ON DELETE CASCADE);")
tk.MustExec("create table t(a int, b int, INDEX ia (a), INDEX ib (b), author_id int, FOREIGN KEY (author_id) REFERENCES planReplayer2.t(a) ON DELETE CASCADE) placement policy p;")
err = h.HandleDDLEvent(<-h.DDLEventCh())
require.NoError(t, err)

Expand Down

0 comments on commit 2f2bf22

Please sign in to comment.