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

parser: support sql_mode 'IGNORE SPACE' #5106

Merged
merged 18 commits into from
Dec 7, 2017

Conversation

spongedu
Copy link
Contributor

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.

@sre-bot
Copy link
Contributor

sre-bot commented Nov 14, 2017

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.

@XuHuaiyu
Copy link
Contributor

/ok-to-test

@shenli
Copy link
Member

shenli commented Nov 16, 2017

@spongedu Thanks!
Please resolve the conflicts.

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
Copy link
Member

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.

Copy link
Contributor Author

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},
Copy link
Member

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?

Copy link
Contributor Author

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

@shenli
Copy link
Member

shenli commented Nov 16, 2017

/run-all-tests

@zz-jason zz-jason added this to the 1.1 milestone Nov 16, 2017
@zz-jason zz-jason added conflicting contribution This PR is from a community contributor. labels Nov 16, 2017
@zz-jason
Copy link
Member

@spongedu plz resolve conflicts.

Conflicts:
	mysql/const.go
	mysql/const_test.go
parser/parser.y Outdated
@@ -2989,10 +3019,18 @@ FunctionCallKeyword:
{
$$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)}
}
| builtinUser '(' ExpressionListOpt ')'
Copy link
Member

Choose a reason for hiding this comment

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

keep the code indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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 :)

Copy link
Contributor Author

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

parser/lexer.go Outdated
@@ -25,6 +25,41 @@ import (

var _ = yyLexer(&Scanner{})

var ignoreSpaceFuncMap = map[string]int{
Copy link
Member

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 ?

Copy link
Contributor Author

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
@tiancaiamao
Copy link
Contributor

/run-all-tests

@tiancaiamao
Copy link
Contributor

LGTM

tiancaiamao
tiancaiamao previously approved these changes Nov 27, 2017
@tiancaiamao tiancaiamao dismissed their stale review November 27, 2017 03:25

misoperation

@tiancaiamao
Copy link
Contributor

PTAL @zz-jason @shenli @XuHuaiyu

parser/parser.y Outdated
| FunctionNameOptionalBraces OptionalBraces
{
$$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1)}
}
| builtinCurDate '(' ')'
Copy link
Member

Choose a reason for hiding this comment

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

keep code indentation

Copy link
Contributor Author

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 ')'
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@zz-jason
Copy link
Member

/run-all-tests

@tiancaiamao tiancaiamao added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 30, 2017
zimulala
zimulala previously approved these changes Dec 6, 2017
Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

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

LGTM

@zimulala zimulala added all-tests-passed status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Dec 6, 2017
@spongedu
Copy link
Contributor Author

spongedu commented Dec 6, 2017

@zimulala Fixed the failed cases. PTAL, Thanks :)

@coocood coocood merged commit d742d92 into pingcap:master Dec 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution This PR is from a community contributor. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants