NewExprContext creates a new ExprContext
(opts ...ExprCtxOption)
| 149 | |
| 150 | // NewExprContext creates a new ExprContext |
| 151 | func 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. |
| 193 | func (ctx *ExprContext) Apply(opts ...ExprCtxOption) *ExprContext { |