Skip to content

Commit

Permalink
plan, executor: check b.err after buildSort and buildLimit in builUni…
Browse files Browse the repository at this point in the history
…on (pingcap#7114)
  • Loading branch information
XuHuaiyu authored and zz-jason committed Jul 21, 2018
1 parent a631821 commit dbd7b61
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions executor/prepared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
}
8 changes: 8 additions & 0 deletions plan/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit dbd7b61

Please sign in to comment.