Skip to content

Commit

Permalink
expression: implement vectorized evaluation for builtinLogicXorSig (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
k-ye authored and sre-bot committed Sep 27, 2019
1 parent 095bee9 commit 8379a1c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
35 changes: 33 additions & 2 deletions expression/builtin_op_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,42 @@ func (b *builtinBitXorSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column)
}

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

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

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[1].VecEvalInt(b.ctx, input, buf); err != nil {
return err
}

i64s := result.Int64s()
arg1s := buf.Int64s()
// Returns NULL if either operand is NULL.
// See https://dev.mysql.com/doc/refman/5.7/en/logical-operators.html#operator_xor
result.MergeNulls(buf)
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}
arg0 := i64s[i]
arg1 := arg1s[i]
if (arg0 != 0 && arg1 != 0) || (arg0 == 0 && arg1 == 0) {
i64s[i] = 0
} else {
i64s[i] = 1
}
}
return nil
}

func (b *builtinBitAndSig) vectorized() bool {
Expand Down
14 changes: 7 additions & 7 deletions expression/builtin_op_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ var vecBuiltinOpCases = map[string][]vecExprBenchCase{
ast.IsTruth: {},
ast.IsFalsity: {},
ast.LogicOr: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: makeBinaryLogicOpDataGens()},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: makeBinaryLogicOpDataGeners()},
},
ast.LogicXor: {},
ast.Xor: {},
ast.LogicXor: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: makeBinaryLogicOpDataGeners()},
},
ast.Xor: {},
ast.LogicAnd: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: makeBinaryLogicOpDataGens()},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: makeBinaryLogicOpDataGeners()},
},
ast.UnaryNot: {},
ast.UnaryMinus: {},
Expand Down Expand Up @@ -62,9 +64,7 @@ func makeGivenValsOrDefaultGener(vals []interface{}, eType types.EvalType) *give
return g
}

func makeBinaryLogicOpDataGens() []dataGenerator {
// TODO: This data generator currently only applies to AND and OR operators,
// so its name may be too generic.
func makeBinaryLogicOpDataGeners() []dataGenerator {
pairs := [][]interface{}{
{nil, nil},
{0, nil},
Expand Down

0 comments on commit 8379a1c

Please sign in to comment.