@@ -594,3 +594,276 @@ drop table db3.t5, db3.t4;
594
594
# cleanup
595
595
drop table db3.t6, db3.t7, db3.t8, db3.t9;
596
596
drop database db3;
597
+ #
598
+ # Bug#36345882 Fix column ordering in Dbdict::buildFK_prepare
599
+ #
600
+ use test;
601
+ create table t1 (
602
+ b1 int as (b) stored not null,
603
+ c1 int as (c) stored not null,
604
+ a1 int as (a) stored not null,
605
+ b2 int as (b) stored not null,
606
+ c2 int as (c) stored not null,
607
+ a2 int as (a) stored not null,
608
+ a int default 0,
609
+ b int default 0,
610
+ c int default 0,
611
+ primary key pk1 (a1,b1,c1) using hash,
612
+ unique key uk2 (a2,b2,c2) using hash
613
+ ) engine=ndbcluster;
614
+ create table t2 (
615
+ a int default 0,
616
+ b int default 0,
617
+ c int default 0,
618
+ d int default 0,
619
+ e int default 0,
620
+ f int default 0,
621
+ b1 int as (b) stored not null,
622
+ c1 int as (c) stored not null,
623
+ a1 int as (a) stored not null,
624
+ b2 int as (b) stored not null,
625
+ c2 int as (c) stored not null,
626
+ a2 int as (a) stored not null,
627
+ b3 int as (b) stored not null,
628
+ c3 int as (c) stored not null,
629
+ a3 int as (a) stored not null,
630
+ primary key pk1 (a1,b1,c1) using hash,
631
+ unique key uk2 (a2,b2,c2) using hash,
632
+ key ok3 (a3,b3,c3),
633
+ key ok3def (c3,b3,a3,d,e,f),
634
+ constraint fk11 foreign key (c1,b1,a1) references t1 (c1,b1,a1),
635
+ constraint fk21 foreign key (c2,b2,a2) references t1 (c1,b1,a1),
636
+ constraint fk31 foreign key (c3,b3,a3) references t1 (c1,b1,a1),
637
+ constraint fk12 foreign key (c1,b1,a1) references t1 (c2,b2,a2),
638
+ constraint fk22 foreign key (c2,b2,a2) references t1 (c2,b2,a2),
639
+ constraint fk32 foreign key (c3,b3,a3) references t1 (c2,b2,a2)
640
+ ) engine=ndbcluster;
641
+ alter table t2 drop index ok3;
642
+ alter table t2 drop index fk12;
643
+ alter table t2 drop index fk22;
644
+ -- t1 --
645
+ Version: Any
646
+ Fragment type: HashMapPartition
647
+ K Value: 6
648
+ Min load factor: 78
649
+ Max load factor: 80
650
+ Temporary table: no
651
+ Number of attributes: 9
652
+ Number of primary keys: 3
653
+ Length of frm data: XXX
654
+ Max Rows: 0
655
+ Row Checksum: 1
656
+ Row GCI: 1
657
+ SingleUserMode: 0
658
+ ForceVarPart: 1
659
+ PartitionCount: 8
660
+ FragmentCount: 8
661
+ PartitionBalance: FOR_RP_BY_LDM
662
+ ExtraRowGciBits: 0
663
+ ExtraRowAuthorBits: 0
664
+ TableStatus: Retrieved
665
+ Table options:
666
+ HashMap: DEFAULT-HASHMAP-3840-8
667
+ -- Attributes --
668
+ b1 Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
669
+ c1 Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
670
+ a1 Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
671
+ b2 Int NOT NULL AT=FIXED ST=MEMORY
672
+ c2 Int NOT NULL AT=FIXED ST=MEMORY
673
+ a2 Int NOT NULL AT=FIXED ST=MEMORY
674
+ a Int NULL AT=FIXED ST=MEMORY DEFAULT 0
675
+ b Int NULL AT=FIXED ST=MEMORY DEFAULT 0
676
+ c Int NULL AT=FIXED ST=MEMORY DEFAULT 0
677
+ -- Indexes --
678
+ PRIMARY KEY(b1, c1, a1) - UniqueHashIndex
679
+ uk2$unique(b2, c2, a2) - UniqueHashIndex
680
+ -- t2 --
681
+ Version: Any
682
+ Fragment type: HashMapPartition
683
+ K Value: 6
684
+ Min load factor: 78
685
+ Max load factor: 80
686
+ Temporary table: no
687
+ Number of attributes: 15
688
+ Number of primary keys: 3
689
+ Length of frm data: XXX
690
+ Max Rows: 0
691
+ Row Checksum: 1
692
+ Row GCI: 1
693
+ SingleUserMode: 0
694
+ ForceVarPart: 1
695
+ PartitionCount: 8
696
+ FragmentCount: 8
697
+ PartitionBalance: FOR_RP_BY_LDM
698
+ ExtraRowGciBits: 0
699
+ ExtraRowAuthorBits: 0
700
+ TableStatus: Retrieved
701
+ Table options:
702
+ HashMap: DEFAULT-HASHMAP-3840-8
703
+ -- Attributes --
704
+ a Int NULL AT=FIXED ST=MEMORY DEFAULT 0
705
+ b Int NULL AT=FIXED ST=MEMORY DEFAULT 0
706
+ c Int NULL AT=FIXED ST=MEMORY DEFAULT 0
707
+ d Int NULL AT=FIXED ST=MEMORY DEFAULT 0
708
+ e Int NULL AT=FIXED ST=MEMORY DEFAULT 0
709
+ f Int NULL AT=FIXED ST=MEMORY DEFAULT 0
710
+ b1 Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
711
+ c1 Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
712
+ a1 Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
713
+ b2 Int NOT NULL AT=FIXED ST=MEMORY
714
+ c2 Int NOT NULL AT=FIXED ST=MEMORY
715
+ a2 Int NOT NULL AT=FIXED ST=MEMORY
716
+ b3 Int NOT NULL AT=FIXED ST=MEMORY
717
+ c3 Int NOT NULL AT=FIXED ST=MEMORY
718
+ a3 Int NOT NULL AT=FIXED ST=MEMORY
719
+ -- Indexes --
720
+ PRIMARY KEY(b1, c1, a1) - UniqueHashIndex
721
+ uk2$unique(b2, c2, a2) - UniqueHashIndex
722
+ ok3def(c3, b3, a3, d, e, f) - OrderedIndex
723
+ -- ForeignKeys --
724
+ XX/XX/fk11 PRIMARY KEY (c1, b1, a1) REFERENCES test.t1/PRIMARY KEY () on update noaction on delete noaction
725
+ XX/XX/fk21 uk2$unique (c2, b2, a2) REFERENCES test.t1/PRIMARY KEY () on update noaction on delete noaction
726
+ XX/XX/fk31 ok3def (c3, b3, a3) REFERENCES test.t1/PRIMARY KEY () on update noaction on delete noaction
727
+ XX/XX/fk12 PRIMARY KEY (c1, b1, a1) REFERENCES test.t1/uk2$unique () on update noaction on delete noaction
728
+ XX/XX/fk22 uk2$unique (c2, b2, a2) REFERENCES test.t1/uk2$unique () on update noaction on delete noaction
729
+ XX/XX/fk32 ok3def (c3, b3, a3) REFERENCES test.t1/uk2$unique () on update noaction on delete noaction
730
+
731
+ NDBT_ProgramExit: 0 - OK
732
+
733
+ insert into t1 (a, b, c) values (11, 12, 13);
734
+ insert into t2 (a, b, c) values (11, 12, 13);
735
+ insert into t2 (a,b,c) values (101, 102, 103);
736
+ ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (Unknown error code)
737
+ # show meta
738
+ show create table t2;
739
+ Table Create Table
740
+ t2 CREATE TABLE `t2` (
741
+ `a` int(11) DEFAULT '0',
742
+ `b` int(11) DEFAULT '0',
743
+ `c` int(11) DEFAULT '0',
744
+ `d` int(11) DEFAULT '0',
745
+ `e` int(11) DEFAULT '0',
746
+ `f` int(11) DEFAULT '0',
747
+ `b1` int(11) GENERATED ALWAYS AS (`b`) STORED NOT NULL,
748
+ `c1` int(11) GENERATED ALWAYS AS (`c`) STORED NOT NULL,
749
+ `a1` int(11) GENERATED ALWAYS AS (`a`) STORED NOT NULL,
750
+ `b2` int(11) GENERATED ALWAYS AS (`b`) STORED NOT NULL,
751
+ `c2` int(11) GENERATED ALWAYS AS (`c`) STORED NOT NULL,
752
+ `a2` int(11) GENERATED ALWAYS AS (`a`) STORED NOT NULL,
753
+ `b3` int(11) GENERATED ALWAYS AS (`b`) STORED NOT NULL,
754
+ `c3` int(11) GENERATED ALWAYS AS (`c`) STORED NOT NULL,
755
+ `a3` int(11) GENERATED ALWAYS AS (`a`) STORED NOT NULL,
756
+ PRIMARY KEY (`a1`,`b1`,`c1`) USING HASH,
757
+ UNIQUE KEY `uk2` (`a2`,`b2`,`c2`) USING HASH,
758
+ KEY `ok3def` (`c3`,`b3`,`a3`,`d`,`e`,`f`),
759
+ CONSTRAINT `fk11` FOREIGN KEY (`c1`,`b1`,`a1`) REFERENCES `t1` (`c1`,`b1`,`a1`) ON DELETE NO ACTION ON UPDATE NO ACTION,
760
+ CONSTRAINT `fk12` FOREIGN KEY (`c1`,`b1`,`a1`) REFERENCES `t1` (`c2`,`b2`,`a2`) ON DELETE NO ACTION ON UPDATE NO ACTION,
761
+ CONSTRAINT `fk21` FOREIGN KEY (`c2`,`b2`,`a2`) REFERENCES `t1` (`c1`,`b1`,`a1`) ON DELETE NO ACTION ON UPDATE NO ACTION,
762
+ CONSTRAINT `fk22` FOREIGN KEY (`c2`,`b2`,`a2`) REFERENCES `t1` (`c2`,`b2`,`a2`) ON DELETE NO ACTION ON UPDATE NO ACTION,
763
+ CONSTRAINT `fk31` FOREIGN KEY (`c3`,`b3`,`a3`) REFERENCES `t1` (`c1`,`b1`,`a1`) ON DELETE NO ACTION ON UPDATE NO ACTION,
764
+ CONSTRAINT `fk32` FOREIGN KEY (`c3`,`b3`,`a3`) REFERENCES `t1` (`c2`,`b2`,`a2`) ON DELETE NO ACTION ON UPDATE NO ACTION
765
+ ) ENGINE=ndbcluster DEFAULT CHARSET=latin1
766
+
767
+ ndb_show_tables completed.....
768
+
769
+ select type,name from ndb_show_tables_results
770
+ where type in ('''ForeignKey''','''FKParentTrigger''','''FKChildTrigger''');
771
+ type name
772
+ 'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
773
+ 'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
774
+ 'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
775
+ 'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
776
+ 'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
777
+ 'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
778
+ 'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
779
+ 'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
780
+ 'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
781
+ 'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
782
+ 'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
783
+ 'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
784
+ 'ForeignKey' 'XX/XX/fk11'
785
+ 'ForeignKey' 'XX/XX/fk12'
786
+ 'ForeignKey' 'XX/XX/fk21'
787
+ 'ForeignKey' 'XX/XX/fk22'
788
+ 'ForeignKey' 'XX/XX/fk31'
789
+ 'ForeignKey' 'XX/XX/fk32'
790
+ # show counts
791
+ select count(*) from t1;
792
+ count(*)
793
+ 1
794
+ select count(*) from t2;
795
+ count(*)
796
+ 1
797
+ # run backup
798
+ # drop tables
799
+ drop table t2, t1;
800
+ # restore meta (disable indexes)
801
+ # restore data (disable indexes)
802
+ # rebuild indexes
803
+ # show meta
804
+ show create table t2;
805
+ Table Create Table
806
+ t2 CREATE TABLE `t2` (
807
+ `a` int(11) DEFAULT '0',
808
+ `b` int(11) DEFAULT '0',
809
+ `c` int(11) DEFAULT '0',
810
+ `d` int(11) DEFAULT '0',
811
+ `e` int(11) DEFAULT '0',
812
+ `f` int(11) DEFAULT '0',
813
+ `b1` int(11) GENERATED ALWAYS AS (`b`) STORED NOT NULL,
814
+ `c1` int(11) GENERATED ALWAYS AS (`c`) STORED NOT NULL,
815
+ `a1` int(11) GENERATED ALWAYS AS (`a`) STORED NOT NULL,
816
+ `b2` int(11) GENERATED ALWAYS AS (`b`) STORED NOT NULL,
817
+ `c2` int(11) GENERATED ALWAYS AS (`c`) STORED NOT NULL,
818
+ `a2` int(11) GENERATED ALWAYS AS (`a`) STORED NOT NULL,
819
+ `b3` int(11) GENERATED ALWAYS AS (`b`) STORED NOT NULL,
820
+ `c3` int(11) GENERATED ALWAYS AS (`c`) STORED NOT NULL,
821
+ `a3` int(11) GENERATED ALWAYS AS (`a`) STORED NOT NULL,
822
+ PRIMARY KEY (`a1`,`b1`,`c1`) USING HASH,
823
+ UNIQUE KEY `uk2` (`a2`,`b2`,`c2`) USING HASH,
824
+ KEY `ok3def` (`c3`,`b3`,`a3`,`d`,`e`,`f`),
825
+ CONSTRAINT `fk11` FOREIGN KEY (`c1`,`b1`,`a1`) REFERENCES `t1` (`c1`,`b1`,`a1`) ON DELETE NO ACTION ON UPDATE NO ACTION,
826
+ CONSTRAINT `fk12` FOREIGN KEY (`c1`,`b1`,`a1`) REFERENCES `t1` (`c2`,`b2`,`a2`) ON DELETE NO ACTION ON UPDATE NO ACTION,
827
+ CONSTRAINT `fk21` FOREIGN KEY (`c2`,`b2`,`a2`) REFERENCES `t1` (`c1`,`b1`,`a1`) ON DELETE NO ACTION ON UPDATE NO ACTION,
828
+ CONSTRAINT `fk22` FOREIGN KEY (`c2`,`b2`,`a2`) REFERENCES `t1` (`c2`,`b2`,`a2`) ON DELETE NO ACTION ON UPDATE NO ACTION,
829
+ CONSTRAINT `fk31` FOREIGN KEY (`c3`,`b3`,`a3`) REFERENCES `t1` (`c1`,`b1`,`a1`) ON DELETE NO ACTION ON UPDATE NO ACTION,
830
+ CONSTRAINT `fk32` FOREIGN KEY (`c3`,`b3`,`a3`) REFERENCES `t1` (`c2`,`b2`,`a2`) ON DELETE NO ACTION ON UPDATE NO ACTION
831
+ ) ENGINE=ndbcluster DEFAULT CHARSET=latin1
832
+
833
+ ndb_show_tables completed.....
834
+
835
+ select type,name from ndb_show_tables_results
836
+ where type in ('''ForeignKey''','''FKParentTrigger''','''FKChildTrigger''');
837
+ type name
838
+ 'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
839
+ 'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
840
+ 'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
841
+ 'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
842
+ 'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
843
+ 'FKChildTrigger' 'NDB$FK_XX_CHILD_XX'
844
+ 'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
845
+ 'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
846
+ 'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
847
+ 'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
848
+ 'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
849
+ 'FKParentTrigger' 'NDB$FK_XX_PARENT_XX'
850
+ 'ForeignKey' 'XX/XX/fk11'
851
+ 'ForeignKey' 'XX/XX/fk12'
852
+ 'ForeignKey' 'XX/XX/fk21'
853
+ 'ForeignKey' 'XX/XX/fk22'
854
+ 'ForeignKey' 'XX/XX/fk31'
855
+ 'ForeignKey' 'XX/XX/fk32'
856
+ # show counts
857
+ select count(*) from t1;
858
+ count(*)
859
+ 1
860
+ select count(*) from t2;
861
+ count(*)
862
+ 1
863
+ select * from t1;
864
+ b1 c1 a1 b2 c2 a2 a b c
865
+ 12 13 11 12 13 11 11 12 13
866
+ select * from t2;
867
+ a b c d e f b1 c1 a1 b2 c2 a2 b3 c3 a3
868
+ 11 12 13 0 0 0 12 13 11 12 13 11 12 13 11
869
+ drop table t2,t1;
0 commit comments