Skip to content

Commit 4741e6b

Browse files
XuHuaiyuzz-jason
authored andcommitted
executor, planner: clone proj schema for different children in buildProj4Union (#7999) (#8007)
1 parent 096d2b2 commit 4741e6b

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

executor/executor_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,11 @@ func (s *testSuite) TestUnion(c *C) {
10391039
tk.MustExec(`set @@tidb_max_chunk_size=2;`)
10401040
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"))
10411041
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"))
1042+
1043+
tk.MustExec("drop table if exists t")
1044+
tk.MustExec("create table t(a int, b int)")
1045+
tk.MustExec("insert into t value(1 ,2)")
1046+
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"))
10421047
}
10431048

10441049
func (s *testSuite) TestIn(c *C) {

planner/core/logical_plan_builder.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ func (b *planBuilder) buildProjection4Union(u *LogicalUnionAll) {
678678
}
679679
b.optFlag |= flagEliminateProjection
680680
proj := LogicalProjection{Exprs: exprs}.init(b.ctx)
681-
proj.SetSchema(expression.NewSchema(unionCols...))
681+
proj.SetSchema(u.schema.Clone())
682682
proj.SetChildren(child)
683683
u.children[childID] = proj
684684
}

0 commit comments

Comments
 (0)