Skip to content

Commit

Permalink
implement vectorized evaluation for builtinRightBinarySig (#13144)
Browse files Browse the repository at this point in the history
  • Loading branch information
icditwang authored and ngaut committed Nov 5, 2019
1 parent e434442 commit ea4cafa
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
37 changes: 35 additions & 2 deletions expression/builtin_string_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -1587,11 +1587,44 @@ func (b *builtinFormatSig) vecEvalString(input *chunk.Chunk, result *chunk.Colum
}

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

func (b *builtinRightBinarySig) vecEvalString(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
}
buf2, err := b.bufAllocator.get(types.ETInt, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf2)
if err := b.args[1].VecEvalInt(b.ctx, input, buf2); err != nil {
return err
}
right := buf2.Int64s()
result.ReserveString(n)
for i := 0; i < n; i++ {
if buf.IsNull(i) || buf2.IsNull(i) {
result.AppendNull()
continue
}
str, rightLength := buf.GetString(i), int(right[i])
strLength := len(str)
if rightLength > strLength {
rightLength = strLength
} else if rightLength < 0 {
rightLength = 0
}
result.AppendString(str[strLength-rightLength:])
}
return nil
}

func (b *builtinSubstringBinary3ArgsSig) vectorized() bool {
Expand Down
9 changes: 9 additions & 0 deletions expression/builtin_string_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ var vecBuiltinStringCases = map[string][]vecExprBenchCase{
},
ast.Right: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETInt}},
// need to add BinaryFlag for the Binary func
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETInt},
childrenFieldTypes: []*types.FieldType{{Tp: mysql.TypeString, Flag: mysql.BinaryFlag, Collate: charset.CollationBin},
{Tp: mysql.TypeLonglong}},
geners: []dataGenerator{
&randLenStrGener{10, 20},
&rangeInt64Gener{begin: -10, end: 20},
},
},
},
ast.Left: {
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETInt}},
Expand Down

0 comments on commit ea4cafa

Please sign in to comment.