diff --git a/expression/builtin_string_vec.go b/expression/builtin_string_vec.go index fcb78460e93f5..ec6e090c8a1ae 100644 --- a/expression/builtin_string_vec.go +++ b/expression/builtin_string_vec.go @@ -912,11 +912,38 @@ func (b *builtinRTrimSig) vecEvalString(input *chunk.Chunk, result *chunk.Column } func (b *builtinStrcmpSig) vectorized() bool { - return false + return true } func (b *builtinStrcmpSig) vecEvalInt(input *chunk.Chunk, result *chunk.Column) error { - return errors.Errorf("not implemented") + n := input.NumRows() + leftBuf, err := b.bufAllocator.get(types.ETString, n) + if err != nil { + return err + } + defer b.bufAllocator.put(leftBuf) + if err := b.args[0].VecEvalString(b.ctx, input, leftBuf); err != nil { + return err + } + rightBuf, err := b.bufAllocator.get(types.ETString, n) + if err != nil { + return err + } + defer b.bufAllocator.put(rightBuf) + if err := b.args[1].VecEvalString(b.ctx, input, rightBuf); err != nil { + return err + } + result.ResizeInt64(n, false) + result.MergeNulls(leftBuf, rightBuf) + i64s := result.Int64s() + for i := 0; i < n; i++ { + // if left or right is null, then set to null and return 0(which is the default value) + if result.IsNull(i) { + continue + } + i64s[i] = int64(types.CompareString(leftBuf.GetString(i), rightBuf.GetString(i))) + } + return nil } func (b *builtinLocateBinary2ArgsSig) vectorized() bool { diff --git a/expression/builtin_string_vec_test.go b/expression/builtin_string_vec_test.go index 0ef985e5b15d6..f095014a41e26 100644 --- a/expression/builtin_string_vec_test.go +++ b/expression/builtin_string_vec_test.go @@ -272,6 +272,21 @@ var vecBuiltinStringCases = map[string][]vecExprBenchCase{ }, }, }, + ast.Strcmp: { + {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString, types.ETString}}, + {retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString, types.ETString}, geners: []dataGenerator{ + &selectStringGener{ + candidates: []string{ + "test", + }, + }, + &selectStringGener{ + candidates: []string{ + "test", + }, + }, + }}, + }, } func (s *testEvaluatorSuite) TestVectorizedBuiltinStringEvalOneVec(c *C) {