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

parser: Support alter convert to syntax #6416

Merged
merged 4 commits into from
Apr 28, 2018

Conversation

spongedu
Copy link
Contributor

for #6394.
This PR support the ALTER TABLE CONVERT TO CHARACTER SET charset_name [COLLATE collation_name] syntax, but not actually change the charset or collation. That's because for now, nothing is done when change character set or collation in ALTER TABLE statements in TiDB, the related TableOption are ignored in function AlterTable in ddl/ddl_api.go.
For example:
In MySQL

mysql> create table t1 (a tinytext character set latin1);                                                                                    
Query OK, 0 rows affected (0.03 sec)

mysql> show create table t1;
+-------+---------------------------------------------------------------------------+
| Table | Create Table                                                              |
+-------+---------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `a` tinytext
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+---------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> alter table t1 default character set utf8;
Query OK, 0 rows affected (0.03 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show create table t1;                                                                                                                 
+-------+----------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                 |
+-------+----------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `a` tinytext CHARACTER SET latin1
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+----------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> alter table t1 default collate latin1_bin;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> show create table t1;                                                                                                                 
+-------+-------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                      |
+-------+-------------------------------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `a` tinytext CHARACTER SET latin1
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin |
+-------+-------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

In TiDB:

tidb> create table t1 (a tinytext character set latin1);
Query OK, 0 rows affected (0.01 sec)

tidb> show create table t1;                                                                                                                  +-------+-------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                          |
+-------+-------------------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `a` tinytext DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin |
+-------+-------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

tidb>                                                                                                                                        tidb> alter table t1 default character set latin1;
Query OK, 0 rows affected (0.00 sec)

tidb> show create table t1;                                                                                                                  +-------+-------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                          |
+-------+-------------------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `a` tinytext DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin |
+-------+-------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

tidb> alter table t1 default collate latin1_bin;
Query OK, 0 rows affected (0.00 sec)

tidb> show create table t1;                                                                                                                  
+-------+-------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                          |
+-------+-------------------------------------------------------------------------------------------------------+
| t1    | CREATE TABLE `t1` (
  `a` tinytext DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin |
+-------+-------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

Maybe we should fix this in another PR.

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

@spongedu maybe we can just return a warning to client, this is easier than supporting another collate.

@zz-jason zz-jason added contribution This PR is from a community contributor. status/LGT1 Indicates that a PR has LGTM 1. labels Apr 28, 2018
@coocood
Copy link
Member

coocood commented Apr 28, 2018

LGTM

@coocood coocood added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Apr 28, 2018
@coocood
Copy link
Member

coocood commented Apr 28, 2018

/run-all-tests

@zz-jason zz-jason merged commit 2b3ccc4 into pingcap:master Apr 28, 2018
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. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants