-
Notifications
You must be signed in to change notification settings - Fork 489
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
Rewrite special comment parser #711
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Instead, simply strip off '/*!' and the pairing '*/'. Temporarily disabled handling of /*+ ... */
This new token has type `hintComment`. The actual hint will be parsed lazily.
change the "DO NOT EDIT" line to fit the Go standard
deleted all optimizer hint rules from parser.go refactor the Makefile to support building both parsers (also deleted some outdated fixup of *parser.go)
Codecov Report
@@ Coverage Diff @@
## master #711 +/- ##
=========================================
- Coverage 77.98% 77.68% -0.3%
=========================================
Files 38 40 +2
Lines 14020 14219 +199
=========================================
+ Hits 10933 11046 +113
- Misses 2435 2513 +78
- Partials 652 660 +8 |
tangenta
reviewed
Jan 7, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rest LGTM
cache the hintparser in the main parser to avoid repeated allocation
PTAL @tangenta @tiancaiamao cc @lonng The integration test is failing because the warnings produced by invalid hint is changed. |
LGTM |
tiancaiamao
approved these changes
Jan 8, 2020
tangenta
pushed a commit
to tangenta/parser
that referenced
this pull request
Apr 14, 2020
* lexer: added a function to scan version digits * lexer: removed special comment scanner Instead, simply strip off '/*!' and the pairing '*/'. Temporarily disabled handling of /*+ ... */ * lexer: support collecting the entire /*+ ... */ as a single token This new token has type `hintComment`. The actual hint will be parsed lazily. * lexer,yy_parser: move lastErrorAsWarn() from Parser into Scanner * goyacc: do not allow conflict, support changing parser type name change the "DO NOT EDIT" line to fit the Go standard * parser,hintparser: created a new parser just for parsing optimizer hints deleted all optimizer hint rules from parser.go refactor the Makefile to support building both parsers (also deleted some outdated fixup of *parser.go) * lexer: fix comment parser * codecov: don't wait for integration test before showing the coverage * lexer: fix comment parsing again * hintparser: TiDB still expects `HASH_JOIN(@qb1 foo@qb2)` to be valid :( * parser,hintparser: provide the true line/column offset in the warnings cache the hintparser in the main parser to avoid repeated allocation * lexer: delete unused sqlOffsetInComment()
tangenta
added a commit
that referenced
this pull request
Apr 20, 2020
tangenta
added a commit
to tangenta/parser
that referenced
this pull request
Apr 28, 2020
tiancaiamao
pushed a commit
to tiancaiamao/parser
that referenced
this pull request
Apr 27, 2021
* lexer: added a function to scan version digits * lexer: removed special comment scanner Instead, simply strip off '/*!' and the pairing '*/'. Temporarily disabled handling of /*+ ... */ * lexer: support collecting the entire /*+ ... */ as a single token This new token has type `hintComment`. The actual hint will be parsed lazily. * lexer,yy_parser: move lastErrorAsWarn() from Parser into Scanner * goyacc: do not allow conflict, support changing parser type name change the "DO NOT EDIT" line to fit the Go standard * parser,hintparser: created a new parser just for parsing optimizer hints deleted all optimizer hint rules from parser.go refactor the Makefile to support building both parsers (also deleted some outdated fixup of *parser.go) * lexer: fix comment parser * codecov: don't wait for integration test before showing the coverage * lexer: fix comment parsing again * hintparser: TiDB still expects `HASH_JOIN(@qb1 foo@qb2)` to be valid :( * parser,hintparser: provide the true line/column offset in the warnings cache the hintparser in the main parser to avoid repeated allocation * lexer: delete unused sqlOffsetInComment()
lyonzhi
pushed a commit
to lyonzhi/parser
that referenced
this pull request
Apr 25, 2024
* lexer: added a function to scan version digits * lexer: removed special comment scanner Instead, simply strip off '/*!' and the pairing '*/'. Temporarily disabled handling of /*+ ... */ * lexer: support collecting the entire /*+ ... */ as a single token This new token has type `hintComment`. The actual hint will be parsed lazily. * lexer,yy_parser: move lastErrorAsWarn() from Parser into Scanner * goyacc: do not allow conflict, support changing parser type name change the "DO NOT EDIT" line to fit the Go standard * parser,hintparser: created a new parser just for parsing optimizer hints deleted all optimizer hint rules from parser.go refactor the Makefile to support building both parsers (also deleted some outdated fixup of *parser.go) * lexer: fix comment parser * codecov: don't wait for integration test before showing the coverage * lexer: fix comment parsing again * hintparser: TiDB still expects `HASH_JOIN(@qb1 foo@qb2)` to be valid :( * parser,hintparser: provide the true line/column offset in the warnings cache the hintparser in the main parser to avoid repeated allocation * lexer: delete unused sqlOffsetInComment()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
Rewrite the special comment parser (
/*! ... */
and/*+ ... */
) to better match MySQL's behavior.This is the first step to solve pingcap/tidb#14030 (comment).
What is changed and how it works?
Removed
specialCommentScanner
. Instead:/*!
or/*!12345
or/*T!
or/*T!012345
, drop this substring and continue parsing as if outside a comment. Use a flag to indicate we should skip the stray*/
./*+
, read the entire comment as a string token. This token will be parsed into[]*ast.TableOptimizerHint
using the new hint parser on-demand. All errors coming from that parsers are demoted to warnings.The
/*+ ... */
is only parsed after keywords SELECT, INSERT, REPLACE, UPDATE, DELETE, CREATE and PARTITION, otherwise it is treated as an ordinary comment. Therefore, some SQL previously failing likeSELECT 1 FROM /*+ hash_agg() */ t1
now becomes successful and ignoring the hint.SELECT 1 FOR UPDATE /*+ max_execution_time(60) */
would still produce an error. We could fix it later?And we now have two parsers, the main
parser.y
, and the optimizer-hint specifichintparser.y
parser.y
. This also deletes the related TiDB-specific keywords.The structure
ast.TableOptimizerHint
is not yet changed, so we are still API-compatible.Check List
Tests
Code changes
Side effects
Related changes