Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: implement vectorized evaluation for builtinLogicAndSig #12336

Merged
merged 12 commits into from
Sep 25, 2019
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()
zz-jason marked this conversation as resolved.
Show resolved Hide resolved

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
}

Reminiscent marked this conversation as resolved.
Show resolved Hide resolved
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