From 648bed40d3ab2bd7a666efc8ef745857b06e6445 Mon Sep 17 00:00:00 2001 From: Zhongyang Wu Date: Mon, 4 Nov 2019 23:43:39 -0500 Subject: [PATCH] expression: implement vectorized evaluation for `builtinCRC32Sig` (#13126) --- expression/builtin_math_vec.go | 22 ++++++++++++++++++++-- expression/builtin_math_vec_test.go | 3 +++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/expression/builtin_math_vec.go b/expression/builtin_math_vec.go index 571df82255..def5de04b6 100644 --- a/expression/builtin_math_vec.go +++ b/expression/builtin_math_vec.go @@ -15,6 +15,7 @@ package expression import ( "fmt" + "hash/crc32" "math" "strconv" @@ -658,11 +659,28 @@ func (b *builtinRoundWithFracIntSig) vectorized() bool { return true } func (b *builtinCRC32Sig) vectorized() bool { - return false + return true } func (b *builtinCRC32Sig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error { - return errors.Errorf("not implemented") + n := input.NumRows() + buf, err := b.bufAllocator.get(types.ETString, n) + if err != nil { + return err + } + defer b.bufAllocator.put(buf) + if err := b.args[0].VecEvalString(b.ctx, input, buf); err != nil { + return err + } + result.ResizeInt64(n, false) + i64s := result.Int64s() + result.MergeNulls(buf) + for i := range i64s { + if !buf.IsNull(i) { + i64s[i] = int64(crc32.ChecksumIEEE(buf.GetBytes(i))) + } + } + return nil } func (b *builtinPISig) vectorized() bool { diff --git a/expression/builtin_math_vec_test.go b/expression/builtin_math_vec_test.go index 5a90a0f031..230372109d 100644 --- a/expression/builtin_math_vec_test.go +++ b/expression/builtin_math_vec_test.go @@ -110,6 +110,9 @@ var vecBuiltinMathCases = map[string][]vecExprBenchCase{ {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, geners: []dataGenerator{nil, &rangeInt64Gener{-10, 10}}}, {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, childrenFieldTypes: []*types.FieldType{{Tp: mysql.TypeInt24, Flag: mysql.UnsignedFlag}}, geners: []dataGenerator{nil, &rangeInt64Gener{-10, 10}}}, }, + ast.CRC32: { + {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString}}, + }, } func (s *testEvaluatorSuite) TestVectorizedBuiltinMathEvalOneVec(c *C) {