-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
parser: support sql_mode 'IGNORE SPACE' #5106
Conversation
Hi contributor, thanks for your PR. This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically. |
/ok-to-test |
@spongedu Thanks! |
mysql/const.go
Outdated
@@ -452,6 +452,16 @@ func (m SQLMode) HasRealAsFloatMode() bool { | |||
return m&ModeRealAsFloat == ModeRealAsFloat | |||
} | |||
|
|||
// HasNoBackslashEscapesMode detects if 'NO_BACKSLASH_ESCAPES' mode is set in SQLMode |
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.
This function is not related with IGNORE_SPACE.
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.
@shenli It seems to be taken into this pr in a merge. I'll delete this.
@@ -828,7 +828,7 @@ func (s *testParserSuite) TestBuiltin(c *C) { | |||
|
|||
// for date, day, weekday | |||
{"SELECT CURRENT_DATE, CURRENT_DATE(), CURDATE()", true}, | |||
{"SELECT CURRENT_DATE, CURRENT_DATE(), CURDATE(1)", true}, | |||
{"SELECT CURRENT_DATE, CURRENT_DATE(), CURDATE(1)", false}, |
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.
Why this is false case?
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.
@shenli it seems that MySQL doesn't support CURDATE
with one parameter. see: https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_curdate
/run-all-tests |
@spongedu plz resolve conflicts. |
Conflicts: mysql/const.go mysql/const_test.go
df777db
to
a04a3b2
Compare
parser/parser.y
Outdated
@@ -2989,10 +3019,18 @@ FunctionCallKeyword: | |||
{ | |||
$$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)} | |||
} | |||
| builtinUser '(' ExpressionListOpt ')' |
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.
keep the code indentation
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.
@zz-jason ok
parser/lexer.go
Outdated
@@ -435,7 +470,16 @@ func scanIdentifier(s *Scanner) (int, Pos, string) { | |||
pos := s.r.pos() | |||
s.r.inc() | |||
s.r.incAsLongAs(isIdentChar) | |||
return identifier, pos, s.r.data(&pos) | |||
lit := s.r.data(&pos) |
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.
It's quite performance sensitive here.
strings.ToLower(lit)
would cause allocation, and map access is not that fast.
I think you can switch the order, check IgnoreSpaceMode first, try the best not to hurt the performance in most cases.
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.
@tiancaiamao ok, I'll take a look. thx :)
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.
@tiancaiamao I've refine this place. PTAL
Conflicts: mysql/const_test.go
parser/lexer.go
Outdated
@@ -25,6 +25,41 @@ import ( | |||
|
|||
var _ = yyLexer(&Scanner{}) | |||
|
|||
var ignoreSpaceFuncMap = map[string]int{ |
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.
How do we obtain tis map ?
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.
@zz-jason I've rewrite this part. PTAL
…RE_SPACE' mode 2. Move check for 'IGNORE_SPACE' to 'isTokenIdentifier' 3. add more tests
/run-all-tests |
LGTM |
parser/parser.y
Outdated
| FunctionNameOptionalBraces OptionalBraces | ||
{ | ||
$$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1)} | ||
} | ||
| builtinCurDate '(' ')' |
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.
keep code indentation
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.
ok
parser/parser.y
Outdated
{ | ||
$$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)} | ||
} | ||
| builtinSysDate '(' FuncDatetimePrecListOpt ')' |
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.
ditto
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.
done
/run-all-tests |
b60485f
to
8380384
Compare
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.
LGTM
@zimulala Fixed the failed cases. PTAL, Thanks :) |
support sql_mode 'IGNORE SPACE' for TiDB, and refine function name resolution rule according to MySQL's behavior. See https://dev.mysql.com/doc/refman/5.7/en/function-resolution.html for details.