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

ddl: allow enum to append values #7767

Merged
merged 2 commits into from
Sep 27, 2018
Merged

ddl: allow enum to append values #7767

merged 2 commits into from
Sep 27, 2018

Conversation

mail2fish
Copy link
Contributor

@mail2fish mail2fish commented Sep 21, 2018

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

  • Improvement (non-breaking change which is an improvement to an existing feature)

How has this PR been tested (mandatory)?

  • added unit test cases in ddl/db_change_test.go

@sre-bot
Copy link
Contributor

sre-bot commented Sep 21, 2018

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.

@mail2fish
Copy link
Contributor Author

/ok-to-test

@lysu lysu added contribution This PR is from a community contributor. component/DDL-need-LGT3 labels Sep 21, 2018
@lysu
Copy link
Contributor

lysu commented Sep 21, 2018

@mail2fish thanks for your PR.

/run-all-tests

@lysu lysu changed the title ddl: allow enum/set to append values ddl: allow enum to append values Sep 21, 2018
@mail2fish
Copy link
Contributor Author

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

Copy link
Contributor

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

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

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

c.Assert(err, IsNil)

expected = []string{"8 N", "10 N", "11 A"}

Copy link
Contributor

Choose a reason for hiding this comment

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

so many blank lines

@mail2fish
Copy link
Contributor Author

/run-all-tests

Copy link
Member

@winoros winoros left a 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?

@mail2fish
Copy link
Contributor Author

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

@winoros winoros Sep 25, 2018

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

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

@mail2fish
Copy link
Contributor Author

/run-all-tests

@@ -349,6 +349,49 @@ type expectQuery struct {
rows []string
}

func (s *testStateChangeSuite) TestAppendEnum(c *C) {
Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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

Copy link
Contributor Author

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.

@mail2fish
Copy link
Contributor Author

/run-all-tests

@mail2fish
Copy link
Contributor Author

/run-all-tests

}
for index, originElem := range origin.Elems {
toElem := to.Elems[index]
if originElem != toElem {

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.

Copy link
Contributor Author

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.

Copy link

@imtbkcat imtbkcat Sep 26, 2018

Choose a reason for hiding this comment

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

Got it.

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/LGT1 Indicates that a PR has LGTM 1. label Sep 26, 2018
zz-jason
zz-jason previously approved these changes Sep 26, 2018
Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@zz-jason zz-jason dismissed their stale review September 26, 2018 09:12

need one more reviewer.

@zz-jason zz-jason added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Sep 26, 2018
@zz-jason
Copy link
Member

@zimulala @winkyao PTAL

@mail2fish
Copy link
Contributor Author

mail2fish commented Sep 27, 2018 via email

@mail2fish
Copy link
Contributor Author

/run-all-tests

@coocood
Copy link
Member

coocood commented Sep 27, 2018

LGTM

@zz-jason zz-jason merged commit 1771d67 into pingcap:master Sep 27, 2018
@you06 you06 added the sig/sql-infra SIG: SQL Infra label Mar 4, 2020
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. sig/sql-infra SIG: SQL Infra status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support modify column to enum types.
10 participants