expression: implement vectorized evaluation for `builtinTrunca… (#13317)

This commit is contained in:
庄天翼
2019-11-12 12:29:26 +08:00
committed by Zhang Jian
parent be39269da7
commit ec5e85f73c
2 changed files with 29 additions and 2 deletions

View File

@ -865,11 +865,37 @@ func (b *builtinFloorDecToDecSig) vecEvalDecimal(input *chunk.Chunk, result *chu
}
func (b *builtinTruncateDecimalSig) vectorized() bool {
return false
return true
}
func (b *builtinTruncateDecimalSig) vecEvalDecimal(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()
if err := b.args[0].VecEvalDecimal(b.ctx, input, result); err != nil {
return err
}
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
}
result.MergeNulls(buf)
ds := result.Decimals()
i64s := buf.Int64s()
ft := b.getRetTp().Decimal
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}
result := new(types.MyDecimal)
if err := ds[i].Round(result, mathutil.Min(int(i64s[i]), ft), types.ModeTruncate); err != nil {
return err
}
ds[i] = *result
}
return nil
}
func (b *builtinRoundWithFracDecSig) vectorized() bool {

View File

@ -109,6 +109,7 @@ var vecBuiltinMathCases = map[string][]vecExprBenchCase{
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETReal, types.ETInt}, geners: []dataGenerator{nil, &rangeInt64Gener{-10, 10}}},
{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}}},
{retEvalType: types.ETDecimal, childrenTypes: []types.EvalType{types.ETDecimal, types.ETInt}},
},
ast.Rand: {
{retEvalType: types.ETReal, childrenTypes: []types.EvalType{types.ETInt}, geners: []dataGenerator{&defaultGener{0, types.ETInt}}},