Skip to content

Commit

Permalink
fix issue:pingcap#11102
Browse files Browse the repository at this point in the history
                                                            Unexcepted result in `SELECT ... CASE WHEN ... ELSE NULL...`
  • Loading branch information
wangxiaoyong committed Jul 5, 2019
1 parent 831f7d3 commit 80fae60
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions expression/constant_fold.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func init() {

specialNullRejectCheck = map[string]struct{}{
ast.NullEQ: struct{}{},
ast.Case: struct{}{},
ast.Case: struct{}{},
}
}

Expand Down Expand Up @@ -112,7 +112,7 @@ func foldConstant(expr Expression) (Expression, bool) {
isDeferredConst = isDeferredConst || isDeferred
}
if !allConstArg {
_, ok := specialNullRejectCheck[x.FuncName.L]
_, ok := specialNullRejectCheck[x.FuncName.L]
if !hasNullArg || !sc.InNullRejectCheck || ok {
return expr, isDeferredConst
}
Expand Down
4 changes: 2 additions & 2 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2723,7 +2723,7 @@ func (s *testSessionSuite) TestLoadClientInteractive(c *C) {
tk.MustQuery("select @@wait_timeout").Check(testkit.Rows("28800"))
}

func (s *testSessionSuite) TestFuncCaseWithLeftJoin(c *C) {
func (s *testSessionSuite) TestFuncCaseWithLeftJoin(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)

tk.MustExec("create table kankan1(id int, name text)")
Expand All @@ -2733,7 +2733,7 @@ func (s *testSessionSuite) TestFuncCaseWithLeftJoin(c *C) {
tk.MustExec("create table kankan2(id int, h1 text)")
tk.MustExec("insert into kankan2 values(2, 'z')")

tk.MustQuery( "select * from (select t1.id, t2.h1, case when t1.name='b' then 'case2' when t1.name='a' then " +
tk.MustQuery("select * from (select t1.id, t2.h1, case when t1.name='b' then 'case2' when t1.name='a' then " +
"'case1' else null end as flag from kankan1 t1 left join kankan2 t2 on t1.id = t2.id) t3 where t3.flag='case1' " +
"order by t3.id").Check(testkit.Rows("1 <nil> case1", "2 z case1"))
}

0 comments on commit 80fae60

Please sign in to comment.