Skip to content

Commit

Permalink
planner: reset not null flag when Apply convert to Join (#19567)
Browse files Browse the repository at this point in the history
  • Loading branch information
wshwsh12 authored Aug 31, 2020
1 parent 1a3103a commit 27ea908
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
13 changes: 13 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7114,3 +7114,16 @@ func (s *testIntegrationSerialSuite) TestIssue17063(c *C) {
tk.MustQuery(`select collation(lag(b, 1, 'B') over w) from t window w as (order by b);`).Check(testkit.Rows("utf8mb4_general_ci", "utf8mb4_general_ci"))
tk.MustQuery(`select coercibility(lag(b, 1, 'B') over w) from t window w as (order by b);`).Check(testkit.Rows("2", "2"))
}

func (s *testIntegrationSuite) TestIssue19504(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1;")
tk.MustExec("create table t1 (c_int int, primary key (c_int));")
tk.MustExec("insert into t1 values (1), (2), (3);")
tk.MustExec("drop table if exists t2;")
tk.MustExec("create table t2 (c_int int, primary key (c_int));")
tk.MustExec("insert into t2 values (1);")
tk.MustQuery("select (select count(c_int) from t2 where c_int = t1.c_int) c1, (select count(1) from t2 where c_int = t1.c_int) c2 from t1;").
Check(testkit.Rows("1 1", "0 0", "0 0"))
}
14 changes: 12 additions & 2 deletions planner/core/rule_decorrelate.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,19 @@ func (s *decorrelateSolver) optimize(ctx context.Context, p LogicalPlan) (Logica
outerCol.RetType = first.RetTp
outerColsInSchema = append(outerColsInSchema, outerCol)
}
newAggFuncs = append(newAggFuncs, agg.AggFuncs...)
agg.AggFuncs = newAggFuncs
apply.SetSchema(expression.MergeSchema(expression.NewSchema(outerColsInSchema...), innerPlan.Schema()))
resetNotNullFlag(apply.schema, outerPlan.Schema().Len(), apply.schema.Len())

for i, aggFunc := range agg.AggFuncs {
if idx := apply.schema.ColumnIndex(aggFunc.Args[0].(*expression.Column)); idx != -1 {
desc, err := aggregation.NewAggFuncDesc(agg.ctx, agg.AggFuncs[i].Name, []expression.Expression{apply.schema.Columns[idx]}, false)
if err != nil {
return nil, err
}
newAggFuncs = append(newAggFuncs, desc)
}
}
agg.AggFuncs = newAggFuncs
np, err := s.optimize(ctx, p)
if err != nil {
return nil, err
Expand Down

0 comments on commit 27ea908

Please sign in to comment.