Skip to content

Commit

Permalink
executor, planner: clone proj schema for different children in buildP…
Browse files Browse the repository at this point in the history
…roj4Union (pingcap#7999)
  • Loading branch information
XuHuaiyu committed Oct 23, 2018
1 parent 65f77f7 commit 61c57b7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,11 @@ func (s *testSuite) TestUnion(c *C) {
tk.MustExec(`set @@tidb_max_chunk_size=2;`)
tk.MustQuery(`select count(*) from (select t1.a, t1.b from t1 left join t2 on t1.a=t2.a union all select t1.a, t1.a from t1 left join t2 on t1.a=t2.a) tmp;`).Check(testkit.Rows("128"))
tk.MustQuery(`select tmp.a, count(*) from (select t1.a, t1.b from t1 left join t2 on t1.a=t2.a union all select t1.a, t1.a from t1 left join t2 on t1.a=t2.a) tmp;`).Check(testkit.Rows("1 128"))

tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int, b int)")
tk.MustExec("insert into t value(1 ,2)")
tk.MustQuery("select a, b from (select a, 0 as d, b from t union all select a, 0 as d, b from t) test;").Check(testkit.Rows("1 2", "1 2"))
}

func (s *testSuite) TestIn(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ func (b *planBuilder) buildProjection4Union(u *LogicalUnionAll) {
}
b.optFlag |= flagEliminateProjection
proj := LogicalProjection{Exprs: exprs}.init(b.ctx)
proj.SetSchema(expression.NewSchema(unionCols...))
proj.SetSchema(u.schema.Clone())
proj.SetChildren(child)
u.children[childID] = proj
}
Expand Down

0 comments on commit 61c57b7

Please sign in to comment.