Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plan, executor: check b.err after buildSort and buildLimit in builUnion #7114

Merged
merged 2 commits into from Jul 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions executor/prepared_test.go
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
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
}
Copy link
Collaborator

@lysu lysu Jul 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have an idea how about extract this part to this style.

package main

import (
	"github.com/juju/errors"
	"fmt"
)

type builder struct {
	err error
}

func (b *builder) b1() {
	b.b2()
	b.traceSelfCallStack()
	return
}

func (b *builder) b2() {
	b.err = errors.New("111")
	return
}

func (b *builder) traceSelfCallStack() {
	if b.err == nil {
		return
	}
	err := errors.NewErrWithCause(b.err, "")
	err.SetLocation(2)
	b.err = &err
	return
}

and still, keep every builder self-call has a b.traceSelfCallStack() followed..(we have no generic, so we can not b.selfCall(b.b2)() which is more readable)

}
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