From dbd7b61404b10bf9d701647c325f945e321e25f6 Mon Sep 17 00:00:00 2001 From: HuaiyuXu <391585975@qq.com> Date: Sat, 21 Jul 2018 10:52:44 +0800 Subject: [PATCH] plan, executor: check b.err after buildSort and buildLimit in builUnion (#7114) --- executor/prepared_test.go | 3 +++ plan/logical_plan_builder.go | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/executor/prepared_test.go b/executor/prepared_test.go index 0a919a904980e..64c74a90ad7e8 100644 --- a/executor/prepared_test.go +++ b/executor/prepared_test.go @@ -263,4 +263,7 @@ func (s *testSuite) TestPreparedNameResolver(c *C) { tk.MustExec("prepare stmt from 'select * from t limit ? offset ?'") _, err := tk.Exec("prepare stmt from 'select b from t'") c.Assert(err.Error(), Equals, "[planner:1054]Unknown column 'b' in 'field list'") + + _, err = tk.Exec("prepare stmt from '(select * FROM t) union all (select * FROM t) order by a limit ?'") + c.Assert(err.Error(), Equals, "[planner:1054]Unknown column 'a' in 'order clause'") } diff --git a/plan/logical_plan_builder.go b/plan/logical_plan_builder.go index dc10ceb4f278e..36723e7d7dfb7 100644 --- a/plan/logical_plan_builder.go +++ b/plan/logical_plan_builder.go @@ -701,9 +701,17 @@ func (b *planBuilder) buildUnion(union *ast.UnionStmt) LogicalPlan { if union.OrderBy != nil { unionPlan = b.buildSort(unionPlan, union.OrderBy.Items, nil) + if b.err != nil { + b.err = errors.Trace(b.err) + return nil + } } if union.Limit != nil { unionPlan = b.buildLimit(unionPlan, union.Limit) + if b.err != nil { + b.err = errors.Trace(b.err) + return nil + } } return unionPlan }