Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: use TxnCtx.InfoSchema to prevent schema inconsistency (#49947) #49964

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion planner/core/logical_plan_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 @@ -71,7 +72,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 @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions util/mock/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

Expand Down