Skip to content

Commit

Permalink
expression: use parameter ctx to do evaluate instead of the inner one…
Browse files Browse the repository at this point in the history
… for all builtinFuncs (pingcap#48409)

close pingcap#48408
  • Loading branch information
lcwangchao authored Nov 14, 2023
1 parent 911334b commit 625dc4e
Show file tree
Hide file tree
Showing 58 changed files with 2,538 additions and 2,534 deletions.
2 changes: 1 addition & 1 deletion pkg/executor/aggfuncs/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func buildGroupConcat(ctx sessionctx.Context, aggFuncDesc *aggregation.AggFuncDe
default:
// The last arg is promised to be a not-null string constant, so the error can be ignored.
c, _ := aggFuncDesc.Args[len(aggFuncDesc.Args)-1].(*expression.Constant)
sep, _, err := c.EvalString(nil, chunk.Row{})
sep, _, err := c.EvalString(ctx, chunk.Row{})
// This err should never happen.
if err != nil {
panic(fmt.Sprintf("Error happened when buildGroupConcat: %s", err.Error()))
Expand Down
1 change: 1 addition & 0 deletions pkg/expression/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ go_library(
"//pkg/util/encrypt",
"//pkg/util/generatedexpr",
"//pkg/util/hack",
"//pkg/util/intest",
"//pkg/util/intset",
"//pkg/util/logutil",
"//pkg/util/mathutil",
Expand Down
20 changes: 2 additions & 18 deletions pkg/expression/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import (
type baseBuiltinFunc struct {
bufAllocator columnBufferAllocator
args []Expression
ctx sessionctx.Context
tp *types.FieldType
pbCode tipb.ScalarFuncSig
ctor collate.Collator
Expand Down Expand Up @@ -125,7 +124,6 @@ func newBaseBuiltinFunc(ctx sessionctx.Context, funcName string, args []Expressi
childrenReversedOnce: new(sync.Once),

args: args,
ctx: ctx,
tp: tp,
}
bf.SetCharsetAndCollation(ec.Charset, ec.Collation)
Expand Down Expand Up @@ -213,7 +211,6 @@ func newBaseBuiltinFuncWithTp(ctx sessionctx.Context, funcName string, args []Ex
childrenReversedOnce: new(sync.Once),

args: args,
ctx: ctx,
tp: fieldType,
}
bf.SetCharsetAndCollation(ec.Charset, ec.Collation)
Expand Down Expand Up @@ -276,7 +273,6 @@ func newBaseBuiltinFuncWithFieldTypes(ctx sessionctx.Context, funcName string, a
childrenReversedOnce: new(sync.Once),

args: args,
ctx: ctx,
tp: fieldType,
}
bf.SetCharsetAndCollation(ec.Charset, ec.Collation)
Expand All @@ -300,7 +296,6 @@ func newBaseBuiltinFuncWithFieldType(ctx sessionctx.Context, tp *types.FieldType
childrenReversedOnce: new(sync.Once),

args: args,
ctx: ctx,
tp: tp,
}
bf.SetCharsetAndCollation(tp.GetCharset(), tp.GetCollate())
Expand Down Expand Up @@ -422,29 +417,24 @@ func (b *baseBuiltinFunc) getRetTp() *types.FieldType {
return b.tp
}

func (b *baseBuiltinFunc) equal(_ sessionctx.Context, fun builtinFunc) bool {
func (b *baseBuiltinFunc) equal(ctx sessionctx.Context, fun builtinFunc) bool {
funArgs := fun.getArgs()
if len(funArgs) != len(b.args) {
return false
}
for i := range b.args {
if !b.args[i].Equal(b.ctx, funArgs[i]) {
if !b.args[i].Equal(ctx, funArgs[i]) {
return false
}
}
return true
}

func (b *baseBuiltinFunc) getCtx() sessionctx.Context {
return b.ctx
}

func (b *baseBuiltinFunc) cloneFrom(from *baseBuiltinFunc) {
b.args = make([]Expression, 0, len(b.args))
for _, arg := range from.args {
b.args = append(b.args, arg.Clone())
}
b.ctx = from.ctx
b.tp = from.tp
b.pbCode = from.pbCode
b.bufAllocator = newLocalColumnPool()
Expand Down Expand Up @@ -550,8 +540,6 @@ type builtinFunc interface {
getArgs() []Expression
// equal check if this function equals to another function.
equal(sessionctx.Context, builtinFunc) bool
// getCtx returns this function's context.
getCtx() sessionctx.Context
// getRetTp returns the return type of the built-in function.
getRetTp() *types.FieldType
// setPbCode sets pbCode for signature.
Expand All @@ -574,10 +562,6 @@ type builtinFunc interface {
CollationInfo
}

type builtinFuncNew interface {
evalIntWithCtx(ctx sessionctx.Context, row chunk.Row) (val int64, isNull bool, err error)
}

// baseFunctionClass will be contained in every struct that implement functionClass interface.
type baseFunctionClass struct {
funcName string
Expand Down
Loading

0 comments on commit 625dc4e

Please sign in to comment.