Bug #96508 Inconsistent naming of foreign keys over NDB tables

Submitted: 12 Aug 2019 10:51 Modified: 22 Aug 2019 14:38
Reporter: Dmitry Lenev Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DDL Severity:S3 (Non-critical)
Version:8.0.18-git OS:Any
Assigned to: CPU Architecture:Any

[12 Aug 2019 10:51] Dmitry Lenev
Description:
In MySQL 8.0 names of foreign keys which were not explicitly provided by
user are automatically generated by SQL-layer and stored in data-dictionary.
Such names have form "<table_name>_ibfk_<number>" so are aligned with
names which were generated by InnoDB SE in 5.7.

However, NDB SE still generates and uses different format for such names
internally "fk_<some_internal_id>_<other_internal_id>" instead of using
 names generated by SQL-layer and stored in DD.

This creates some issues:
- Discrepancies in SHOW CREATE TABLE output and I_S.REFENTIAL_CONSTRAINTS
  contents.
- Improper MDL locking for foreign keys (since it relies on names
  generated by SQL-layer).
- Confusing names of foreign keys in error messages.

How to repeat:
CREATE TABLE parent (pk INT PRIMARY KEY) ENGINE=NDBCLUSTER;
CREATE TABLE child (fk1 INT, fk2 INT,
	FOREIGN KEY (fk1) REFERENCES parent (pk),
	CONSTRAINT c1 FOREIGN KEY (fk2) REFERENCES parent (pk)) ENGINE=NDBCLUSTER;
SHOW CREATE TABLE child;
#	Table  	Create Table
#	child  	CREATE TABLE `child` (
#		  `fk1` int(11) DEFAULT NULL,
#		  `fk2` int(11) DEFAULT NULL,
#		  KEY `fk1` (`fk1`),
#		  KEY `c1` (`fk2`),
#		  CONSTRAINT `FK_13_16` FOREIGN KEY (`fk1`) REFERENCES `parent` (`pk`) ON DELETE NO ACTION ON UPDATE NO ACTION,
#		  CONSTRAINT `c1` FOREIGN KEY (`fk2`) REFERENCES `parent` (`pk`) ON DELETE NO ACTION ON UPDATE NO ACTION
#		) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
SELECT * FROM information_schema.referential_constraints;
#	CONSTRAINT_CATALOG     CONSTRAINT_SCHEMA       CONSTRAINT_NAME UNIQUE_CONSTRAINT_CATALOG       UNIQUE_CONSTRAINT_SCHEMA        UNIQUE_CONSTRAINT_NAME  MATCH_OPTION    UPDATE_RULE     DELETE_RULE    TABLE_NAME      REFERENCED_TABLE_NAME
#	def    test    child_ibfk_1    def     test    PRIMARY NONE    NO ACTION       NO ACTION       child   parent
#	def    test    c1      def     test    PRIMARY NONE    NO ACTION       NO ACTION       child   parent

Suggested fix:
Per discussion with NDB team we need to change NDB SE to use names generated
by SQL-layer. We also should use non-SE dependent suffix _fk_ (rather than
_ibfk_) for such names at least for NDB tables.
[22 Aug 2019 14:38] Paul DuBois
Posted by developer:
 
Fixed in 8.0.18.

NDB Cluster now uses tbl_name_fk_N as the naming pattern for
internally generated foreign keys, which is similar to the
tbl_name_ibfk_N pattern used by InnoDB.
[22 Nov 2019 16:12] Jon Stephens
See also BUG#96602.

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.