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

Function NewExprContext

pkg/expression/exprstatic/exprctx.go:151–190  ·  view source on GitHub ↗

NewExprContext creates a new ExprContext

(opts ...ExprCtxOption)

Source from the content-addressed store, hash-verified

149
150// NewExprContext creates a new ExprContext
151func NewExprContext(opts ...ExprCtxOption) *ExprContext {
152 cs, err := charset.GetCharsetInfo(mysql.DefaultCharset)
153 intest.AssertNoError(err)
154
155 ctx := &ExprContext{
156 exprCtxState: exprCtxState{
157 charset: cs.Name,
158 collation: cs.DefaultCollation,
159 defaultCollationForUTF8MB4: mysql.DefaultCollationName,
160 blockEncryptionMode: variable.DefBlockEncryptionMode,
161 sysDateIsNow: variable.DefSysdateIsNow,
162 noopFuncsMode: variable.TiDBOptOnOffWarn(variable.DefTiDBEnableNoopFuncs),
163 windowingUseHighPrecision: true,
164 groupConcatMaxLen: variable.DefGroupConcatMaxLen,
165 },
166 }
167 for _, opt := range opts {
168 opt(&ctx.exprCtxState)
169 }
170
171 if ctx.evalCtx == nil {
172 ctx.evalCtx = NewEvalContext()
173 }
174
175 if ctx.rng == nil {
176 ctx.rng = mathutil.NewWithTime()
177 }
178
179 if ctx.columnIDAllocator == nil {
180 ctx.columnIDAllocator = exprctx.NewSimplePlanColumnIDAllocator(0)
181 }
182
183 if ctx.planCacheTracker == nil {
184 cacheTracker := contextutil.NewPlanCacheTracker(ctx.evalCtx)
185 ctx.planCacheTracker = &cacheTracker
186 ctx.planCacheTracker.EnablePlanCache()
187 }
188
189 return ctx
190}
191
192// Apply returns a new `ExprContext` with the fields updated according to the given options.
193func (ctx *ExprContext) Apply(opts ...ExprCtxOption) *ExprContext {

Callers 15

TestBuildExpressionFunction · 0.92
TestContextDetachFunction · 0.92
EvalExpireTimeFunction · 0.92
ToConstraintFunction · 0.92
NewPartitionExprBuildCtxFunction · 0.92
TestDetachExecutorFunction · 0.92
newReorgExprCtxFunction · 0.92
newLitExprContextFunction · 0.92
TestMetaBuildContextFunction · 0.92
NewContextFunction · 0.92

Calls 8

GetCharsetInfoFunction · 0.92
AssertNoErrorFunction · 0.92
TiDBOptOnOffWarnFunction · 0.92
NewWithTimeFunction · 0.92
optStruct · 0.85
EnablePlanCacheMethod · 0.80
NewEvalContextFunction · 0.70

Tested by 12

TestBuildExpressionFunction · 0.74
TestContextDetachFunction · 0.74
TestDetachExecutorFunction · 0.74
TestMetaBuildContextFunction · 0.74
TestContextDetachFunction · 0.74
TestNewStaticExprCtxFunction · 0.56