Skip to content

Commit

Permalink
expression: implement vectorized evaluation for `builtinLeastDecimalS…
Browse files Browse the repository at this point in the history
…ig` (#12150)
  • Loading branch information
hey-kong authored and sre-bot committed Sep 12, 2019
1 parent fb683be commit c153a5f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
35 changes: 35 additions & 0 deletions expression/builtin_compare_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,38 @@ func (b *builtinGreatestDecimalSig) vecEvalDecimal(input *chunk.Chunk, result *c
func (b *builtinGreatestDecimalSig) vectorized() bool {
return true
}

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

d64s := result.Decimals()
for j := 1; j < len(b.args); j++ {
if err := b.args[j].VecEvalDecimal(b.ctx, input, buf); err != nil {
return err
}

result.MergeNulls(buf)
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}
v := buf.GetDecimal(i)
if v.Compare(&d64s[i]) < 0 {
d64s[i] = *v
}
}
}
return nil
}

func (b *builtinLeastDecimalSig) vectorized() bool {
return true
}
3 changes: 3 additions & 0 deletions expression/builtin_compare_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ var vecBuiltinCompareCases = map[string][]vecExprBenchCase{
ast.Greatest: {
{types.ETDecimal, []types.EvalType{types.ETDecimal, types.ETDecimal, types.ETDecimal}, nil},
},
ast.Least: {
{types.ETDecimal, []types.EvalType{types.ETDecimal, types.ETDecimal, types.ETDecimal}, nil},
},
}

func (s *testEvaluatorSuite) TestVectorizedBuiltinCompareEvalOneVec(c *C) {
Expand Down

0 comments on commit c153a5f

Please sign in to comment.