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

*: year type should have an unsigned flag #7542

Merged
merged 7 commits into from
Aug 31, 2018
Merged

Conversation

jackysp
Copy link
Member

@jackysp jackysp commented Aug 29, 2018

What problem does this PR solve?

Fix #7537. year type should have an unsigned flag. According to https://dev.mysql.com/doc/refman/8.0/en/numeric-type-overview.html ,
if you specify ZEROFILL for a numeric column, MySQL automatically adds the UNSIGNED attribute to the column.

What is changed and how it works?

Add unsigned flag back to year type, and add zerofill flag for all types except year type in show create table.

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change

Side effects

  • Increased code complexity

Related changes

  • Need to cherry-pick to the release branch

PTAL @zimulala @winkyao

@jackysp jackysp added component/DDL-need-LGT3 require-LGT3 Indicates that the PR requires three LGTM. labels Aug 29, 2018
@jackysp
Copy link
Member Author

jackysp commented Aug 29, 2018

/run-all-tests

ddl/ddl_api.go Outdated
@@ -394,6 +394,12 @@ func columnDefToCol(ctx sessionctx.Context, offset int, colDef *ast.ColumnDef, o
col.Flag &= ^mysql.BinaryFlag
col.Flag |= mysql.ZerofillFlag
}
// If you specify ZEROFILL for a numeric column, MySQL automatically adds the UNSIGNED attribute to the column.
// See https://dev.mysql.com/doc/refman/8.0/en/numeric-type-overview.html for more details.
// But some types like bit and year, won't show its unsigned flag in `show create table`.
Copy link
Contributor

@lysu lysu Aug 29, 2018

Choose a reason for hiding this comment

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

we should not support zerofill as #6688?

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems it still could work in some client/driver, see #7525

Copy link
Contributor

Choose a reason for hiding this comment

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

myabe we need use 5.7


// Test show create table with zerofill flag
tk.MustExec(`drop table if exists t`)
tk.MustExec(`create table t(id int primary key, val tinyint(10) zerofill);`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a year type?

Copy link
Member Author

Choose a reason for hiding this comment

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

year with zerofill?

Copy link
Member

Choose a reason for hiding this comment

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

yes

Copy link
Member Author

Choose a reason for hiding this comment

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

It is not allowed, according to #7542 (comment) @shenli

@jackysp
Copy link
Member Author

jackysp commented Aug 29, 2018

@winkyao in this pr #6745 , I've tested the schema in it, but MySQL does not return an error.

mysql> CREATE TABLE `abc` (
    ->   `y` year UNSIGNED NOT NULL,
    ->   `x` int(11) DEFAULT NULL,
    ->   PRIMARY KEY (`y`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin
    -> ;
Query OK, 0 rows affected

MySQL allow create table for a year type with zerofill/unsigned constraint. I think we should fix it in parser.

@jackysp
Copy link
Member Author

jackysp commented Aug 30, 2018

PTAL @winkyao

@jackysp
Copy link
Member Author

jackysp commented Aug 30, 2018

Add the parser support for year with field option according to https://github.com/mysql/mysql-server/blob/68816f735f02735e10ea6bea8efc291e4d3cac33/sql/sql_yacc.yy#L6263
PTAL @shenli

for _, col := range tbl.Meta().Columns {
if col.Name.String() == "y" {
yearCol = col
break
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this removal affect test-case's behavior?

Copy link
Member Author

Choose a reason for hiding this comment

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

No.

@jackysp
Copy link
Member Author

jackysp commented Aug 30, 2018

/run-all-tests

@coocood
Copy link
Member

coocood commented Aug 31, 2018

LGTM

Copy link

@imtbkcat imtbkcat left a comment

Choose a reason for hiding this comment

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

LGTM

@imtbkcat imtbkcat added the status/LGT2 Indicates that a PR has LGTM 2. label Aug 31, 2018
@jackysp jackysp merged commit 1f2841f into pingcap:master Aug 31, 2018
@jackysp jackysp changed the title ddl: year type should have an unsigned flag *: year type should have an unsigned flag Aug 31, 2018
@jackysp jackysp removed component/DDL-need-LGT3 require-LGT3 Indicates that the PR requires three LGTM. labels Aug 31, 2018
@jackysp jackysp deleted the year branch September 7, 2018 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants