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

executor: wrong result of nullif expr when used with is null expr. (#23170) #23279

Merged
merged 5 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 3 additions & 0 deletions expression/builtin_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ func InferType4ControlFuncs(lhs, rhs *types.FieldType) *types.FieldType {
resultFieldType := &types.FieldType{}
if lhs.Tp == mysql.TypeNull {
*resultFieldType = *rhs
// If any of arg is NULL, result type need unset NotNullFlag.
types.SetTypeFlag(&resultFieldType.Flag, mysql.NotNullFlag, false)
// If both arguments are NULL, make resulting type BINARY(0).
if rhs.Tp == mysql.TypeNull {
resultFieldType.Tp = mysql.TypeString
Expand All @@ -75,6 +77,7 @@ func InferType4ControlFuncs(lhs, rhs *types.FieldType) *types.FieldType {
}
} else if rhs.Tp == mysql.TypeNull {
*resultFieldType = *lhs
types.SetTypeFlag(&resultFieldType.Flag, mysql.NotNullFlag, false)
} else {
resultFieldType = types.AggFieldType([]*types.FieldType{lhs, rhs})
evalType := types.AggregateEvalType([]*types.FieldType{lhs, rhs}, &resultFieldType.Flag)
Expand Down
11 changes: 11 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3733,6 +3733,17 @@ func (s *testIntegrationSuite) TestCompareBuiltin(c *C) {
result.Check(testkit.Rows("0"))
}

// #23157: make sure if Nullif expr is correct combined with IsNull expr.
func (s *testIntegrationSuite) TestNullifWithIsNull(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int not null);")
tk.MustExec("insert into t values(1),(2);")
rows := tk.MustQuery("select * from t where nullif(a,a) is null;")
rows.Check(testkit.Rows("1", "2"))
}

func (s *testIntegrationSuite) TestAggregationBuiltin(c *C) {
defer s.cleanEnv(c)
tk := testkit.NewTestKit(c, s.store)
Expand Down