-
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
ddl: allow enum to append values #7767
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 |
@mail2fish thanks for your PR. /run-all-tests |
/run-all-tests |
ddl/ddl_api.go
Outdated
@@ -1430,6 +1430,7 @@ func modifiable(origin *types.FieldType, to *types.FieldType) error { | |||
if to.Charset != origin.Charset { | |||
msg := fmt.Sprintf("charset %s not match origin %s", to.Charset, origin.Charset) | |||
return errUnsupportedModifyColumn.GenWithStackByArgs(msg) | |||
|
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.
remove this line.
ddl/ddl_api.go
Outdated
for index, originElem := range origin.Elems { | ||
toElem := to.Elems[index] | ||
if originElem != toElem { | ||
msg := fmt.Sprintf("cannot modify value %s to %s", originElem, toElem) |
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 about:
msg := fmt.Sprintf("cannot modify enum column value %s to %s", originElem, toElem)
ddl/ddl_api.go
Outdated
return errUnsupportedModifyColumn.GenWithStackByArgs("modify enum column is not supported") | ||
if origin.Tp == to.Tp { | ||
if len(to.Elems) < len(origin.Elems) { | ||
msg := fmt.Sprintf("elem length %d is less than origin %d", len(to.Elems), len(origin.Elems)) |
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 about:
msg := fmt.Sprintf("enum column elements length %d is less than origin %d", len(to.Elems), len(origin.Elems))
ddl/db_change_test.go
Outdated
c.Assert(err, IsNil) | ||
|
||
expected = []string{"8 N", "10 N", "11 A"} | ||
|
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.
so many blank lines
/run-all-tests |
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.
Allow to append new values to existing ENUM/SET fields
But you don't take SET
into consideration?
@winoros This PR is needed by my job. Maybe I could post another PR for the set. |
ddl/ddl_api.go
Outdated
return errUnsupportedModifyColumn.GenWithStackByArgs("modify enum column is not supported") | ||
if origin.Tp == to.Tp { | ||
if len(to.Elems) < len(origin.Elems) { | ||
msg := fmt.Sprintf("enum column elements length %d is less than origin %d", len(to.Elems), len(origin.Elems)) |
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.
Is the number of enum column's elements is less than the original
more clearer?
ddl/ddl_api.go
Outdated
} | ||
return nil | ||
} | ||
msg := fmt.Sprintf("cannot modify enum type column to type %s", to.String()) |
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.
cannot modify enum column's type to type %s
/run-all-tests |
@@ -349,6 +349,49 @@ type expectQuery struct { | |||
rows []string | |||
} | |||
|
|||
func (s *testStateChangeSuite) TestAppendEnum(c *C) { |
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.
I think we should test the ALTER TABLE ... MODIFY COLUMN
statements which modify the enum column to another column type.
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.
What's the test result you expected? An error message?
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.
According to the modifiable()
function, some changes are allowed, while others are not.
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.
At this time, to.Tp is always be enum. If we alter enum's column to other type, we will got the error message: the number of enum column's elements is less than the original.
Is that all right?
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.
Yes, for example:
CREATE TABLE ti1(a INT NOT NULL, b INT, c INT, e ENUM('a', 'b')) engine=InnoDB;
ALTER TABLE ti1 MODIFY COLUMN e ENUM('a', 'b', 'c'); -- succeed
ALTER TABLE ti1 MODIFY COLUMN e ENUM('a'); -- failed
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.
Hi, I have add some new test, please check it. thank you.
/run-all-tests |
/run-all-tests |
} | ||
for index, originElem := range origin.Elems { | ||
toElem := to.Elems[index] | ||
if originElem != toElem { |
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.
For enum enum('N','Y')
, alter table t change c2 c2 enum('N','Y','A','B') DEFAULT 'A';
is okay, but alter table t change c2 c2 enum('A','B','N','Y') DEFAULT 'A'
does not work.
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.
What do you mean? The enum order shouldn't be changed. The SQL "alter table t change c2 c2 enum('A','B','N','Y') DEFAULT 'A' " is also not working at MySQL.
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.
Got it.
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
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
You are right. It worked in MySQL.
But I am not sure whether we should support this feature.
After I changed the enum order in MySQL 5.6, The enum's value in the rows
has changed.
mysql> create table t (c1 varchar(64),c2 enum('N','Y') not null default
'N',c3 timestamp on update current_timestamp,c4 int primary key,unique key
idx2 (c2, c3));
Query OK, 0 rows affected (0.21 sec)
mysql> insert into t values('a', 'N', '2017-07-01', 8);
Query OK, 1 row affected (0.04 sec)
mysql> select c2+0 from t;
+------+
| c2+0 |
+------+
| 1 |
+------+
1 row in set (0.00 sec)
mysql> alter table t change c2 c2 enum('A','B','D','F','Y','N') DEFAULT 'D';
Query OK, 1 row affected (0.53 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> select c2+0 from t;
+------+
| c2+0 |
+------+
| 6 |
+------+
1 row in set (0.00 sec)
Lingyu Song <notifications@github.com> 于2018年9月26日周三 下午4:59写道:
… ***@***.**** commented on this pull request.
------------------------------
In ddl/ddl_api.go
<#7767 (comment)>:
> @@ -1455,7 +1455,22 @@ func modifiable(origin *types.FieldType, to *types.FieldType) error {
return nil
}
case mysql.TypeEnum:
- return errUnsupportedModifyColumn.GenWithStackByArgs("modify enum column is not supported")
+ if origin.Tp == to.Tp {
+ if len(to.Elems) < len(origin.Elems) {
+ msg := fmt.Sprintf("the number of enum column's elements is less than the original: %d", len(origin.Elems))
+ return errUnsupportedModifyColumn.GenWithStackByArgs(msg)
+ }
+ for index, originElem := range origin.Elems {
+ toElem := to.Elems[index]
+ if originElem != toElem {
I use MySQL 5.6 to execute these case.
in MySQL:
mysql> create table t (c1 varchar(64),c2 enum('N','Y') not null default 'N',c3
timestamp on update current_timestamp,c4 int primary key,unique key idx2 (c2,
c3));
Query OK, 0 rows affected (0.03 sec)
mysql> insert into t values('a', 'N', '2017-07-01', 8);
Query OK, 1 row affected (0.00 sec)
mysql> alter table t change c2 c2 enum('A','B','N','Y') DEFAULT 'A';
Query OK, 1 row affected (0.05 sec)
Records: 1 Duplicates: 0 Warnings: 0
in TiDB:
mysql> insert into t values('a', 'N', '2017-07-01', 8);
Query OK, 1 row affected (0.00 sec)
mysql> alter table t change c2 c2 enum('A','B','N','Y') DEFAULT 'A';
ERROR 1105 (HY000): unsupported modify column cannot modify enum column
value N to A
mysql> alter table t change c2 c2 enum('N','Y','A','B') DEFAULT 'A';
Query OK, 0 rows affected (0.01 sec)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#7767 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAVWjEoUiXDd2khMrhG9SkMlOnfHtta3ks5ue0HpgaJpZM4W0FuT>
.
|
/run-all-tests |
LGTM |
What have you changed? (mandatory)
fix #6398
Allow to append new values to existing ENUM fields.
Removing values or changing existing values is still unsupported.
What are the type of the changes (mandatory)?
How has this PR been tested (mandatory)?