From 95d133a60fa13769e2e405cbd2abb1f159307d1a Mon Sep 17 00:00:00 2001 From: Nithish Sankaranarayanan Date: Fri, 11 Oct 2019 07:37:03 +0200 Subject: [PATCH] expression: implement vectorized evaluation for 'builtinBitAndSig' (#12612) --- expression/builtin_op_vec.go | 22 ++++++++++++++++++++-- expression/builtin_op_vec_test.go | 3 +++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/expression/builtin_op_vec.go b/expression/builtin_op_vec.go index b08b977e0b..1b0ff760d4 100644 --- a/expression/builtin_op_vec.go +++ b/expression/builtin_op_vec.go @@ -370,11 +370,29 @@ func (b *builtinLogicXorSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column } func (b *builtinBitAndSig) vectorized() bool { - return false + return true } func (b *builtinBitAndSig) 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 + } + numRows := input.NumRows() + buf, err := b.bufAllocator.get(types.ETInt, numRows) + if err != nil { + return err + } + defer b.bufAllocator.put(buf) + if err := b.args[1].VecEvalInt(b.ctx, input, buf); err != nil { + return err + } + arg0s := result.Int64s() + arg1s := buf.Int64s() + result.MergeNulls(buf) + for i := 0; i < numRows; i++ { + arg0s[i] &= arg1s[i] + } + return nil } func (b *builtinRealIsFalseSig) vectorized() bool { diff --git a/expression/builtin_op_vec_test.go b/expression/builtin_op_vec_test.go index ca12bd1d6f..aa5ce9c2de 100644 --- a/expression/builtin_op_vec_test.go +++ b/expression/builtin_op_vec_test.go @@ -50,6 +50,9 @@ var vecBuiltinOpCases = map[string][]vecExprBenchCase{ {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETDecimal}}, {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt}}, }, + ast.And: { + {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: makeBinaryLogicOpDataGeners()}, + }, ast.UnaryMinus: {}, ast.IsNull: { {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETReal}},