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
… (#49966)

ref #41622
  • Loading branch information
ti-chi-bot authored Jan 5, 2024
1 parent 63e621a commit 6cb8310
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
18 changes: 17 additions & 1 deletion pkg/planner/core/logical_plans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion pkg/planner/core/point_get_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions pkg/util/mock/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,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 6cb8310

Please sign in to comment.