Skip to content

Commit

Permalink
expression: implement vectorized evaluation for `builtinGreatestStrin…
Browse files Browse the repository at this point in the history
…gSig` (pingcap#12778)
  • Loading branch information
mmyj authored and qw4990 committed Oct 21, 2019
1 parent 691199b commit 6182871
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
47 changes: 45 additions & 2 deletions expression/builtin_compare_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,11 +902,54 @@ func (b *builtinNullEQDurationSig) vecEvalInt(input *chunk.Chunk, result *chunk.
}

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

func (b *builtinGreatestStringSig) vecEvalString(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
if err := b.args[0].VecEvalString(b.ctx, input, result); err != nil {
return err
}

n := input.NumRows()
buf1, err := b.bufAllocator.get(types.ETString, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf1)
buf2, err := b.bufAllocator.get(types.ETString, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf2)

src := result
arg := buf1
dst := buf2
for j := 1; j < len(b.args); j++ {
if err := b.args[j].VecEvalString(b.ctx, input, arg); err != nil {
return err
}
for i := 0; i < n; i++ {
if src.IsNull(i) || arg.IsNull(i) {
dst.AppendNull()
continue
}
srcStr := src.GetString(i)
argStr := arg.GetString(i)
if types.CompareString(srcStr, argStr) > 0 {
dst.AppendString(srcStr)
} else {
dst.AppendString(argStr)
}
}
src, dst = dst, src
arg.ReserveString(n)
dst.ReserveString(n)
}
if len(b.args)%2 == 0 {
src.CopyConstruct(result)
}
return nil
}

func (b *builtinLTDurationSig) vectorized() bool {
Expand Down
2 changes: 2 additions & 0 deletions expression/builtin_compare_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ var vecBuiltinCompareCases = map[string][]vecExprBenchCase{
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal, types.ETDecimal}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt, types.ETInt}},
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETReal, types.ETReal}},
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString}},
{retEvalType: types.ETString, childrenTypes: []types.EvalType{types.ETString, types.ETString, types.ETString}},
},
ast.Least: {
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal, types.ETDecimal}},
Expand Down

0 comments on commit 6182871

Please sign in to comment.