Skip to content

Commit

Permalink
expression: implement vectorized evaluation for builtinSetVarSig an…
Browse files Browse the repository at this point in the history
…d `builtinGetVarSig` (#13181)
  • Loading branch information
mmyj authored and sre-bot committed Nov 9, 2019
1 parent b7eddbf commit 9edc272
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 6 deletions.
68 changes: 64 additions & 4 deletions expression/builtin_other_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
package expression

import (
"strings"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/stringutil"
)

func (b *builtinValuesIntSig) vectorized() bool {
Expand Down Expand Up @@ -91,11 +95,42 @@ func (b *builtinGetParamStringSig) vecEvalString(input *chunk.Chunk, result *chu
}

func (b *builtinSetVarSig) vectorized() bool {
return false
return true
}

func (b *builtinSetVarSig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()
buf0, err := b.bufAllocator.get(types.ETString, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf0)
if err := b.args[0].VecEvalString(b.ctx, input, buf0); err != nil {
return err
}
buf1, err := b.bufAllocator.get(types.ETString, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf1)
if err := b.args[1].VecEvalString(b.ctx, input, buf1); err != nil {
return err
}
result.ReserveString(n)
sessionVars := b.ctx.GetSessionVars()
sessionVars.UsersLock.Lock()
defer sessionVars.UsersLock.Unlock()
for i := 0; i < n; i++ {
if buf0.IsNull(i) || buf1.IsNull(i) {
result.AppendNull()
continue
}
varName := strings.ToLower(buf0.GetString(i))
res := buf1.GetString(i)
sessionVars.Users[varName] = stringutil.Copy(res)
result.AppendString(res)
}
return nil
}

func (b *builtinValuesDecimalSig) vectorized() bool {
Expand All @@ -107,9 +142,34 @@ func (b *builtinValuesDecimalSig) vecEvalDecimal(input *chunk.Chunk, result *chu
}

func (b *builtinGetVarSig) vectorized() bool {
return false
return true
}

func (b *builtinGetVarSig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()
buf0, err := b.bufAllocator.get(types.ETString, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf0)
if err := b.args[0].VecEvalString(b.ctx, input, buf0); err != nil {
return err
}
result.ReserveString(n)
sessionVars := b.ctx.GetSessionVars()
sessionVars.UsersLock.Lock()
defer sessionVars.UsersLock.Unlock()
for i := 0; i < n; i++ {
if buf0.IsNull(i) {
result.AppendNull()
continue
}
varName := strings.ToLower(buf0.GetString(i))
if v, ok := sessionVars.Users[varName]; ok {
result.AppendString(v)
continue
}
result.AppendNull()
}
return nil
}
9 changes: 7 additions & 2 deletions expression/builtin_other_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@ import (

. "github.com/pingcap/check"
"github.com/pingcap/parser/ast"
"github.com/pingcap/tidb/types"
)

var vecBuiltinOtherCases = map[string][]vecExprBenchCase{
ast.SetVar: {},
ast.GetVar: {},
ast.SetVar: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString}},
},
ast.GetVar: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString}},
},
ast.BitCount: {},
ast.GetParam: {},
}
Expand Down

0 comments on commit 9edc272

Please sign in to comment.