Bug #78150 Failure creating composite FKs referencing composite PKs of parent
Submitted: 20 Aug 2015 12:03 Modified: 4 Sep 2015 16:45
Reporter: Lakshmi Narayanan Sreethar Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Cluster: Cluster (NDB) storage engine Severity:S3 (Non-critical)
Version:7.4.7 OS:Any
Assigned to: CPU Architecture:Any

[20 Aug 2015 12:03] Lakshmi Narayanan Sreethar
Description:
Trying to create a table with composite FKs referencing composite PKs of the parent table fails if one of the column in the composite FK is primary and unique. The problem seems to be in the find_matching_index function in the ha_ndbcluster. 

How to repeat:
mysql> create table t1(
    -> a int not null,
    -> b int not null,
    -> primary key pk1(a,b)
    -> ) engine ndb;
Query OK, 0 rows affected (0.67 sec)

mysql> create table t2 (
    -> a int primary key,
    -> b int not null,
    -> unique key uniquea(a),
    -> foreign key fkab(a,b) references t1(a,b)
    -> ) engine ndb;
ERROR 1296 (HY000): Got error 21021 'Create foreign key failed in NDB - invalid request' from NDBCLUSTER

Suggested fix:
Returning proper child/parent index to the createForeignKey function might solve this problem.
[4 Sep 2015 16:45] Jon Stephens
Documented fix in the NDB 7.3.11 and 7.4.8 changelogs, as follows:

    Trying to create an NDB table with a composite foreign key
    referencing a composite primary key of the parent table failed
    when one of the columns in the composite foreign key was the
    primary key and had a unique index.

Closed.