Bug #76450 generated column with "KEY" makes PRIMARY KEY

Submitted: 23 Mar 2015 10:43 Modified: 24 Mar 2015 7:33
Reporter: Tsubasa Tanaka (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DDL Severity:S3 (Non-critical)
Version:5.7.6 OS:Linux (CentOS 6.5)
Assigned to: CPU Architecture:Any

[23 Mar 2015 10:43] Tsubasa Tanaka
Description:
When creating generated column with "KEY" keyword, MySQL always tries to make PRIMARY KEY.

Is that an expected behavier? (that means doc is not enough)
Or a Parser's bug?

I expected "KEY", not "PRIMARY"/"UNIQUE", makes SECONDARY INDEX.

http://dev.mysql.com/doc/refman/5.7/en/create-table.html#create-table-generated-columns

How to repeat:
mysql57> CREATE TABLE t2 (num int, val varchar(32) AS (md5(num)) STORED KEY);
Query OK, 0 rows affected (0.03 sec)

mysql57> SHOW CREATE TABLE t2\G
*************************** 1. row ***************************
       Table: t2
Create Table: CREATE TABLE `t2` (
  `num` int(11) DEFAULT NULL,
  `val` varchar(32) GENERATED ALWAYS AS (md5(num)) STORED NOT NULL,
  PRIMARY KEY (`val`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
[23 Mar 2015 13:37] MySQL Verification Team
Hello Tanaka-San,

Thank you for the report.

Thanks,
Umesh
[24 Mar 2015 7:29] Øystein Grøvlen
Posted by developer:
 
Generated columns follow the same syntax as ordinary columns.  For ordinary columns, the manual already says: 
"The key attribute PRIMARY KEY can also be specified as just KEY when given in a column definition." 
(http://dev.mysql.com/doc/refman/5.7/en/create-table.html)
[24 Mar 2015 7:33] Tsubasa Tanaka
I confirmed that you're correct.

mysql57> create table t1 (num int key);
Query OK, 0 rows affected (0.04 sec)

mysql57> show create table t1\G
*************************** 1. row ***************************
       Table: t1
Create Table: CREATE TABLE `t1` (
  `num` int(11) NOT NULL,
  PRIMARY KEY (`num`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)

I change this case's status to "Closed", and I'm sorry to taking your time.
Thanks,

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.052 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.