Skip to content

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

Merged
alainjobart merged 5 commits intovitessio:masterfrom
tinyspeck:fix-for-begin-commit-rollback
Feb 7, 2018
Merged

Add support for trailing comments in begin/commit/rollback statements#3613
alainjobart merged 5 commits intovitessio:masterfrom
tinyspeck:fix-for-begin-commit-rollback

Conversation

@rafael
Copy link
Copy Markdown
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.

@rafael rafael requested a review from demmer January 31, 2018 21:25
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

sougou commented Feb 7, 2018

LGTM

Approved with PullApprove

@alainjobart alainjobart merged commit c9edcc8 into vitessio:master Feb 7, 2018
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