Add support for trailing comments in begin/commit/rollback statements#3613
Conversation
demmer
left a comment
There was a problem hiding this comment.
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?
|
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 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. |
|
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 :) |
go/vt/sqlparser/analyzer.go
Outdated
| 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. |
There was a problem hiding this comment.
minor nits:
"relying on" not "relying in".
I might clarify your counterexample as "BEGIN JUNK" as opposed to "BEGIN ..."
Otherwise LGTM
Description
The following fixes an issue where trailing comments cause
begin,commit,rollbackstatements to fail.Per discussion with @sougou in slack, making just a quick fix as this whole analyzer needs to be reworked.
Tests