-
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: Supports transitions between the same type (String types) #20032
Conversation
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.
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
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) | ||
} |
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.
Did you try that in MySQL? Is that permitted?
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, It's be allowed.
Sorry for such a long time, I will review it this weekend!!! |
/run-all-tests |
@AilinKid Do we need to support convertion between different charset? |
Should we take collate into consideration? @wjhuang2016 |
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") |
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.
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
.
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. |
@Patrick0308 merge failed. |
mysql_test also needs to be modified to pass the CI. We'll adjust it. |
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 |
Thanks @djshow832 , I fix this scene, but I found it's so complex to fully compatible with old version in a |
don't worry, I will resolve it tomorrow |
/run-all-tests |
/run-common-test tidb-test=pr/1093 |
/integration-common-test tidb-test=pr/1093 |
/run-all-tests tidb-test=pr/1093 |
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
/merge |
/run-all-tests |
thanks for your contribution so much~ (๑¯◡¯๑) |
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
pingcap/docs
/pingcap/docs-cn
:Check List
Tests
Release note