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

create table for invisible unique key with auto_increment should have same behavior with it's show create tables #28093

Closed
aytrack opened this issue Sep 16, 2021 · 5 comments · Fixed by #30477
Assignees
Labels
severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@aytrack
Copy link
Contributor

aytrack commented Sep 16, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create table t0(a int auto_increment, unique key (a) invisible);
show create table t0;
CREATE TABLE `t1` (  `a` int(11) NOT NULL AUTO_INCREMENT,  UNIQUE KEY `a` (`a`) /*!80000 INVISIBLE */) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

2. What did you expect to see? (Required)

mysql> create table t0(a int auto_increment, unique key (a) invisible);
ERROR 3522 (HY000): A primary key index cannot be invisible

the sql of create table t0 should have same behavior with show create table result.

3. What did you see instead (Required)

MySQL root@127.0.0.1:test> create table t0(a int auto_increment, unique key (a) invisible);
                       ->  show create table t0;
                       ->  CREATE TABLE `t1` (  `a` int(11) NOT NULL AUTO_INCREMENT,  UNIQUE KEY `a` (`a`) /*!80000 INVISIBLE */) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
Query OK, 0 rows affected
Time: 0.145s

+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                           |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t0    | CREATE TABLE `t0` (\n  `a` int(11) NOT NULL AUTO_INCREMENT,\n  UNIQUE KEY `a` (`a`) /*!80000 INVISIBLE */\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin |
+-------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

1 row in set
Time: 0.010s
(3522, 'A primary key index cannot be invisible')

4. What is your TiDB version? (Required)

master( 6ebfe8a)

@aytrack aytrack added type/bug The issue is confirmed as a bug. sig/sql-infra SIG: SQL Infra severity/moderate labels Sep 16, 2021
@wjhuang2016
Copy link
Member

It's the expected behavior.
MySQL:

mysql> CREATE TABLE `t1` (  `a` int(11) NOT NULL AUTO_INCREMENT,  UNIQUE KEY `a` (`a`) /*!80000 INVISIBLE */) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
ERROR 3522 (HY000): A primary key index cannot be invisible

If a has not null, then it would be the implicit primary key in MySQL. To be compatible with MySQL, TiDB also forbids this usage.

@wjhuang2016 wjhuang2016 added wontfix This issue will not be fixed. and removed type/bug The issue is confirmed as a bug. severity/moderate labels Sep 17, 2021
@aytrack
Copy link
Contributor Author

aytrack commented Sep 17, 2021

the problem is,

create table t0(a int auto_increment, unique key (a) invisible);

above sql has't the not null and can execute success, but show create table got the not null

MySQL > show create table t0\G
***************************[ 1. row ]***************************
Table        | t0
Create Table | CREATE TABLE `t0` (
  `a` int(11) NOT NULL AUTO_INCREMENT,
  UNIQUE KEY `a` (`a`) /*!80000 INVISIBLE */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin

while use the show create table info to create a new table will got A primary key index cannot be invisible error.

for mysql, an unique index with auto_increment but without not null, it will be return the error.

mysql> create table t0(a int auto_increment, unique key (a) invisible);
ERROR 3522 (HY000): A primary key index cannot be invisible

@aytrack
Copy link
Contributor Author

aytrack commented Sep 17, 2021

If need to be compatible with MySQL, TiDB should forbids create table t0(a int auto_increment, unique key (a) invisible);, otherwise it should have same behavior with the show create table info

@wjhuang2016
Copy link
Member

I get it.

@wjhuang2016 wjhuang2016 added type/bug The issue is confirmed as a bug. severity/moderate and removed wontfix This issue will not be fixed. labels Sep 22, 2021
@github-actions
Copy link

github-actions bot commented Dec 7, 2021

Please check whether the issue should be labeled with 'affects-x.y' or 'fixes-x.y.z', and then remove 'needs-more-info' label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants