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 builtinInstrBinarySig #13446

Merged
merged 4 commits into from
Nov 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
expression:implement vectorized evaluation for builtinInstrBinarySig
  • Loading branch information
icditwang committed Nov 14, 2019
commit 0b5fb4de61092935607cb444fcfba559bb950c70
37 changes: 35 additions & 2 deletions expression/builtin_string_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -1420,11 +1420,44 @@ func (b *builtinOrdSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) err
}

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

func (b *builtinInstrBinarySig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error {
return errors.Errorf("not implemented")
n := input.NumRows()
str, err := b.bufAllocator.get(types.ETString, n)
if err != nil {
return err
}
defer b.bufAllocator.put(str)
if err := b.args[0].VecEvalString(b.ctx, input, str); err != nil {
return err
}
substr, err := b.bufAllocator.get(types.ETString, n)
if err != nil {
return err
}
defer b.bufAllocator.put(substr)
if err := b.args[1].VecEvalString(b.ctx, input, substr); err != nil {
return err
}
result.ResizeInt64(n, false)
result.MergeNulls(str, substr)
res := result.Int64s()
for i := 0; i < n; i++ {
if result.IsNull(i) {
continue
}
strI := str.GetString(i)
substrI := substr.GetString(i)
idx := strings.Index(strI, substrI)
if idx == -1 {
res[i] = 0
Copy link
Member

Choose a reason for hiding this comment

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

This state seems like equivalent to
res[i] = int64(idx + 1)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will remove it.Do I need to change the non-vec func?It has it also.

Copy link
Member

Choose a reason for hiding this comment

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

I think we don't need change that one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

continue
}
res[i] = int64(idx + 1)
}
return nil
}

func (b *builtinLengthSig) vectorized() bool {
Expand Down
22 changes: 22 additions & 0 deletions expression/builtin_string_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,28 @@ var vecBuiltinStringCases = map[string][]vecExprBenchCase{
},
},
},
ast.Instr: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString, types.ETString},
childrenFieldTypes: []*types.FieldType{
{Tp: mysql.TypeString, Flag: mysql.BinaryFlag, Collate: charset.CollationBin},
{Tp: mysql.TypeString, Flag: mysql.BinaryFlag, Collate: charset.CollationBin},
},
},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString, types.ETString},
childrenFieldTypes: []*types.FieldType{
{Tp: mysql.TypeString, Flag: mysql.BinaryFlag, Collate: charset.CollationBin},
{Tp: mysql.TypeString, Flag: mysql.BinaryFlag, Collate: charset.CollationBin},
},
geners: []dataGenerator{&constStrGener{"test,case"}, &constStrGener{"case"}},
},
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString, types.ETString},
childrenFieldTypes: []*types.FieldType{
{Tp: mysql.TypeString, Flag: mysql.BinaryFlag, Collate: charset.CollationBin},
{Tp: mysql.TypeString, Flag: mysql.BinaryFlag, Collate: charset.CollationBin},
},
geners: []dataGenerator{&constStrGener{"test,case"}, &constStrGener{""}},
},
},
}

func (s *testEvaluatorSuite) TestVectorizedBuiltinStringEvalOneVec(c *C) {
Expand Down