Bug #70696 Restriction on FK parents being Unique key not documented

Submitted: 23 Oct 2013 10:24 Modified: 24 Oct 2013 1:37
Reporter: Andrew Morgan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:7.3 OS:Any
Assigned to: Jon Stephens CPU Architecture:Any
Tags: documentation, foreign keys

[23 Oct 2013 10:24] Andrew Morgan
Description:
Unlike InnoDB, NDB insists that the parent index is unique and the addition of a constraint fails if it isn't. As this difference exists, it should be documented.

How to repeat:
CREATE TABLE campuses (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
code varchar(30) NOT NULL,
PRIMARY KEY (id),
KEY name (name),
KEY code (code)
) ENGINE=ndbcluster AUTO_INCREMENT=152 DEFAULT CHARSET=latin1;

CREATE TABLE thresholdtriggers (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(60) NOT NULL,
threshold_amount decimal(10,2) NOT NULL,
emails text NOT NULL,
PRIMARY KEY (id)
) ENGINE=ndbcluster DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS thresholdtriggerstocampuses (
id int(11) NOT NULL AUTO_INCREMENT,
threshold_trigger_id int(11) NOT NULL,
campus_code varchar(30) NOT NULL,
PRIMARY KEY (id),
KEY threshold_trigger_id (threshold_trigger_id),
KEY campus_code (campus_code),
CONSTRAINT thresholdtriggerstocampuses_ibfk_2 FOREIGN KEY (campus_code) REFERENCES campuses (code) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=ndbcluster DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;

+---------+------+------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                        |
+---------+------+------------------------------------------------------------------------------------------------+
| Warning | 1296 | Got error 21026 'Create foreign key failed in NDB - parent index is not unique index' from NDB |
| Error   | 1215 | Cannot add foreign key constraint                                                              |
+---------+------+------------------------------------------------------------------------------------------------+

If I then make campuses.code be a UNIQUE key then it passes.

Suggested fix:
Document this restriction in http://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html
[23 Oct 2013 11:00] MySQL Verification Team
Hello Andrew,

Thank you for the bug report and test case.
Verified as described.

Thanks,
Umesh
[24 Oct 2013 1:34] Jon Stephens
Wrong category. If you want me to fix Docs bugs, they need to be filed as *Docs* bugs.
[24 Oct 2013 1:37] Jon Stephens
Fixed in mysqldoc rev 36506. Closed.

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

Page generated in 0.040 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.