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: Supports transitions between the same type (String types) #20032

Merged
merged 34 commits into from
Oct 16, 2020

Conversation

Patrick0308
Copy link
Contributor

What problem does this PR solve?

Issue Number: close #19571

Problem Summary:

What is changed and how it works?

What's Changed: Supports transitions between the same type (String types)

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test
  • Integration test

Release note

  • Supports transitions between the same type (String types)

@ti-srebot ti-srebot added the contribution This PR is from a community contributor. label Sep 16, 2020
@github-actions github-actions bot added the sig/sql-infra SIG: SQL Infra label Sep 16, 2020
Copy link
Contributor

@djshow832 djshow832 left a comment

Choose a reason for hiding this comment

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

The procedure is basically right. Please be cautious about all kinds of transitions, because even a small bug may cause data loss.

ddl/ddl_api.go Outdated
Comment on lines 3261 to 3376
if origin.Tp != to.Tp {
msg := fmt.Sprintf("cannot modify enum type column's to type %s", to.String())
return "", errUnsupportedModifyColumn.GenWithStackByArgs(msg)
}
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 {
msg := fmt.Sprintf("cannot modify enum column value %s to %s", originElem, toElem)
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.

Did you try that in MySQL? Is that permitted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, It's be allowed.

@Patrick0308 Patrick0308 requested a review from a team as a code owner September 22, 2020 13:31
@Patrick0308 Patrick0308 requested review from wshwsh12 and removed request for a team September 22, 2020 13:31
@wshwsh12 wshwsh12 requested review from AilinKid and removed request for wshwsh12 September 23, 2020 03:26
@AilinKid
Copy link
Contributor

Sorry for such a long time, I will review it this weekend!!!

@Patrick0308
Copy link
Contributor Author

/run-all-tests

ddl/column.go Outdated Show resolved Hide resolved
ddl/column.go Outdated Show resolved Hide resolved
@Patrick0308
Copy link
Contributor Author

@AilinKid Do we need to support convertion between different charset?

@AilinKid
Copy link
Contributor

AilinKid commented Sep 27, 2020

@AilinKid Do we need to support conversion between different charset?

Should we take collate into consideration? @wjhuang2016

ddl/column.go Outdated Show resolved Hide resolved
ddl/db_test.go Outdated
c.Assert(c2.FieldType.Tp, Equals, mysql.TypeBlob)

// text to set
tk.MustGetErrMsg("alter table tt change a a set('111', '2222');", "[types:1265]Data truncated for column 'a' at row 2")
Copy link
Member

Choose a reason for hiding this comment

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

If sql_mode is set to "", the job will be succeeded and warnings will be returned instead and 10000 will be converted to an empty value.

Since we don't have sql_mode here, you can choose to update your code if #20012 is merged before this PR(it's up to you). For now, let's skip the sql_mode.

ddl/column.go Outdated Show resolved Hide resolved
@bb7133
Copy link
Member

bb7133 commented Sep 27, 2020

@AilinKid Do we need to support conversion between different charset?

Should we take collate into consideration? @wjhuang2016

No, I don't think we need to consider the charset and collation in this PR. Let's keep the current constraint for modifying charset and constraint.

ddl/column.go Outdated Show resolved Hide resolved
ddl/column.go Outdated Show resolved Hide resolved
@ti-srebot
Copy link
Contributor

@Patrick0308 merge failed.

@djshow832
Copy link
Contributor

mysql_test also needs to be modified to pass the CI. We'll adjust it.

@djshow832
Copy link
Contributor

mysql> CREATE TABLE t1(a INT AUTO_INCREMENT PRIMARY KEY, b ENUM('a', 'b', 'c') NOT NULL);
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO t1 (b) VALUES ('a'), ('c'), ('b'), ('b'), ('a');
Query OK, 5 rows affected (0.00 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> ALTER TABLE t1 MODIFY b ENUM('a', 'z', 'b', 'c') NOT NULL;
Query OK, 0 rows affected (0.02 sec)

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

When tidb_enable_change_column_type is false, the ALTER should fail. PTAL @Patrick0308

@Patrick0308
Copy link
Contributor Author

Patrick0308 commented Oct 15, 2020

Thanks @djshow832 , I fix this scene, but I found it's so complex to fully compatible with old version in a CheckModifyTypeCompatible function, may be we need a new CheckModifyTypeCompatible function when tidb_enable_change_column_type is true.

@Patrick0308 Patrick0308 dismissed stale reviews from ti-srebot and djshow832 via b923e4d October 15, 2020 11:56
@Patrick0308 Patrick0308 requested a review from djshow832 October 15, 2020 13:31
@AilinKid
Copy link
Contributor

Thanks @djshow832 , I fix this scene, but I found it's so difficult to fully compatible with old version in a CheckModifyTypeCompatible function, may be we need a new CheckModifyTypeCompatible function when tidb_enable_change_column_type is true.

don't worry, I will resolve it tomorrow

@AilinKid
Copy link
Contributor

/run-all-tests

@AilinKid
Copy link
Contributor

/run-common-test tidb-test=pr/1093

@AilinKid
Copy link
Contributor

/integration-common-test tidb-test=pr/1093

@AilinKid
Copy link
Contributor

/run-all-tests tidb-test=pr/1093

Copy link
Contributor

@AilinKid AilinKid left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-srebot ti-srebot removed the status/LGT2 Indicates that a PR has LGTM 2. label Oct 16, 2020
@ti-srebot ti-srebot added the status/LGT3 The PR has already had 3 LGTM. label Oct 16, 2020
@AilinKid
Copy link
Contributor

/merge

@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot ti-srebot merged commit da70410 into pingcap:master Oct 16, 2020
@AilinKid
Copy link
Contributor

thanks for your contribution so much~ (๑¯◡¯๑)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression contribution This PR is from a community contributor. sig/sql-infra SIG: SQL Infra status/can-merge Indicates a PR has been approved by a committer. status/LGT3 The PR has already had 3 LGTM.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Supports transitions between the same type (String types)
5 participants