Skip to content

Commit

Permalink
expression: don't append null when param for char() is null (#30236)
Browse files Browse the repository at this point in the history
  • Loading branch information
Defined2014 committed Dec 2, 2021
1 parent 6898975 commit 004382d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 0 additions & 1 deletion expression/builtin_string_vec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2287,7 +2287,6 @@ func (b *builtinCharSig) vecEvalString(input *chunk.Chunk, result *chunk.Column)
bigints = bigints[0:0]
for j := 0; j < l-1; j++ {
if buf[j].IsNull(i) {
result.AppendNull()
continue
}
bigints = append(bigints, bufint[j][i])
Expand Down
6 changes: 6 additions & 0 deletions expression/builtin_string_vec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,12 @@ var vecBuiltinStringCases = map[string][]vecExprBenchCase{
geners: []dataGenerator{&charInt64Gener{}, &charInt64Gener{}, &charInt64Gener{}, nil},
constants: []*Constant{nil, nil, nil, {Value: types.NewDatum("ascii"), RetType: types.NewFieldType(mysql.TypeString)}},
},
{
retEvalType: types.ETString,
childrenTypes: []types.EvalType{types.ETInt, types.ETInt, types.ETInt, types.ETString},
geners: []dataGenerator{&charInt64Gener{}, nil, &charInt64Gener{}, nil},
constants: []*Constant{nil, nil, nil, {Value: types.NewDatum("ascii"), RetType: types.NewFieldType(mysql.TypeString)}},
},
},
ast.FindInSet: {
{retEvalType: types.ETInt, childrenTypes: []types.EvalType{types.ETString, types.ETString}},
Expand Down
12 changes: 12 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10649,6 +10649,18 @@ func (s *testIntegrationSuite) TestIssue29513(c *C) {
tk.MustQuery("select '123' union select cast(a as char(2)) from t;").Sort().Check(testkit.Rows("123", "45"))
}

func (s *testIntegrationSuite) TestIssue29755(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")

tk.MustExec("set tidb_enable_vectorized_expression = on;")
tk.MustQuery("select char(123, NULL, 123)").Check(testkit.Rows("{{"))
tk.MustQuery("select char(NULL, 123, 123)").Check(testkit.Rows("{{"))
tk.MustExec("set tidb_enable_vectorized_expression = off;")
tk.MustQuery("select char(123, NULL, 123)").Check(testkit.Rows("{{"))
tk.MustQuery("select char(NULL, 123, 123)").Check(testkit.Rows("{{"))
}

func (s *testIntegrationSuite) TestIssue30101(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down

0 comments on commit 004382d

Please sign in to comment.