diff --git a/pkg/executor/plan_replayer.go b/pkg/executor/plan_replayer.go index 9eae7fcb90b87..06c160f942850 100644 --- a/pkg/executor/plan_replayer.go +++ b/pkg/executor/plan_replayer.go @@ -524,12 +524,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) { diff --git a/pkg/server/handler/optimizor/plan_replayer_test.go b/pkg/server/handler/optimizor/plan_replayer_test.go index dacbc0638c463..0748d0e12359a 100644 --- a/pkg/server/handler/optimizor/plan_replayer_test.go +++ b/pkg/server/handler/optimizor/plan_replayer_test.go @@ -450,14 +450,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)