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

Refactor parser: Avoid some assertion for StmtNode #4705

Merged
merged 4 commits into from
Oct 9, 2017
Merged

Conversation

shenli
Copy link
Member

@shenli shenli commented Oct 1, 2017

Make code cleaner. No performance improvement.

Before:

➜ parser git:(master) ✗ go test -run=XXX -bench=. -benchtime=10s
BenchmarkSysbenchSelect-4 3000000 4589 ns/op 1888 B/op 27 allocs/op
BenchmarkParse-4 1000000 14310 ns/op 5224 B/op 89 allocs/op
PASS
ok github.com/pingcap/tidb/parser 32.910s
➜ parser git:(master) ✗ go test -run=XXX -bench=. -benchtime=10s
BenchmarkSysbenchSelect-4 3000000 4770 ns/op 1888 B/op 27 allocs/op
BenchmarkParse-4 1000000 14001 ns/op 5224 B/op 89 allocs/op
PASS
ok github.com/pingcap/tidb/parser 33.489s
➜ parser git:(master) ✗ go test -run=XXX -bench=. -benchtime=10s
BenchmarkSysbenchSelect-4 3000000 4679 ns/op 1888 B/op 27 allocs/op
BenchmarkParse-4 ^[[A 1000000 14028 ns/op 5224 B/op 89 allocs/op
PASS
ok github.com/pingcap/tidb/parser 32.791s
➜ parser git:(master) ✗ go test -run=XXX -bench=. -benchtime=10s
BenchmarkSysbenchSelect-4 3000000 4628 ns/op 1888 B/op 27 allocs/op
BenchmarkParse-4 1000000 14434 ns/op 5224 B/op 89 allocs/op
PASS
ok github.com/pingcap/tidb/parser 33.395s

After:

➜ parser git:(shenli/parser) ✗ go test -run=XXX -bench=. -benchtime=10s
BenchmarkSysbenchSelect-4 3000000 4586 ns/op 1888 B/op 27 allocs/op
BenchmarkParse-4 1000000 14229 ns/op 5224 B/op 89 allocs/op
PASS
ok github.com/pingcap/tidb/parser 32.819s
➜ parser git:(shenli/parser) ✗ go test -run=XXX -bench=. -benchtime=10s
BenchmarkSysbenchSelect-4 3000000 4567 ns/op 1888 B/op 27 allocs/op
BenchmarkParse-4 1000000 14253 ns/op 5224 B/op 89 allocs/op
PASS
ok github.com/pingcap/tidb/parser 32.768s
➜ parser git:(shenli/parser) ✗ go test -run=XXX -bench=. -benchtime=10s
BenchmarkSysbenchSelect-4 3000000 4622 ns/op 1888 B/op 27 allocs/op
BenchmarkParse-4 1000000 14979 ns/op 5224 B/op 89 allocs/op
PASS
ok github.com/pingcap/tidb/parser 33.719s
➜ parser git:(shenli/parser) ✗ go test -run=XXX -bench=. -benchtime=10s
BenchmarkSysbenchSelect-4 3000000 4701 ns/op 1888 B/op 27 allocs/op
BenchmarkParse-4 1000000 14687 ns/op 5224 B/op 89 allocs/op
PASS
ok github.com/pingcap/tidb/parser 33.645s
➜ parser git:(shenli/parser) ✗ go test -run=XXX -bench=. -benchtime=10s
BenchmarkSysbenchSelect-4 3000000 4561 ns/op 1888 B/op 27 allocs/op
BenchmarkParse-4 1000000 14233 ns/op 5224 B/op 89 allocs/op
PASS
ok github.com/pingcap/tidb/parser 32.730s

@shenli
Copy link
Member Author

shenli commented Oct 4, 2017

/run-all-tests

@shenli shenli mentioned this pull request Oct 4, 2017
2 tasks
@zz-jason
Copy link
Member

zz-jason commented Oct 9, 2017

LGTM

@zz-jason zz-jason added the status/LGT1 Indicates that a PR has LGTM 1. label Oct 9, 2017
parser/parser.y Outdated
ShowStmt "Show engines/databases/tables/columns/warnings/status statement"
Statement "statement"
ExplainableStmt "explainable statement"
TruncateTableStmt "TRANSACTION TABLE statement"
Copy link
Contributor

Choose a reason for hiding this comment

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

align these 5 lines.

| SubSelect
{
// `(select 1)`; is a valid select statement
// TODO: This is used to fix issue #320. There may be a better solution.
$$ = $1.(*ast.SubqueryExpr).Query
$$ = $1.(*ast.SubqueryExpr).Query.(ast.StmtNode)
Copy link
Contributor

Choose a reason for hiding this comment

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

why we add type assertion here?

Copy link
Member Author

Choose a reason for hiding this comment

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

$1.(*ast.SubqueryExpr).Query is a ResultSet, not StmtNode.

@shenli
Copy link
Member Author

shenli commented Oct 9, 2017

@XuHuaiyu PTAL

@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Oct 9, 2017

circleci failed @shenli

@shenli
Copy link
Member Author

shenli commented Oct 9, 2017

@XuHuaiyu I can not open CircleCI now. I merge master and rerun it.

Copy link
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

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

LGTM

@XuHuaiyu XuHuaiyu merged commit 0d0685a into master Oct 9, 2017
@XuHuaiyu XuHuaiyu deleted the shenli/parser branch October 9, 2017 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants