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

planner: reset not null flag when Apply convert to Join #19567

Merged
merged 6 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
13 changes: 13 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7113,3 +7113,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 {
first, err := aggregation.NewAggFuncDesc(agg.ctx, agg.AggFuncs[i].Name, []expression.Expression{apply.schema.Columns[idx]}, false)
wshwsh12 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, err
}
newAggFuncs = append(newAggFuncs, first)
}
}
agg.AggFuncs = newAggFuncs
np, err := s.optimize(ctx, p)
if err != nil {
return nil, err
Expand Down