Skip to content

Commit

Permalink
expression: implement vectorized evaluation for `builtinLogicA… (#12336)
Browse files Browse the repository at this point in the history
  • Loading branch information
lauhg authored and zz-jason committed Sep 25, 2019
1 parent 7343287 commit e8ffaf1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
45 changes: 43 additions & 2 deletions expression/builtin_op_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package expression

import (
"github.com/pingcap/errors"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
)

Expand Down Expand Up @@ -107,11 +108,51 @@ func (b *builtinUnaryNotRealSig) vecEvalInt(input *chunk.Chunk, result *chunk.Co
}

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

func (b *builtinLogicAndSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()

if err := b.args[0].VecEvalInt(b.ctx, input, result); err != nil {
return err
}

buf1, err := b.bufAllocator.get(types.ETInt, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf1)
if err := b.args[1].VecEvalInt(b.ctx, input, buf1); err != nil {
return err
}

i64s := result.Int64s()
arg1 := buf1.Int64s()

for i := 0; i < n; i++ {
isNull0 := result.IsNull(i)
if !isNull0 && i64s[i] == 0 {
result.SetNull(i, false)
continue
}

isNull1 := buf1.IsNull(i)
if !isNull1 && arg1[i] == 0 {
i64s[i] = 0
result.SetNull(i, false)
continue
}

if isNull0 || isNull1 {
result.SetNull(i, true)
continue
}

i64s[i] = 1
}

return nil
}

func (b *builtinBitXorSig) vectorized() bool {
Expand Down
15 changes: 9 additions & 6 deletions expression/builtin_op_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ import (

. "github.com/pingcap/check"
"github.com/pingcap/parser/ast"
"github.com/pingcap/tidb/types"
)

var vecBuiltinOpCases = map[string][]vecExprBenchCase{
ast.IsTruth: {},
ast.IsFalsity: {},
ast.LogicOr: {},
ast.LogicXor: {},
ast.Xor: {},
ast.LogicAnd: {},
ast.IsTruth: {},
ast.IsFalsity: {},
ast.LogicOr: {},
ast.LogicXor: {},
ast.Xor: {},
ast.LogicAnd: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}},
},
ast.UnaryNot: {},
ast.UnaryMinus: {},
ast.IsNull: {},
Expand Down

0 comments on commit e8ffaf1

Please sign in to comment.