Bug #72047 | Manual does not explain names for indexes generated for FOREIGN keys properly | ||
---|---|---|---|
Submitted: | 15 Mar 2014 16:20 | Modified: | 29 Oct 2014 12:00 |
Reporter: | Valeriy Kravchuk | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Documentation | Severity: | S3 (Non-critical) |
Version: | 5.6 | OS: | Any |
Assigned to: | Daniel Price | CPU Architecture: | Any |
Tags: | foreign key, information_schema, innodb_sys_indexes |
[15 Mar 2014 16:20]
Valeriy Kravchuk
[17 Mar 2014 6:41]
MySQL Verification Team
Hello Valeriy, Thank you for the report. Thanks, Umesh
[23 Oct 2014 14:59]
Daniel Price
Posted by developer: Regarding this issue: "I've never seen names like ID_IND, FOR_IND or REF_IND in MySQL 5.6 for any other tables but InnoDB's own system tables." Using the FK linked tables provided above, here is an example of user created tables with FOR_IND, ID_IND, and REF_IND indexes. mysql> Select t.table_id, t.name, i.name from information_schema.innodb_sys_tables t, information_schema.innodb_sys_indexes i where t.name LIKE 'test%' AND i.name LIKE '%_IND' ORDER BY i.name; +----------+-------------+---------+ | table_id | name | name | +----------+-------------+---------+ | 3771 | test/child | FOR_IND | | 3770 | test/parent | FOR_IND | | 3771 | test/child | ID_IND | | 3770 | test/parent | ID_IND | | 3771 | test/child | ID_IND | | 3770 | test/parent | ID_IND | | 3771 | test/child | REF_IND | | 3770 | test/parent | REF_IND | +----------+-------------+---------+ 8 rows in set (0.00 sec)
[23 Oct 2014 21:28]
Daniel Price
Posted by developer: The "Using FOREIGN KEY" Constraints section explains that a name for a constraint is automatically generated if not provided: http://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html If the CONSTRAINT symbol clause is given, the symbol value, if used, must be unique in the database. A duplicate symbol will result in an error similar to: ERROR 1022 (2300): Can't write; duplicate key in table '#sql- 464_1'. If the clause is not given, or a symbol is not included following the CONSTRAINT keyword, a name for the constraint is created automatically.
[29 Oct 2014 0:56]
Daniel Price
Regarding foreign key index naming: 0) If there is an explicitly defined index which can support FK, which is being created, its name will be used. Implicit supporting index won't be created in this case. verified. 1) If there is no explicit supporting index for FK, implicit index will be created. Its name is determined using the following rules: a) If CONSTRAINT <symbol> clause is present in FK definition <ident> will be used as name of implicit index. b) Otherwise name from FOREIGN KEY <index_name> clause will be used. c) If there is no CONSTRAINT clause and FOREIGN KEY clause doesn't specify foreign key name, the name will be auto-generated from referencing column names (as it happens for ordinary KEYs).
[29 Oct 2014 12:00]
Daniel Price
Posted by developer: The FOREIGN KEY index_name option description has been revised to full explain foreign key index naming. http://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html Thank you for the bug report.