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 (#7999) (#8007)
  • Loading branch information
XuHuaiyu authored and zz-jason committed Oct 23, 2018
1 parent 096d2b2 commit 4741e6b
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 @@ -1039,6 +1039,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 4741e6b

Please sign in to comment.