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: Fix unexpected panic when using IF function. (#21132) #21711

Merged
merged 6 commits into from
Jan 27, 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
9 changes: 9 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7412,6 +7412,15 @@ func (s *testIntegrationSerialSuite) TestJsonObjectCompare(c *C) {
tk.MustQuery("select json_object('k', a) = json_object('k', b) from tx").Check(testkit.Rows("1"))
}

func (s *testIntegrationSuite2) TestIssue15847(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop view if exists t15847")
tk.MustExec("CREATE VIEW t15847(c0) AS SELECT NULL;")
tk.MustQuery("SELECT * FROM t15847 WHERE (NOT (IF(t15847.c0, NULL, NULL)));").Check(testkit.Rows())
tk.MustExec("drop view if exists t15847")
}

func (s *testIntegrationSerialSuite) TestIssue21290(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
8 changes: 7 additions & 1 deletion expression/scalar_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,13 @@ func newFunctionImpl(ctx sessionctx.Context, fold int, funcName string, retType
}
funcArgs := make([]Expression, len(args))
copy(funcArgs, args)
typeInferForNull(funcArgs)
switch funcName {
case ast.If, ast.Ifnull, ast.Nullif:
// Do nothing. Because it will call InferType4ControlFuncs.
default:
typeInferForNull(funcArgs)
}

f, err := fc.getFunction(ctx, funcArgs)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions expression/typeinfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1015,9 +1015,9 @@ func (s *testInferTypeSuite) createTestCase4CompareFuncs() []typeInferTestCase {
{"nullif(c_float_d , 123)", mysql.TypeFloat, charset.CharsetBin, mysql.BinaryFlag, 12, types.UnspecifiedLength},
{"nullif(c_double_d , 123)", mysql.TypeDouble, charset.CharsetBin, mysql.BinaryFlag, 22, types.UnspecifiedLength},
{"nullif(c_decimal , 123)", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, 6, 3},
{"nullif(c_datetime , 123)", mysql.TypeDatetime, charset.CharsetUTF8MB4, mysql.BinaryFlag, 22, 2},
{"nullif(c_time_d , 123)", mysql.TypeDuration, charset.CharsetUTF8MB4, mysql.BinaryFlag, 10, 0},
{"nullif(c_timestamp_d, 123)", mysql.TypeTimestamp, charset.CharsetUTF8MB4, mysql.BinaryFlag, 19, 0},
{"nullif(c_datetime , 123)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 22, 2},
{"nullif(c_time_d , 123)", mysql.TypeDuration, charset.CharsetBin, mysql.BinaryFlag, 10, 0},
{"nullif(c_timestamp_d, 123)", mysql.TypeTimestamp, charset.CharsetBin, mysql.BinaryFlag, 19, 0},
{"nullif(c_char , 123)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength},
{"nullif(c_varchar , 123)", mysql.TypeVarchar, charset.CharsetUTF8MB4, 0, 20, types.UnspecifiedLength}, // TODO: tp should be TypeVarString
{"nullif(c_text_d , 123)", mysql.TypeBlob, charset.CharsetUTF8MB4, 0, 65535, types.UnspecifiedLength}, // TODO: tp should be TypeMediumBlob
Expand Down