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
66 changes: 66 additions & 0 deletions expression/builtin_op_vec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2019 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package expression

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

func (b *builtinLogicAndSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error {
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 {
i64s[i] = 0
continue
}

isNull1 := buf1.IsNull(i)
if !isNull1 && arg1[i] == 0 {
i64s[i] = 0
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 *builtinLogicAndSig) vectorized() bool {
return true
}
44 changes: 44 additions & 0 deletions expression/builtin_op_vec_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2019 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package expression

import (
"testing"

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

var vecBuiltinOpCases = map[string][]vecExprBenchCase{
ast.LogicAnd: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}},
},
}

func (s *testEvaluatorSuite) TestVectorizedBuiltinOpEvalOneVec(c *C) {
testVectorizedEvalOneVec(c, vecBuiltinOpCases)
}

func (s *testEvaluatorSuite) TestVectorizedBuiltinOpFunc(c *C) {
testVectorizedBuiltinFunc(c, vecBuiltinOpCases)
}

func BenchmarkVectorizedBuiltinOpEvalOneVec(b *testing.B) {
benchmarkVectorizedEvalOneVec(b, vecBuiltinOpCases)
}

func BenchmarkVectorizedBuiltinOpFunc(b *testing.B) {
benchmarkVectorizedBuiltinFunc(b, vecBuiltinOpCases)
}