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: fix alter table charset bug that change blob column type to text #10477

Merged
merged 10 commits into from
Jun 4, 2019

Conversation

crazycs520
Copy link
Contributor

What problem does this PR solve?

Alter table charset will change blob column to text column. just like below.

Before

tidb> create table t1 (a blob) character set utf8;
Query OK, 0 rows affected
Time: 0.005s
tidb> alter table t1 charset=utf8mb4 collate=utf8mb4_bin;
Query OK, 0 rows affected
Time: 0.005s
tidb> show create table t1
+-------+-------------------------------------------------------------+
| Table | Create Table                                                |
+-------+-------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (                                         |
|       |   `a` text DEFAULT NULL                                     |
|       | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+-------------------------------------------------------------+

What is changed and how it works?

  • fix Alter table column bug.

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change

Side effects

Related changes

  • Need to cherry-pick to the release branch

@zhouqiang-cl
Copy link
Contributor

/rebuild

@codecov
Copy link

codecov bot commented May 15, 2019

Codecov Report

Merging #10477 into master will decrease coverage by 0.0136%.
The diff coverage is 100%.

@@               Coverage Diff               @@
##            master     #10477        +/-   ##
===============================================
- Coverage   78.354%   78.3403%   -0.0137%     
===============================================
  Files          414        414                
  Lines        87730      87730                
===============================================
- Hits         68740      68728        -12     
- Misses       13849      13856         +7     
- Partials      5141       5146         +5

ddl/table.go Outdated
@@ -735,6 +735,9 @@ func onModifyTableCharsetAndCollate(t *meta.Meta, job *model.Job) (ver int64, _
tblInfo.Collate = toCollate
// update column charset.
for _, col := range tblInfo.Columns {
if col.Charset == charset.CharsetBin {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can use HasCharset here.

@@ -735,7 +736,7 @@ func onModifyTableCharsetAndCollate(t *meta.Meta, job *model.Job) (ver int64, _
tblInfo.Collate = toCollate
// update column charset.
for _, col := range tblInfo.Columns {
if typesNeedCharset(col.Tp) {
if field_types.HasCharset(&col.FieldType) {
Copy link
Member

Choose a reason for hiding this comment

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

I guess typesNeedCharset can be replaced by HasCharset. Another code that calls this function is:

if typesNeedCharset(tp.Tp) {

Can you confirm it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No,

if typesNeedCharset(tp.Tp) {
here may be have not set the column Flag, use HasCharset here may be got some error.

Copy link
Contributor

Choose a reason for hiding this comment

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

so why you use HashCharset finally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

HashCharset can be used here(ddl/table.go #739), but ddl/ddl_api.go #299 should use typesNeedCharset function.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I still don't quite understand, why is it correct to change to HasCharset?

@crazycs520
Copy link
Contributor Author

/run-all-tests

1 similar comment
@zhouqiang-cl
Copy link
Contributor

/run-all-tests

@zhouqiang-cl
Copy link
Contributor

/rebuild

Copy link
Member

@bb7133 bb7133 left a comment

Choose a reason for hiding this comment

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

LGTM

However, obviously, we should not judge column type from their charsets. It should be corrected in some other PRs.

Copy link
Contributor

@winkyao winkyao left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

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

LGTM

@zimulala
Copy link
Contributor

zimulala commented Jun 4, 2019

/run-all-tests

@zimulala zimulala added the status/LGT3 The PR has already had 3 LGTM. label Jun 4, 2019
@crazycs520
Copy link
Contributor Author

/run-all-tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/sql-infra SIG: SQL Infra status/LGT3 The PR has already had 3 LGTM. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants