From 089895a574353bd404edf217de0ffa3effda76eb Mon Sep 17 00:00:00 2001 From: tsthght <781181214@qq.com> Date: Sat, 2 Nov 2019 21:43:34 +0800 Subject: [PATCH] expression: implement vectorized evaluation for 'builtinGTIntSig' (#13074) --- expression/builtin_compare_vec.go | 39 ++++++++++++++++++++++++-- expression/builtin_compare_vec_test.go | 25 ++++++++++++++--- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/expression/builtin_compare_vec.go b/expression/builtin_compare_vec.go index 9ef2432bd9..815d9b876b 100644 --- a/expression/builtin_compare_vec.go +++ b/expression/builtin_compare_vec.go @@ -275,11 +275,35 @@ func (b *builtinNEIntSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) e } func (b *builtinGTIntSig) vectorized() bool { - return false + return true } func (b *builtinGTIntSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error { - return errors.Errorf("not implemented") + n := input.NumRows() + var err error + var buf0, buf1 *chunk.Column + buf0, err = b.bufAllocator.get(types.ETInt, n) + if err != nil { + return err + } + defer b.bufAllocator.put(buf0) + if err := b.args[0].VecEvalInt(b.ctx, input, buf0); 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 + } + + result.ResizeInt64(n, false) + vecCompareInt(mysql.HasUnsignedFlag(b.args[0].GetType().Flag), mysql.HasUnsignedFlag(b.args[1].GetType().Flag), buf0, buf1, result) + result.MergeNulls(buf0, buf1) + vecResOfGT(result.Int64s()) + return nil } func (b *builtinCoalesceDurationSig) vectorized() bool { @@ -432,6 +456,17 @@ func vecResOfLT(res []int64) { } } +func vecResOfGT(res []int64) { + n := len(res) + for i := 0; i < n; i++ { + if res[i] > 0 { + res[i] = 1 + } else { + res[i] = 0 + } + } +} + //vecCompareInt is vectorized CompareInt() func vecCompareInt(isUnsigned0, isUnsigned1 bool, largs, rargs, result *chunk.Column) { switch { diff --git a/expression/builtin_compare_vec_test.go b/expression/builtin_compare_vec_test.go index 3466a4bb0b..65ecebb526 100644 --- a/expression/builtin_compare_vec_test.go +++ b/expression/builtin_compare_vec_test.go @@ -46,10 +46,27 @@ var vecBuiltinCompareCases = map[string][]vecExprBenchCase{ }, ast.Coalesce: {}, ast.NullEQ: {}, - ast.GT: {}, - ast.EQ: {}, - ast.GE: {}, - ast.Date: {}, + ast.GT: { + {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}}, + {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, + childrenFieldTypes: []*types.FieldType{{Tp: mysql.TypeLonglong, Flag: mysql.UnsignedFlag}, + {Tp: mysql.TypeLonglong, Flag: mysql.UnsignedFlag}, + }, + }, + {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, + childrenFieldTypes: []*types.FieldType{{Tp: mysql.TypeLonglong}, + {Tp: mysql.TypeLonglong, Flag: mysql.UnsignedFlag}, + }, + }, + {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt}, + childrenFieldTypes: []*types.FieldType{{Tp: mysql.TypeLonglong, Flag: mysql.UnsignedFlag}, + {Tp: mysql.TypeLonglong}, + }, + }, + }, + ast.EQ: {}, + ast.GE: {}, + ast.Date: {}, ast.Greatest: { {retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETDecimal, types.ETDecimal}}, {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETInt, types.ETInt, types.ETInt}},