MCPcopy
hub / github.com/pingcap/tidb / MakeEvalContextStatic

Function MakeEvalContextStatic

pkg/expression/exprstatic/evalctx.go:490–529  ·  view source on GitHub ↗

MakeEvalContextStatic converts the `exprctx.StaticConvertibleEvalContext` to `EvalContext`.

(ctx exprctx.StaticConvertibleEvalContext)

Source from the content-addressed store, hash-verified

488
489// MakeEvalContextStatic converts the `exprctx.StaticConvertibleEvalContext` to `EvalContext`.
490func MakeEvalContextStatic(ctx exprctx.StaticConvertibleEvalContext) *EvalContext {
491 typeCtx := ctx.TypeCtx()
492 errCtx := ctx.ErrCtx()
493
494 // TODO: at least provide some optional eval prop provider which is suitable to be used in the static context.
495 props := make([]exprctx.OptionalEvalPropProvider, 0, exprctx.OptPropsCnt)
496
497 params := variable.NewPlanCacheParamList()
498 for _, param := range ctx.AllParamValues() {
499 params.Append(param)
500 }
501
502 // TODO: use a more structural way to replace the closure.
503 // These closure makes sure the fields which may be changed in the execution of the next statement will not be embedded into them, to make
504 // sure it's safe to call them after the session continues to execute other statements.
505 staticCtx := NewEvalContext(
506 WithWarnHandler(ctx.GetWarnHandler()),
507 WithSQLMode(ctx.SQLMode()),
508 WithTypeFlags(typeCtx.Flags()),
509 WithLocation(typeCtx.Location()),
510 WithErrLevelMap(errCtx.LevelMap()),
511 WithCurrentDB(ctx.CurrentDB()),
512 WithCurrentTime(func() func() (time.Time, error) {
513 currentTime, currentTimeErr := ctx.CurrentTime()
514
515 return func() (time.Time, error) {
516 return currentTime, currentTimeErr
517 }
518 }()),
519 WithMaxAllowedPacket(ctx.GetMaxAllowedPacket()),
520 WithDefaultWeekFormatMode(ctx.GetDefaultWeekFormatMode()),
521 WithDivPrecisionIncrement(ctx.GetDivPrecisionIncrement()),
522 WithParamList(params),
523 WithUserVarsReader(ctx.GetUserVarsReader().Clone()),
524 WithOptionalProperty(props...),
525 WithEnableRedactLog(ctx.GetTiDBRedactLog()),
526 )
527
528 return staticCtx
529}

Callers 3

IntoStaticMethod · 0.92
MakeExprContextStaticFunction · 0.85

Calls 15

AppendMethod · 0.95
NewPlanCacheParamListFunction · 0.92
WithWarnHandlerFunction · 0.85
WithSQLModeFunction · 0.85
WithTypeFlagsFunction · 0.85
WithLocationFunction · 0.85
WithErrLevelMapFunction · 0.85
WithCurrentDBFunction · 0.85
WithCurrentTimeFunction · 0.85
WithMaxAllowedPacketFunction · 0.85

Tested by 1