From 33691c50829df6932564637ec89aee349a2d3e5e Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 2 Jan 2024 13:00:38 +0800 Subject: [PATCH 1/2] This is an automated cherry-pick of #49947 Signed-off-by: ti-chi-bot --- planner/core/logical_plan_test.go | 38 ++++++++++++++++++++++++++++++- planner/core/point_get_plan.go | 2 +- util/mock/context.go | 5 ++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/planner/core/logical_plan_test.go b/planner/core/logical_plan_test.go index 7458c7307c19c..ac6908e2c54e9 100644 --- a/planner/core/logical_plan_test.go +++ b/planner/core/logical_plan_test.go @@ -21,6 +21,7 @@ import ( "strings" "testing" +<<<<<<< HEAD:planner/core/logical_plan_test.go "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/infoschema" @@ -36,6 +37,26 @@ import ( "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/testkit/testdata" "github.com/pingcap/tidb/util/hint" +======= + "github.com/pingcap/tidb/pkg/config" + "github.com/pingcap/tidb/pkg/domain" + "github.com/pingcap/tidb/pkg/expression" + "github.com/pingcap/tidb/pkg/infoschema" + "github.com/pingcap/tidb/pkg/parser" + "github.com/pingcap/tidb/pkg/parser/ast" + "github.com/pingcap/tidb/pkg/parser/format" + "github.com/pingcap/tidb/pkg/parser/model" + "github.com/pingcap/tidb/pkg/parser/mysql" + "github.com/pingcap/tidb/pkg/parser/terror" + "github.com/pingcap/tidb/pkg/planner/property" + "github.com/pingcap/tidb/pkg/planner/util" + "github.com/pingcap/tidb/pkg/sessionctx" + "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" +>>>>>>> 70452024e78 (planner: use TxnCtx.InfoSchema to prevent schema inconsistency (#49947)):pkg/planner/core/logical_plans_test.go "github.com/stretchr/testify/require" ) @@ -71,7 +92,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/planner/core/point_get_plan.go b/planner/core/point_get_plan.go index 82d2c91db5f3b..caa3051360139 100644 --- a/planner/core/point_get_plan.go +++ b/planner/core/point_get_plan.go @@ -1616,7 +1616,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, diff --git a/util/mock/context.go b/util/mock/context.go index d99fc5626b873..753d203754f18 100644 --- a/util/mock/context.go +++ b/util/mock/context.go @@ -454,6 +454,11 @@ func (c *Context) InSandBoxMode() bool { return c.inSandBoxMode } +// SetInfoSchema is to set info shema for the test. +func (c *Context) SetInfoSchema(is sessionctx.InfoschemaMetaVersion) { + c.is = is +} + // Close implements the sessionctx.Context interface. func (*Context) Close() {} From 6b82b2c861961ea5df7c6c5a7f1e48929187368a Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 23 Jan 2024 22:01:11 +0800 Subject: [PATCH 2/2] update Signed-off-by: Weizhen Wang --- planner/core/logical_plan_test.go | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/planner/core/logical_plan_test.go b/planner/core/logical_plan_test.go index ac6908e2c54e9..bdaf1984d5484 100644 --- a/planner/core/logical_plan_test.go +++ b/planner/core/logical_plan_test.go @@ -21,7 +21,6 @@ import ( "strings" "testing" -<<<<<<< HEAD:planner/core/logical_plan_test.go "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/infoschema" @@ -37,26 +36,7 @@ import ( "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/testkit/testdata" "github.com/pingcap/tidb/util/hint" -======= - "github.com/pingcap/tidb/pkg/config" - "github.com/pingcap/tidb/pkg/domain" - "github.com/pingcap/tidb/pkg/expression" - "github.com/pingcap/tidb/pkg/infoschema" - "github.com/pingcap/tidb/pkg/parser" - "github.com/pingcap/tidb/pkg/parser/ast" - "github.com/pingcap/tidb/pkg/parser/format" - "github.com/pingcap/tidb/pkg/parser/model" - "github.com/pingcap/tidb/pkg/parser/mysql" - "github.com/pingcap/tidb/pkg/parser/terror" - "github.com/pingcap/tidb/pkg/planner/property" - "github.com/pingcap/tidb/pkg/planner/util" - "github.com/pingcap/tidb/pkg/sessionctx" - "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" ->>>>>>> 70452024e78 (planner: use TxnCtx.InfoSchema to prevent schema inconsistency (#49947)):pkg/planner/core/logical_plans_test.go + "github.com/pingcap/tidb/util/mock" "github.com/stretchr/testify/require" )