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

mysql, sessionctx: refine set/get variable 'SQL_MODE' #4530

Merged
merged 20 commits into from Sep 15, 2017

Conversation

Projects
None yet
5 participants
@spongedu
Contributor

spongedu commented Sep 14, 2017

  1. MySQL throws an error if the input is illegal when set variable SQL_MODE.
mysql> set sql_mode="NO_ZERO_DATE,adfa";
ERROR 1231 (42000): Variable 'sql_mode' can't be set to the value of 'adfa'

TiDB do not do this check for now.

tidb>  set sql_mode="NO_ZERO_DATE,adfa";
Query OK, 0 rows affected (0.00 sec)

tidb> select @@sql_mode;
Field   1:  `@@sql_mode`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       STRING
Collation:  ? (0)
Length:     0
Max_length: 17
Decimals:   31
Flags:      


+-------------------+
| @@sql_mode        |
+-------------------+
| NO_ZERO_DATE,ADFA |
+-------------------+
1 row in set (0.00 sec)

  1. InMysql, SQL_MODE output is re-format, which is not done in TiDB.
    In MySQL:
mysql> set sql_mode =", ";
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> select @@sql_mode;
+------------+
| @@sql_mode |
+------------+
|            |
+------------+
1 row in set (0.00 sec)

In TiDB:

tidb> set sql_mode=", ";
Query OK, 0 rows affected (0.00 sec)

tidb> select @@sql_mode;
+------------+
| @@sql_mode |
+------------+
| ,          |
+------------+
1 row in set (0.00 sec)
@sre-bot

This comment has been minimized.

Show comment
Hide comment
@sre-bot

sre-bot Sep 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.

sre-bot commented Sep 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.

Show outdated Hide outdated mysql/const.go

@spongedu spongedu changed the title from mysql, sessionctx: throws error on illegal input when set 'SQL_MODE to mysql, sessionctx: refine set/get variable 'SQL_MODE' Sep 15, 2017

Show outdated Hide outdated mysql/const.go
Show outdated Hide outdated mysql/const_test.go
Show outdated Hide outdated session.go
var sqlMode mysql.SQLMode
for _, mode := range modes {
sqlMode = sqlMode | mysql.GetSQLMode(mode)
sqlMode, err2 := mysql.GetSQLMode(sVal)

This comment has been minimized.

@zz-jason

zz-jason Sep 15, 2017

Member

s/err2/err/

@zz-jason

zz-jason Sep 15, 2017

Member

s/err2/err/

This comment has been minimized.

@spongedu

spongedu Sep 15, 2017

Contributor

use the name err would cover outside definition of err in line sVal, err := value.ToString()

@spongedu

spongedu Sep 15, 2017

Contributor

use the name err would cover outside definition of err in line sVal, err := value.ToString()

This comment has been minimized.

@zz-jason

zz-jason Sep 15, 2017

Member

it does not matter, if outside err is not nil, function will be returned before this instruction, we can safely override it

@zz-jason

zz-jason Sep 15, 2017

Member

it does not matter, if outside err is not nil, function will be returned before this instruction, we can safely override it

This comment has been minimized.

@spongedu

spongedu Sep 15, 2017

Contributor

But the compile-time check would fail when execute make dev.....

@spongedu

spongedu Sep 15, 2017

Contributor

But the compile-time check would fail when execute make dev.....

This comment has been minimized.

@zz-jason

zz-jason Sep 15, 2017

Member

I see..

@zz-jason

zz-jason Sep 15, 2017

Member

I see..

Show outdated Hide outdated sessionctx/varsutil/varsutil.go
Show outdated Hide outdated session.go
@zz-jason

This comment has been minimized.

Show comment
Hide comment
@zz-jason
Member

zz-jason commented Sep 15, 2017

Show outdated Hide outdated mysql/const.go
Show outdated Hide outdated sessionctx/varsutil/varsutil.go
Show outdated Hide outdated sessionctx/varsutil/varsutil.go
Show outdated Hide outdated sessionctx/varsutil/varsutil.go

spongedu added some commits Sep 15, 2017

@spongedu

This comment has been minimized.

Show comment
Hide comment
@spongedu

spongedu Sep 15, 2017

Contributor

@coocood PTAL

Contributor

spongedu commented Sep 15, 2017

@coocood PTAL

Show outdated Hide outdated mysql/const.go
Show outdated Hide outdated sessionctx/varsutil/varsutil.go
Show outdated Hide outdated mysql/const.go
Show outdated Hide outdated mysql/const.go
@spongedu

This comment has been minimized.

Show comment
Hide comment
@spongedu

spongedu Sep 15, 2017

Contributor

Done @coocood PTAL

Contributor

spongedu commented Sep 15, 2017

Done @coocood PTAL

@coocood

This comment has been minimized.

Show comment
Hide comment
@coocood

coocood Sep 15, 2017

Member

LGTM

Member

coocood commented Sep 15, 2017

LGTM

@zz-jason

LGTM

@zz-jason zz-jason merged commit 74d5ce4 into pingcap:master Sep 15, 2017

4 checks passed

ci/circleci Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
jenkins-ci-tidb/build Jenkins job succeeded.
Details
license/cla Contributor License Agreement is signed.
Details

@spongedu spongedu deleted the spongedu:set_sql_mode branch Sep 15, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment