Skip to content

Commit

Permalink
expression: implement vectorized evaluation for builtinLengthSig (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
b41sh authored and ngaut committed Oct 14, 2019
1 parent 4634cff commit ea06d14
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
26 changes: 24 additions & 2 deletions expression/builtin_string_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -812,11 +812,33 @@ func (b *builtinInstrBinarySig) vecEvalInt(input *chunk.Chunk, result *chunk.Col
}

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

// vecEvalInt evaluates a builtinLengthSig.
// See https://dev.mysql.com/doc/refman/5.7/en/string-functions.html
func (b *builtinLengthSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()
buf, err := b.bufAllocator.get(types.ETString, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf)
if err := b.args[0].VecEvalString(b.ctx, input, buf); err != nil {
return err
}

result.ResizeInt64(n, false)
result.MergeNulls(buf)
i64s := result.Int64s()
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}
str := buf.GetBytes(i)
i64s[i] = int64(len(str))
}
return nil
}

func (b *builtinLocate2ArgsSig) vectorized() bool {
Expand Down
4 changes: 3 additions & 1 deletion expression/builtin_string_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import (
)

var vecBuiltinStringCases = map[string][]vecExprBenchCase{
ast.Length: {},
ast.Length: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString}, geners: []dataGenerator{&defaultGener{0.2, types.ETString}}},
},
ast.ASCII: {},
ast.Concat: {},
ast.ConcatWS: {},
Expand Down

0 comments on commit ea06d14

Please sign in to comment.