Skip to content

Commit

Permalink
expression: implement vectorized evaluation for builtinLikeSig (#13644
Browse files Browse the repository at this point in the history
)
  • Loading branch information
pingyu authored and sre-bot committed Nov 21, 2019
1 parent 567f0d4 commit 3ad9d3b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
48 changes: 46 additions & 2 deletions expression/builtin_like_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,58 @@ import (
"github.com/pingcap/errors"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/stringutil"
)

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

func (b *builtinLikeSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()
bufVal, err := b.bufAllocator.get(types.ETString, n)
if err != nil {
return err
}
defer b.bufAllocator.put(bufVal)
if err = b.args[0].VecEvalString(b.ctx, input, bufVal); err != nil {
return err
}

bufPattern, err := b.bufAllocator.get(types.ETString, n)
if err != nil {
return err
}
defer b.bufAllocator.put(bufPattern)
if err = b.args[1].VecEvalString(b.ctx, input, bufPattern); err != nil {
return err
}

bufEscape, err := b.bufAllocator.get(types.ETInt, n)
if err != nil {
return err
}
defer b.bufAllocator.put(bufEscape)
if err = b.args[2].VecEvalInt(b.ctx, input, bufEscape); err != nil {
return err
}
escapes := bufEscape.Int64s()

result.ResizeInt64(n, false)
result.MergeNulls(bufVal, bufPattern, bufEscape)
i64s := result.Int64s()
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}

escape := byte(escapes[i])
patChars, patTypes := stringutil.CompilePattern(bufPattern.GetString(i), escape)
match := stringutil.DoMatch(bufVal.GetString(i), patChars, patTypes)
i64s[i] = boolToInt64(match)
}

return nil
}

func (b *builtinRegexpBinarySig) vectorized() bool {
Expand Down
6 changes: 5 additions & 1 deletion expression/builtin_like_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import (
)

var vecBuiltinLikeCases = map[string][]vecExprBenchCase{
ast.Like: {},
ast.Like: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString, types.ETString, types.ETInt},
geners: []dataGenerator{nil, nil, &rangeInt64Gener{int('\\'), int('\\') + 1}},
},
},
ast.Regexp: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString, types.ETString}},
},
Expand Down

0 comments on commit 3ad9d3b

Please sign in to comment.