Skip to content

Commit c1c1453

Browse files
committed
Bug#36345882 Contribution: [RONDB-620] Fix column ordering in Dbdict::buildFK_prepare
Contributed by Axel Svensson. If one have a table with data adding a multicolumn foreign key constraint could fail even if the data satisifies the constraint. Namely if the order columns are mentioned in the references clause do not match the order the columns are defined for the table. Example#1, alter table add constraint foreign key: mysql> create table prnt (pk1 int, pk2 int, primary key(pk2,pk1) -> ) engine=ndbcluster; mysql> create table chld (pk int primary key, col1 int, col2 int -> ) engine=ndbcluster; mysql> insert into prnt values (1,2); mysql> insert into chld values (0,1,2); mysql> alter table chld add -> constraint fk foreign key(col2,col1) -> references prnt(pk2,pk1); mysql> \W Show warnings enabled. mysql> alter table chld -> add constraint fk foreign key(col2,col1) -> references prnt(pk2,pk1); ERROR 1215 (HY000): Cannot add foreign key constraint Warning (Code 1296): Got error 21033 'Create foreign key failed in NDB - No parent row found' from NDB Error (Code 1215): Cannot add foreign key constraint Example#2, ndb_restore --rebuild-indexes: mysql> create table prnt (pk1 int, pk2 int, primary key(pk2,pk1) -> ) engine=ndbcluster; mysql> create table chld (pk int primary key, col1 int, col2 int, -> constraint fk foreign key(col2,col1) -> references prnt(pk2,pk1) -> ) engine=ndbcluster; mysql> insert into prnt values (1,2); mysql> insert into chld values (0,1,2); ndb_mgm> start backup ... Node 1: Backup 1 started from node 3 completed mysql> drop table chld, prnt; $ ndb_restore -b 1 -n 1 -m --disable-indexes BACKUP/BACKUP-1 $ ndb_restore -b 1 -n 1 -r --disable-indexes BACKUP/BACKUP-1 $ ndb_restore -b 1 -n 2 -r --disable-indexes BACKUP/BACKUP-1 $ ndb_restore -b 1 -n 1 --rebuild-indexes BACKUP/BACKUP-1 ... Failed to create foreign key fk parent test.prnt.PK child test.chld.fk : 21033: Create foreign key failed in NDB - No parent row found Problem: When checking the existing data for a pending foreign key constraint with multi column key, columns from referencing table were matches with the columns in the referenced table in wrong order. In the examples above, the columns (col2,col1) from referencing table is matches against columns (pk1,pk2) in referenced table resulting in col2 is matched against pk1 and col1 against pk2 instead of the intention to match col2 against pk2 and col1 against pk1. The checking code expected the index in parent table to use the same column order as specified in the references clause of constraint definition. But unique indexes in NDB always uses the column order as they appear in table definition. In example above: - PRIMARY KEY(pk1,pk2) - PRIMARY KEY(pk2,pk1) - UNIQUE KEY(pk1,pk2) - UNIQUE KEY(pk2,pk1) all would use key with column order as (pk1,pk2) since that is the order in table definition create table prnt (pk1 int, pk2 int) Also note that the ordered index in the child table must have the columns in the order specified in the constraint. Note that the code maintaining the foreign key constraint did handle multicolumn keys correctly. Fix: When Dbdict sends GSN_BUILD_FK_IMPL_REQ to TRIX it now sends the child columns to fetch matching the parent index order. Change-Id: I3bd57d3d2c36628c1dc03e1f590a2d5bcb9b04de
1 parent e52b3ad commit c1c1453

File tree

7 files changed

+569
-54
lines changed

7 files changed

+569
-54
lines changed

mysql-test/suite/ndb/include/ndb_desc_print.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ let $ndb_desc_cmd= $NDB_DESC $ndb_desc_opts;
1919
replace_regex /Version: [0-9]*/Version: Any/
2020
/NDB\$BLOB_[0-9]*_/NDB$BLOB_XX_/
2121
/Length of frm data: [0-9]*/Length of frm data: XXX/
22+
/^[0-9]+\/[0-9]+/XX\/XX/
2223
/IndexTable [0-9]*/IndexTable XX/
2324
/^([0-9][0-9]*) [0-9 ]*/\1 .../
2425
/Table id: [0-9]*/Table id: XXX/

mysql-test/suite/ndb/r/ndb_fk_build.result

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,52 @@ drop foreign key fk4,
6666
drop foreign key fk5,
6767
drop foreign key fk6;
6868
drop table parent, child;
69+
create table parent (
70+
b1 int as (b) stored not null,
71+
c1 int as (c) stored not null,
72+
a1 int as (a) stored not null,
73+
b2 int as (b) stored not null,
74+
c2 int as (c) stored not null,
75+
a2 int as (a) stored not null,
76+
a int default 0,
77+
b int default 0,
78+
c int default 0,
79+
primary key pk1 (a1,b1,c1) using hash,
80+
unique key uk2 (a2,b2,c2) using hash
81+
) engine=ndbcluster;
82+
create table child (
83+
a int default 0,
84+
b int default 0,
85+
c int default 0,
86+
d int default 0,
87+
e int default 0,
88+
f int default 0,
89+
b1 int as (b) stored not null,
90+
c1 int as (c) stored not null,
91+
a1 int as (a) stored not null,
92+
b2 int as (b) stored not null,
93+
c2 int as (c) stored not null,
94+
a2 int as (a) stored not null,
95+
b3 int as (b) stored not null,
96+
c3 int as (c) stored not null,
97+
a3 int as (a) stored not null,
98+
primary key pk1 (a1,b1,c1) using hash,
99+
unique key uk2 (a2,b2,c2) using hash,
100+
key ok3 (a3,b3,c3),
101+
key ok3def (c3,b3,a3,d,e,f)
102+
) engine=ndbcluster;
103+
insert into parent (a, b, c) values (11, 12, 13);
104+
insert into child (a, b, c) values (11, 12, 13);
105+
alter table child add
106+
constraint fk11 foreign key (c1,b1,a1) references parent (c1,b1,a1);
107+
alter table child add
108+
constraint fk21 foreign key (c2,b2,a2) references parent (c1,b1,a1);
109+
alter table child add
110+
constraint fk31 foreign key (c3,b3,a3) references parent (c1,b1,a1);
111+
alter table child add
112+
constraint fk12 foreign key (c1,b1,a1) references parent (c2,b2,a2);
113+
alter table child add
114+
constraint fk22 foreign key (c2,b2,a2) references parent (c2,b2,a2);
115+
alter table child add
116+
constraint fk32 foreign key (c3,b3,a3) references parent (c2,b2,a2);
117+
drop table child, parent;

mysql-test/suite/ndb/r/ndb_fk_restore.result

Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,3 +542,267 @@ drop table db3.t5, db3.t4;
542542
# cleanup
543543
drop table db3.t6, db3.t7, db3.t8, db3.t9;
544544
drop database db3;
545+
#
546+
# Bug#36345882 Fix column ordering in Dbdict::buildFK_prepare
547+
#
548+
use test;
549+
create table t1 (
550+
b1 int as (b) stored not null,
551+
c1 int as (c) stored not null,
552+
a1 int as (a) stored not null,
553+
b2 int as (b) stored not null,
554+
c2 int as (c) stored not null,
555+
a2 int as (a) stored not null,
556+
a int default 0,
557+
b int default 0,
558+
c int default 0,
559+
primary key pk1 (a1,b1,c1) using hash,
560+
unique key uk2 (a2,b2,c2) using hash
561+
) engine=ndbcluster;
562+
create table t2 (
563+
a int default 0,
564+
b int default 0,
565+
c int default 0,
566+
d int default 0,
567+
e int default 0,
568+
f int default 0,
569+
b1 int as (b) stored not null,
570+
c1 int as (c) stored not null,
571+
a1 int as (a) stored not null,
572+
b2 int as (b) stored not null,
573+
c2 int as (c) stored not null,
574+
a2 int as (a) stored not null,
575+
b3 int as (b) stored not null,
576+
c3 int as (c) stored not null,
577+
a3 int as (a) stored not null,
578+
primary key pk1 (a1,b1,c1) using hash,
579+
unique key uk2 (a2,b2,c2) using hash,
580+
key ok3 (a3,b3,c3),
581+
key ok3def (c3,b3,a3,d,e,f),
582+
constraint fk11 foreign key (c1,b1,a1) references t1 (c1,b1,a1),
583+
constraint fk21 foreign key (c2,b2,a2) references t1 (c1,b1,a1),
584+
constraint fk31 foreign key (c3,b3,a3) references t1 (c1,b1,a1),
585+
constraint fk12 foreign key (c1,b1,a1) references t1 (c2,b2,a2),
586+
constraint fk22 foreign key (c2,b2,a2) references t1 (c2,b2,a2),
587+
constraint fk32 foreign key (c3,b3,a3) references t1 (c2,b2,a2)
588+
) engine=ndbcluster;
589+
alter table t2 drop index ok3;
590+
alter table t2 drop index fk12;
591+
alter table t2 drop index fk22;
592+
-- t1 --
593+
Version: Any
594+
Fragment type: HashMapPartition
595+
K Value: 6
596+
Min load factor: 78
597+
Max load factor: 80
598+
Temporary table: no
599+
Number of attributes: 9
600+
Number of primary keys: 3
601+
Length of frm data: XXX
602+
Max Rows: 0
603+
Row Checksum: 1
604+
Row GCI: 1
605+
SingleUserMode: 0
606+
ForceVarPart: 1
607+
PartitionCount: 8
608+
FragmentCount: 8
609+
PartitionBalance: FOR_RP_BY_LDM
610+
ExtraRowGciBits: 0
611+
ExtraRowAuthorBits: 0
612+
TableStatus: Retrieved
613+
Table options: readbackup
614+
HashMap: DEFAULT-HASHMAP-3840-8
615+
-- Attributes --
616+
b1 Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
617+
c1 Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
618+
a1 Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
619+
b2 Int NOT NULL AT=FIXED ST=MEMORY
620+
c2 Int NOT NULL AT=FIXED ST=MEMORY
621+
a2 Int NOT NULL AT=FIXED ST=MEMORY
622+
a Int NULL AT=FIXED ST=MEMORY DEFAULT 0
623+
b Int NULL AT=FIXED ST=MEMORY DEFAULT 0
624+
c Int NULL AT=FIXED ST=MEMORY DEFAULT 0
625+
-- Indexes --
626+
PRIMARY KEY(b1, c1, a1) - UniqueHashIndex
627+
uk2$unique(b2, c2, a2) - UniqueHashIndex
628+
-- t2 --
629+
Version: Any
630+
Fragment type: HashMapPartition
631+
K Value: 6
632+
Min load factor: 78
633+
Max load factor: 80
634+
Temporary table: no
635+
Number of attributes: 15
636+
Number of primary keys: 3
637+
Length of frm data: XXX
638+
Max Rows: 0
639+
Row Checksum: 1
640+
Row GCI: 1
641+
SingleUserMode: 0
642+
ForceVarPart: 1
643+
PartitionCount: 8
644+
FragmentCount: 8
645+
PartitionBalance: FOR_RP_BY_LDM
646+
ExtraRowGciBits: 0
647+
ExtraRowAuthorBits: 0
648+
TableStatus: Retrieved
649+
Table options: readbackup
650+
HashMap: DEFAULT-HASHMAP-3840-8
651+
-- Attributes --
652+
a Int NULL AT=FIXED ST=MEMORY DEFAULT 0
653+
b Int NULL AT=FIXED ST=MEMORY DEFAULT 0
654+
c Int NULL AT=FIXED ST=MEMORY DEFAULT 0
655+
d Int NULL AT=FIXED ST=MEMORY DEFAULT 0
656+
e Int NULL AT=FIXED ST=MEMORY DEFAULT 0
657+
f Int NULL AT=FIXED ST=MEMORY DEFAULT 0
658+
b1 Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
659+
c1 Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
660+
a1 Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
661+
b2 Int NOT NULL AT=FIXED ST=MEMORY
662+
c2 Int NOT NULL AT=FIXED ST=MEMORY
663+
a2 Int NOT NULL AT=FIXED ST=MEMORY
664+
b3 Int NOT NULL AT=FIXED ST=MEMORY
665+
c3 Int NOT NULL AT=FIXED ST=MEMORY
666+
a3 Int NOT NULL AT=FIXED ST=MEMORY
667+
-- Indexes --
668+
PRIMARY KEY(b1, c1, a1) - UniqueHashIndex
669+
uk2$unique(b2, c2, a2) - UniqueHashIndex
670+
ok3def(c3, b3, a3, d, e, f) - OrderedIndex
671+
-- ForeignKeys --
672+
XX/XX/fk11 PRIMARY KEY (c1, b1, a1) REFERENCES test.t1/PRIMARY KEY () on update noaction on delete noaction
673+
XX/XX/fk21 uk2$unique (c2, b2, a2) REFERENCES test.t1/PRIMARY KEY () on update noaction on delete noaction
674+
XX/XX/fk31 ok3def (c3, b3, a3) REFERENCES test.t1/PRIMARY KEY () on update noaction on delete noaction
675+
XX/XX/fk12 PRIMARY KEY (c1, b1, a1) REFERENCES test.t1/uk2$unique () on update noaction on delete noaction
676+
XX/XX/fk22 uk2$unique (c2, b2, a2) REFERENCES test.t1/uk2$unique () on update noaction on delete noaction
677+
XX/XX/fk32 ok3def (c3, b3, a3) REFERENCES test.t1/uk2$unique () on update noaction on delete noaction
678+
insert into t1 (a, b, c) values (11, 12, 13);
679+
insert into t2 (a, b, c) values (11, 12, 13);
680+
insert into t2 (a,b,c) values (101, 102, 103);
681+
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `fk11` FOREIGN KEY (`c1`,`b1`,`a1`) REFERENCES `t1` (`c1`,`b1`,`a1`) ON DELETE NO ACTION ON UPDATE NO ACTION)
682+
# show meta
683+
show create table t2;
684+
Table Create Table
685+
t2 CREATE TABLE `t2` (
686+
`a` int DEFAULT '0',
687+
`b` int DEFAULT '0',
688+
`c` int DEFAULT '0',
689+
`d` int DEFAULT '0',
690+
`e` int DEFAULT '0',
691+
`f` int DEFAULT '0',
692+
`b1` int GENERATED ALWAYS AS (`b`) STORED NOT NULL,
693+
`c1` int GENERATED ALWAYS AS (`c`) STORED NOT NULL,
694+
`a1` int GENERATED ALWAYS AS (`a`) STORED NOT NULL,
695+
`b2` int GENERATED ALWAYS AS (`b`) STORED NOT NULL,
696+
`c2` int GENERATED ALWAYS AS (`c`) STORED NOT NULL,
697+
`a2` int GENERATED ALWAYS AS (`a`) STORED NOT NULL,
698+
`b3` int GENERATED ALWAYS AS (`b`) STORED NOT NULL,
699+
`c3` int GENERATED ALWAYS AS (`c`) STORED NOT NULL,
700+
`a3` int GENERATED ALWAYS AS (`a`) STORED NOT NULL,
701+
PRIMARY KEY (`a1`,`b1`,`c1`) USING HASH,
702+
UNIQUE KEY `uk2` (`a2`,`b2`,`c2`) USING HASH,
703+
KEY `ok3def` (`c3`,`b3`,`a3`,`d`,`e`,`f`),
704+
CONSTRAINT `fk11` FOREIGN KEY (`c1`, `b1`, `a1`) REFERENCES `t1` (`c1`, `b1`, `a1`),
705+
CONSTRAINT `fk12` FOREIGN KEY (`c1`, `b1`, `a1`) REFERENCES `t1` (`c2`, `b2`, `a2`),
706+
CONSTRAINT `fk21` FOREIGN KEY (`c2`, `b2`, `a2`) REFERENCES `t1` (`c1`, `b1`, `a1`),
707+
CONSTRAINT `fk22` FOREIGN KEY (`c2`, `b2`, `a2`) REFERENCES `t1` (`c2`, `b2`, `a2`),
708+
CONSTRAINT `fk31` FOREIGN KEY (`c3`, `b3`, `a3`) REFERENCES `t1` (`c1`, `b1`, `a1`),
709+
CONSTRAINT `fk32` FOREIGN KEY (`c3`, `b3`, `a3`) REFERENCES `t1` (`c2`, `b2`, `a2`)
710+
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
711+
select type,name from ndb_show_tables_results
712+
where type in ('''ForeignKey''','''FKParentTrigger''','''FKChildTrigger''');
713+
type name
714+
'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
715+
'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
716+
'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
717+
'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
718+
'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
719+
'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
720+
'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
721+
'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
722+
'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
723+
'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
724+
'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
725+
'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
726+
'ForeignKey' 'XX/XX/fk11'
727+
'ForeignKey' 'XX/XX/fk12'
728+
'ForeignKey' 'XX/XX/fk21'
729+
'ForeignKey' 'XX/XX/fk22'
730+
'ForeignKey' 'XX/XX/fk31'
731+
'ForeignKey' 'XX/XX/fk32'
732+
# show counts
733+
select count(*) from t1;
734+
count(*)
735+
1
736+
select count(*) from t2;
737+
count(*)
738+
1
739+
# run backup
740+
# drop tables
741+
drop table t2, t1;
742+
# restore meta (disable indexes)
743+
# restore data (disable indexes)
744+
# rebuild indexes
745+
# show meta
746+
show create table t2;
747+
Table Create Table
748+
t2 CREATE TABLE `t2` (
749+
`a` int DEFAULT '0',
750+
`b` int DEFAULT '0',
751+
`c` int DEFAULT '0',
752+
`d` int DEFAULT '0',
753+
`e` int DEFAULT '0',
754+
`f` int DEFAULT '0',
755+
`b1` int GENERATED ALWAYS AS (`b`) STORED NOT NULL,
756+
`c1` int GENERATED ALWAYS AS (`c`) STORED NOT NULL,
757+
`a1` int GENERATED ALWAYS AS (`a`) STORED NOT NULL,
758+
`b2` int GENERATED ALWAYS AS (`b`) STORED NOT NULL,
759+
`c2` int GENERATED ALWAYS AS (`c`) STORED NOT NULL,
760+
`a2` int GENERATED ALWAYS AS (`a`) STORED NOT NULL,
761+
`b3` int GENERATED ALWAYS AS (`b`) STORED NOT NULL,
762+
`c3` int GENERATED ALWAYS AS (`c`) STORED NOT NULL,
763+
`a3` int GENERATED ALWAYS AS (`a`) STORED NOT NULL,
764+
PRIMARY KEY (`a1`,`b1`,`c1`) USING HASH,
765+
UNIQUE KEY `uk2` (`a2`,`b2`,`c2`) USING HASH,
766+
KEY `ok3def` (`c3`,`b3`,`a3`,`d`,`e`,`f`),
767+
CONSTRAINT `fk11` FOREIGN KEY (`c1`, `b1`, `a1`) REFERENCES `t1` (`c1`, `b1`, `a1`),
768+
CONSTRAINT `fk12` FOREIGN KEY (`c1`, `b1`, `a1`) REFERENCES `t1` (`c2`, `b2`, `a2`),
769+
CONSTRAINT `fk21` FOREIGN KEY (`c2`, `b2`, `a2`) REFERENCES `t1` (`c1`, `b1`, `a1`),
770+
CONSTRAINT `fk22` FOREIGN KEY (`c2`, `b2`, `a2`) REFERENCES `t1` (`c2`, `b2`, `a2`),
771+
CONSTRAINT `fk31` FOREIGN KEY (`c3`, `b3`, `a3`) REFERENCES `t1` (`c1`, `b1`, `a1`),
772+
CONSTRAINT `fk32` FOREIGN KEY (`c3`, `b3`, `a3`) REFERENCES `t1` (`c2`, `b2`, `a2`)
773+
) ENGINE=ndbcluster DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
774+
select type,name from ndb_show_tables_results
775+
where type in ('''ForeignKey''','''FKParentTrigger''','''FKChildTrigger''');
776+
type name
777+
'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
778+
'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
779+
'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
780+
'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
781+
'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
782+
'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
783+
'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
784+
'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
785+
'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
786+
'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
787+
'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
788+
'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
789+
'ForeignKey' 'XX/XX/fk11'
790+
'ForeignKey' 'XX/XX/fk12'
791+
'ForeignKey' 'XX/XX/fk21'
792+
'ForeignKey' 'XX/XX/fk22'
793+
'ForeignKey' 'XX/XX/fk31'
794+
'ForeignKey' 'XX/XX/fk32'
795+
# show counts
796+
select count(*) from t1;
797+
count(*)
798+
1
799+
select count(*) from t2;
800+
count(*)
801+
1
802+
select * from t1;
803+
b1 c1 a1 b2 c2 a2 a b c
804+
12 13 11 12 13 11 11 12 13
805+
select * from t2;
806+
a b c d e f b1 c1 a1 b2 c2 a2 b3 c3 a3
807+
11 12 13 0 0 0 12 13 11 12 13 11 12 13 11
808+
drop table t2,t1;

mysql-test/suite/ndb/t/ndb_fk_build.test

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,61 @@ drop foreign key fk5,
7272
drop foreign key fk6;
7373

7474
drop table parent, child;
75+
76+
# Check multi column foreign keys
77+
78+
eval create table parent (
79+
b1 int as (b) stored not null,
80+
c1 int as (c) stored not null,
81+
a1 int as (a) stored not null,
82+
b2 int as (b) stored not null,
83+
c2 int as (c) stored not null,
84+
a2 int as (a) stored not null,
85+
a int default 0,
86+
b int default 0,
87+
c int default 0,
88+
primary key pk1 (a1,b1,c1) using hash,
89+
unique key uk2 (a2,b2,c2) using hash
90+
) engine=ndbcluster;
91+
92+
eval create table child (
93+
a int default 0,
94+
b int default 0,
95+
c int default 0,
96+
d int default 0,
97+
e int default 0,
98+
f int default 0,
99+
b1 int as (b) stored not null,
100+
c1 int as (c) stored not null,
101+
a1 int as (a) stored not null,
102+
b2 int as (b) stored not null,
103+
c2 int as (c) stored not null,
104+
a2 int as (a) stored not null,
105+
b3 int as (b) stored not null,
106+
c3 int as (c) stored not null,
107+
a3 int as (a) stored not null,
108+
primary key pk1 (a1,b1,c1) using hash,
109+
unique key uk2 (a2,b2,c2) using hash,
110+
key ok3 (a3,b3,c3),
111+
key ok3def (c3,b3,a3,d,e,f)
112+
) engine=ndbcluster;
113+
114+
# Add parent row, use different values for the different columns.
115+
insert into parent (a, b, c) values (11, 12, 13);
116+
# Add valid child row.
117+
insert into child (a, b, c) values (11, 12, 13);
118+
119+
alter table child add
120+
constraint fk11 foreign key (c1,b1,a1) references parent (c1,b1,a1);
121+
alter table child add
122+
constraint fk21 foreign key (c2,b2,a2) references parent (c1,b1,a1);
123+
alter table child add
124+
constraint fk31 foreign key (c3,b3,a3) references parent (c1,b1,a1);
125+
alter table child add
126+
constraint fk12 foreign key (c1,b1,a1) references parent (c2,b2,a2);
127+
alter table child add
128+
constraint fk22 foreign key (c2,b2,a2) references parent (c2,b2,a2);
129+
alter table child add
130+
constraint fk32 foreign key (c3,b3,a3) references parent (c2,b2,a2);
131+
132+
drop table child, parent;

0 commit comments

Comments
 (0)