-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
ddl: introduce newReorgExprCtx
to replace mock.Context
usage
#53389
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ import ( | |
sess "github.com/pingcap/tidb/pkg/ddl/internal/session" | ||
"github.com/pingcap/tidb/pkg/ddl/logutil" | ||
"github.com/pingcap/tidb/pkg/distsql" | ||
exprctx "github.com/pingcap/tidb/pkg/expression/context" | ||
"github.com/pingcap/tidb/pkg/expression/contextstatic" | ||
"github.com/pingcap/tidb/pkg/kv" | ||
"github.com/pingcap/tidb/pkg/meta" | ||
"github.com/pingcap/tidb/pkg/metrics" | ||
|
@@ -73,6 +75,19 @@ type reorgCtx struct { | |
references atomicutil.Int32 | ||
} | ||
|
||
func newReorgExprCtx() exprctx.ExprContext { | ||
evalCtx := contextstatic.NewStaticEvalContext( | ||
contextstatic.WithSQLMode(mysql.ModeNone), | ||
contextstatic.WithTypeFlags(types.DefaultStmtFlags), | ||
contextstatic.WithErrLevelMap(stmtctx.DefaultStmtErrLevels), | ||
) | ||
|
||
return contextstatic.NewStaticExprContext( | ||
contextstatic.WithEvalCtx(evalCtx), | ||
contextstatic.WithUseCache(false), | ||
) | ||
} | ||
|
||
func newReorgSessCtx(store kv.Storage) sessionctx.Context { | ||
c := mock.NewContext() | ||
c.Store = store | ||
|
@@ -601,16 +616,15 @@ func (dc *ddlCtx) GetTableMaxHandle(ctx *JobContext, startTS uint64, tbl table.P | |
// empty table | ||
return nil, true, nil | ||
} | ||
sessCtx := newReorgSessCtx(dc.store) | ||
row := chk.GetRow(0) | ||
if tblInfo.IsCommonHandle { | ||
maxHandle, err = buildCommonHandleFromChunkRow(sessCtx.GetSessionVars().StmtCtx, tblInfo, pkIdx, handleCols, row) | ||
maxHandle, err = buildCommonHandleFromChunkRow(time.UTC, tblInfo, pkIdx, handleCols, row) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return maxHandle, false, err | ||
} | ||
return kv.IntHandle(row.GetInt64(0)), false, nil | ||
} | ||
|
||
func buildCommonHandleFromChunkRow(sctx *stmtctx.StatementContext, tblInfo *model.TableInfo, idxInfo *model.IndexInfo, | ||
func buildCommonHandleFromChunkRow(loc *time.Location, tblInfo *model.TableInfo, idxInfo *model.IndexInfo, | ||
cols []*model.ColumnInfo, row chunk.Row) (kv.Handle, error) { | ||
fieldTypes := make([]*types.FieldType, 0, len(cols)) | ||
for _, col := range cols { | ||
|
@@ -620,8 +634,7 @@ func buildCommonHandleFromChunkRow(sctx *stmtctx.StatementContext, tblInfo *mode | |
tablecodec.TruncateIndexValues(tblInfo, idxInfo, datumRow) | ||
|
||
var handleBytes []byte | ||
handleBytes, err := codec.EncodeKey(sctx.TimeZone(), nil, datumRow...) | ||
err = sctx.HandleError(err) | ||
handleBytes, err := codec.EncodeKey(loc, nil, datumRow...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems the HandleError takes no effect here because |
||
if err != nil { | ||
return nil, err | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call of
makeupDecodeColMap
iswritePhysicalTableRecord -> newBackfillScheduler -> newTxnBackfillScheduler -> makeupDecodeColMap
. This is the only call chain. So we can just move the expr ctx construct intomakeupDecodeColMap