Skip to content

Commit

Permalink
planner: use TxnCtx.InfoSchema to prevent schema inconsistency (#49947)…
Browse files Browse the repository at this point in the history
… (#49965)

ref #41622
  • Loading branch information
ti-chi-bot authored Jan 8, 2024
1 parent ae491e2 commit 29df3c8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
18 changes: 17 additions & 1 deletion planner/core/logical_plans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +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/util/mock"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -91,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()
Expand Down
2 changes: 1 addition & 1 deletion planner/core/point_get_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -1656,7 +1656,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,
Expand Down
5 changes: 5 additions & 0 deletions util/mock/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,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() {}

Expand Down

0 comments on commit 29df3c8

Please sign in to comment.