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 'builtinCoalesceJSONSig' #12915

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
41 changes: 39 additions & 2 deletions expression/builtin_compare_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/pingcap/errors"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/types/json"
"github.com/pingcap/tidb/util/chunk"
)

Expand Down Expand Up @@ -779,11 +780,47 @@ func (b *builtinLEDurationSig) vecEvalInt(input *chunk.Chunk, result *chunk.Colu
}

func (b *builtinCoalesceJSONSig) vectorized() bool {
return false
return true
}

func (b *builtinCoalesceJSONSig) vecEvalJSON(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
var buf *chunk.Column
var err error
n := input.NumRows()
res := make(map[int]*json.BinaryJSON)
Copy link
Contributor

Choose a reason for hiding this comment

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

Using map to record the reuslt is too slow. Any other idea?

result.ReserveJSON(n)
var count int
for _, a := range b.getArgs() {
buf, err = b.bufAllocator.get(types.ETJson, n)
if err != nil {
return err
}
defer b.bufAllocator.put(buf)
Copy link
Contributor

Choose a reason for hiding this comment

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

defer does not execute until the function return. So in this case, there will alloc len(b.getArgs()) columns and will be gc when this function return?

if err := a.VecEvalString(b.ctx, input, buf); err != nil {
return err
}

for i := 0; i < n; i++ {
if buf.IsNull(i) || res[i] != nil {
continue
}
js := buf.GetJSON(i)
res[i] = &js
count++
}
if count == n {
break
}
}

for i := 0; i < n; i++ {
if res[i] == nil {
result.AppendNull()
continue
}
result.AppendJSON(*res[i])
}
return nil
}

func (b *builtinGTRealSig) vectorized() bool {
Expand Down
16 changes: 11 additions & 5 deletions expression/builtin_compare_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ import (
)

var vecBuiltinCompareCases = map[string][]vecExprBenchCase{
ast.NE: {},
ast.IsNull: {},
ast.LE: {},
ast.LT: {},
ast.Coalesce: {},
ast.NE: {},
ast.IsNull: {},
ast.LE: {},
ast.LT: {},
ast.Coalesce: {
{retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETJson}},
{retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETJson, types.ETJson}},
{retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETJson, types.ETJson, types.ETJson}},
{retEvalType: types.ETJson, childrenTypes: []types.EvalType{types.ETJson, types.ETJson, types.ETJson},
geners: []dataGenerator{&defaultGener{1, types.ETJson}, &defaultGener{1, types.ETJson}, &defaultGener{1, types.ETJson}}},
},
ast.NullEQ: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETReal, types.ETReal}},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString, types.ETString}, geners: []dataGenerator{&randLenStrGener{10, 20}, &randLenStrGener{0, 20}}},
Expand Down