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 builtinAbsRealSig #12273

Merged
merged 6 commits into from
Sep 23, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions expression/builtin_math_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,21 @@ func (b *builtinPowSig) vectorized() bool {
return true
}

func (b *builtinAbsRealSig) vecEvalReal(input *chunk.Chunk, result *chunk.Column) error {
if err := b.args[0].VecEvalReal(b.ctx, input, result); err != nil {
return err
}
f64s := result.Float64s()
for i := 0; i < len(f64s); i++ {
f64s[i] = math.Abs(f64s[i])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be faster if we only calculate the non NULL values?

Copy link
Contributor Author

@tsthght tsthght Sep 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when only calculate the non NULL values, like that:
if result.IsNull(i) {
continue
}
BenchmarkVectorizedBuiltinMathFunc/builtinAbsRealSig-VecBuiltinFunc-8 500000 3210 ns/op 0 B/op 0 allocs/op

when calculate all values,
BenchmarkVectorizedBuiltinMathFunc/builtinAbsRealSig-VecBuiltinFunc-8 2000000 956 ns/op 0 B/op 0 allocs/op

so, calculate all values is falster.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

}
return nil
}

func (b *builtinAbsRealSig) vectorized() bool {
return true
}

func (b *builtinAbsIntSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error {
if err := b.args[0].VecEvalInt(b.ctx, input, result); err != nil {
return err
Expand Down
1 change: 1 addition & 0 deletions expression/builtin_math_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ var vecBuiltinMathCases = map[string][]vecExprBenchCase{
},
ast.Abs: {
{types.ETDecimal, []types.EvalType{types.ETDecimal}, nil},
{types.ETReal, []types.EvalType{types.ETReal}, nil},
{types.ETInt, []types.EvalType{types.ETInt}, nil},
},
ast.Round: {
Expand Down