Skip to content

Commit

Permalink
planner, expression: fix simplify outer join with cast (pingcap#12701)
Browse files Browse the repository at this point in the history
  • Loading branch information
justarandomstring authored and imtbkcat committed Nov 13, 2019
1 parent 22edd4c commit ba5835c
Show file tree
Hide file tree
Showing 4 changed files with 1,783 additions and 1 deletion.
2 changes: 1 addition & 1 deletion expression/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func EvaluateExprWithNull(ctx sessionctx.Context, schema *Schema, expr Expressio
for i, arg := range x.GetArgs() {
args[i] = EvaluateExprWithNull(ctx, schema, arg)
}
return NewFunctionInternal(ctx, x.FuncName.L, types.NewFieldType(mysql.TypeTiny), args...)
return NewFunctionInternal(ctx, x.FuncName.L, x.RetType, args...)
case *Column:
if !schema.Contains(x) {
return x
Expand Down
37 changes: 37 additions & 0 deletions planner/core/physical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1393,3 +1393,40 @@ func (s *testPlanSuite) TestUnmatchedTableInHint(c *C) {
}
}
}

func (s *testPlanSuite) TestSimplifyOuterJoinWithCast(c *C) {
defer testleak.AfterTest(c)()
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
defer func() {
dom.Close()
store.Close()
}()
se, err := session.CreateSession4Test(store)
c.Assert(err, IsNil)
_, err = se.Execute(context.Background(), "use test")
c.Assert(err, IsNil)

var input []string
var output []struct {
SQL string
Best string
}
s.testData.GetTestCases(c, &input, &output)
for i, test := range input {
comment := Commentf("case:%v sql:%s", i, test)
stmt, err := s.ParseOneStmt(test, "", "")
c.Assert(err, IsNil, comment)

p, err := planner.Optimize(context.Background(), se, stmt, s.is)
c.Assert(err, IsNil)
s.testData.OnRecord(func() {
output[i].SQL = test
output[i].Best = core.ToString(p)
})
c.Assert(core.ToString(p), Equals, output[i].Best)

warnings := se.GetSessionVars().StmtCtx.GetWarnings()
c.Assert(warnings, HasLen, 0, comment)
}
}
Loading

0 comments on commit ba5835c

Please sign in to comment.