Skip to content

Commit

Permalink
expression: implement vectorized evaluation for builtinGreatestIntSig (
Browse files Browse the repository at this point in the history
  • Loading branch information
tangwz committed Sep 19, 2019
1 parent f9724db commit 0c81877
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions expression/builtin_compare_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,39 @@ func (b *builtinLeastDecimalSig) vecEvalDecimal(input *chunk.Chunk, result *chun
func (b *builtinLeastDecimalSig) vectorized() bool {
return true
}

func (b *builtinGreatestIntSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error {
n := input.NumRows()
buf, err := b.bufAllocator.get(types.ETInt, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf)
if err := b.args[0].VecEvalInt(b.ctx, input, result); err != nil {
return err
}

i64s := result.Int64s()
for j := 1; j < len(b.args); j++ {
if err := b.args[j].VecEvalInt(b.ctx, input, buf); err != nil {
return err
}
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
} else if buf.IsNull(i) {
result.SetNull(i, true)
continue
}
v := buf.GetInt64(i)
if v > i64s[i] {
i64s[i] = v
}
}
}
return nil
}

func (b *builtinGreatestIntSig) vectorized() bool {
return true
}
1 change: 1 addition & 0 deletions expression/builtin_compare_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
var vecBuiltinCompareCases = map[string][]vecExprBenchCase{
ast.Greatest: {
{types.ETDecimal, []types.EvalType{types.ETDecimal, types.ETDecimal, types.ETDecimal}, nil},
{types.ETInt, []types.EvalType{types.ETInt, types.ETInt, types.ETInt}, nil},
},
ast.Least: {
{types.ETDecimal, []types.EvalType{types.ETDecimal, types.ETDecimal, types.ETDecimal}, nil},
Expand Down

0 comments on commit 0c81877

Please sign in to comment.