Skip to content

Commit 76f84f4

Browse files
authored
executor, planner: clone proj schema for different children in buildProj4Union (#7999)
1 parent cc1b771 commit 76f84f4

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
@@ -1076,6 +1076,11 @@ func (s *testSuite) TestUnion(c *C) {
10761076
tk.MustExec(`set @@tidb_max_chunk_size=2;`)
10771077
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"))
10781078
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"))
1079+
1080+
tk.MustExec("drop table if exists t")
1081+
tk.MustExec("create table t(a int, b int)")
1082+
tk.MustExec("insert into t value(1 ,2)")
1083+
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"))
10791084
}
10801085

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

planner/core/logical_plan_builder.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ func (b *PlanBuilder) buildProjection4Union(u *LogicalUnionAll) {
712712
}
713713
b.optFlag |= flagEliminateProjection
714714
proj := LogicalProjection{Exprs: exprs}.init(b.ctx)
715-
proj.SetSchema(expression.NewSchema(unionCols...))
715+
proj.SetSchema(u.schema.Clone())
716716
proj.SetChildren(child)
717717
u.children[childID] = proj
718718
}

0 commit comments

Comments
 (0)