From d7a8ff38646299f04312092d3a66a40d1de0bc2c Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Sun, 31 Dec 2023 19:48:34 +0800 Subject: [PATCH 1/3] planner: use TxnCtx.InfoSchema to prevent schema inconsistency --- pkg/planner/core/point_get_plan.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/planner/core/point_get_plan.go b/pkg/planner/core/point_get_plan.go index 63403cfe5256f..0fe6a7bfbe83a 100644 --- a/pkg/planner/core/point_get_plan.go +++ b/pkg/planner/core/point_get_plan.go @@ -1657,7 +1657,7 @@ func buildPointUpdatePlan(ctx sessionctx.Context, pointPlan PhysicalPlan, dbName VirtualAssignmentsOffset: len(orderedList), }.Init(ctx) updatePlan.names = pointPlan.OutputNames() - is := ctx.GetInfoSchema().(infoschema.InfoSchema) + is := sessiontxn.GetTxnManager(ctx).GetTxnInfoSchema() t, _ := is.TableByID(tbl.ID) updatePlan.tblID2Table = map[int64]table.Table{ tbl.ID: t, From a9c48db51ca97fdbea9d0d764f379d89dfd96a97 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Mon, 1 Jan 2024 01:06:46 +0800 Subject: [PATCH 2/3] planner: use TxnCtx.InfoSchema to prevent schema inconsistency --- pkg/planner/core/logical_plans_test.go | 18 +++++++++++++++++- pkg/util/mock/context.go | 5 +++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pkg/planner/core/logical_plans_test.go b/pkg/planner/core/logical_plans_test.go index 82283419f6012..770b433d3a38c 100644 --- a/pkg/planner/core/logical_plans_test.go +++ b/pkg/planner/core/logical_plans_test.go @@ -37,6 +37,7 @@ import ( "github.com/pingcap/tidb/pkg/sessionctx/variable" "github.com/pingcap/tidb/pkg/testkit/testdata" "github.com/pingcap/tidb/pkg/util/hint" + "github.com/pingcap/tidb/pkg/util/mock" "github.com/pingcap/tipb/go-tipb" "github.com/stretchr/testify/require" ) @@ -93,7 +94,22 @@ func createPlannerSuite() (s *plannerSuite) { } } s.is = infoschema.MockInfoSchema(tblInfos) - s.ctx = MockContext() + ctx := mock.NewContext() + ctx.Store = &mock.Store{ + Client: &mock.Client{}, + } + initStatsCtx := mock.NewContext() + initStatsCtx.Store = &mock.Store{ + Client: &mock.Client{}, + } + ctx.GetSessionVars().CurrentDB = "test" + do := domain.NewMockDomain() + if err := do.CreateStatsHandle(ctx, initStatsCtx); err != nil { + panic(fmt.Sprintf("create mock context panic: %+v", err)) + } + domain.BindDomain(ctx, do) + ctx.SetInfoSchema(s.is) + s.ctx = ctx domain.GetDomain(s.ctx).MockInfoCacheAndLoadInfoSchema(s.is) s.ctx.GetSessionVars().EnableWindowFunction = true s.p = parser.New() diff --git a/pkg/util/mock/context.go b/pkg/util/mock/context.go index 56dc4ae1ad50d..1e440e9ae8bf9 100644 --- a/pkg/util/mock/context.go +++ b/pkg/util/mock/context.go @@ -450,6 +450,11 @@ func (c *Context) InSandBoxMode() bool { return c.inSandBoxMode } +// SetInfoSchema implements the sessionctx.Context interface. +func (c *Context) SetInfoSchema(is sessionctx.InfoschemaMetaVersion) { + c.is = is +} + // Close implements the sessionctx.Context interface. func (*Context) Close() {} From 7bd1d96638a299ab66fdf84163e351662a2a1c79 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 2 Jan 2024 10:32:20 +0800 Subject: [PATCH 3/3] u Signed-off-by: Weizhen Wang --- pkg/util/mock/context.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/util/mock/context.go b/pkg/util/mock/context.go index 1e440e9ae8bf9..24bf504cb1fa6 100644 --- a/pkg/util/mock/context.go +++ b/pkg/util/mock/context.go @@ -450,7 +450,7 @@ func (c *Context) InSandBoxMode() bool { return c.inSandBoxMode } -// SetInfoSchema implements the sessionctx.Context interface. +// SetInfoSchema is to set info shema for the test. func (c *Context) SetInfoSchema(is sessionctx.InfoschemaMetaVersion) { c.is = is }