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

Add support for trailing comments in begin/commit/rollback statements #3613

Merged

Conversation

rafael
Copy link
Member

@rafael rafael commented Jan 31, 2018

Description

The following fixes an issue where trailing comments cause begin, commit, rollback statements to fail.

Per discussion with @sougou in slack, making just a quick fix as this whole analyzer needs to be reworked.

Tests

  • Added unit tests to verify the fix.

Copy link
Member

@demmer demmer left a comment

Choose a reason for hiding this comment

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

I feel like this is strictly worse than just comparing the lowercase first word since we are already computing it and don’t have to do the additional scan to split out comments.

Can you explain what was the motivation for this approach?

@rafael
Copy link
Member Author

rafael commented Feb 1, 2018

I first went down that road but noticed that it breaks the tests. The reason is that if you just compare lowercase first word, something like this will be considered a valid StmtBegin :

BEGIN sneaky invalid comment

You are right that strictly worse in performance, but given that this extra scan only happens for these kind of statements, I decided to lean more towards being strict with the syntax.

@demmer
Copy link
Member

demmer commented Feb 1, 2018

Ah of course -- because BEGIN etc aren't statements in the grammar so we actually rely on Preview to "parse" the statement. That is not clearly obvious from reading this code.

I was about to suggest that you move the scan lower down so it doesn't affect the rest of the statements (which you just did) so +1 to that.

The only other suggestion would be to add a comment explaining why BEGIN etc work differently from all the others so that another casual observer doesn't fall into the same fallacy that I did :)

switch strings.ToLower(trimmed) {
// For the following statements is not enough to just check
// loweredFirstWord. This is because they are not statements
// in the grammar and we are relying in Preview to parse them.
Copy link
Member

Choose a reason for hiding this comment

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

minor nits:
"relying on" not "relying in".
I might clarify your counterexample as "BEGIN JUNK" as opposed to "BEGIN ..."

Otherwise LGTM

@sougou
Copy link
Contributor

sougou commented Feb 7, 2018

LGTM

Approved with PullApprove

@alainjobart alainjobart merged commit c9edcc8 into vitessio:master Feb 7, 2018
systay pushed a commit that referenced this pull request Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants