@@ -714,6 +714,7 @@ t2 CREATE TABLE `t2` (
714
714
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`c2`) REFERENCES `t1` (`c1`)
715
715
) ENGINE=InnoDB DEFAULT CHARSET=latin1
716
716
ALTER TABLE t1 CHANGE COLUMN c1 C1 INT;
717
+ ALTER TABLE t2 CHANGE COLUMN c2 C2 INT;
717
718
SHOW CREATE TABLE t1;
718
719
Table Create Table
719
720
t1 CREATE TABLE `t1` (
@@ -723,24 +724,147 @@ t1 CREATE TABLE `t1` (
723
724
SHOW CREATE TABLE t2;
724
725
Table Create Table
725
726
t2 CREATE TABLE `t2` (
726
- `c2 ` int(11) NOT NULL,
727
- KEY `c2` (`c2 `),
727
+ `C2 ` int(11) DEFAULT NULL,
728
+ KEY `c2` (`C2 `),
728
729
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`c2`) REFERENCES `t1` (`c1`)
729
730
) ENGINE=InnoDB DEFAULT CHARSET=latin1
731
+ ALTER TABLE t1 CHANGE COLUMN C1 c5 INT;
732
+ ALTER TABLE t2 CHANGE COLUMN C2 c6 INT;
730
733
SHOW CREATE TABLE t1;
731
734
Table Create Table
732
735
t1 CREATE TABLE `t1` (
733
- `C1 ` int(11) NOT NULL DEFAULT '0',
734
- PRIMARY KEY (`C1 `)
736
+ `c5 ` int(11) NOT NULL DEFAULT '0',
737
+ PRIMARY KEY (`c5 `)
735
738
) ENGINE=InnoDB DEFAULT CHARSET=latin1
736
739
SHOW CREATE TABLE t2;
737
740
Table Create Table
738
741
t2 CREATE TABLE `t2` (
739
- `c2 ` int(11) NOT NULL,
740
- KEY `c2` (`c2 `),
741
- CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`c2 `) REFERENCES `t1` (`c1 `)
742
+ `c6 ` int(11) DEFAULT NULL,
743
+ KEY `c2` (`c6 `),
744
+ CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`c6 `) REFERENCES `t1` (`c5 `)
742
745
) ENGINE=InnoDB DEFAULT CHARSET=latin1
746
+ SELECT C.NAME FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS C INNER JOIN
747
+ INFORMATION_SCHEMA.INNODB_SYS_TABLES T ON C.TABLE_ID=T.TABLE_ID
748
+ WHERE T.NAME='test/t1';
749
+ NAME
750
+ c5
751
+ SELECT F.NAME FROM INFORMATION_SCHEMA.INNODB_SYS_FIELDS F INNER JOIN
752
+ INFORMATION_SCHEMA.INNODB_SYS_INDEXES I ON F.INDEX_ID=I.INDEX_ID INNER JOIN
753
+ INFORMATION_SCHEMA.INNODB_SYS_TABLES T ON I.TABLE_ID=T.TABLE_ID
754
+ WHERE T.NAME='test/t1' AND I.NAME='PRIMARY';
755
+ NAME
756
+ c5
757
+ SELECT C.REF_COL_NAME, C.FOR_COL_NAME FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS C INNER JOIN
758
+ INFORMATION_SCHEMA.INNODB_SYS_FOREIGN F ON C.ID=F.ID
759
+ WHERE F.FOR_NAME='test/t2';
760
+ REF_COL_NAME FOR_COL_NAME
761
+ c5 c6
743
762
DROP TABLE t2, t1;
763
+ # virtual columns case too
764
+ CREATE TABLE t1 (a INT, b INT GENERATED ALWAYS AS (a) VIRTUAL) ENGINE = InnoDB;
765
+ ALTER TABLE t1 CHANGE COLUMN a A INT;
766
+ SHOW CREATE TABLE t1;
767
+ Table Create Table
768
+ t1 CREATE TABLE `t1` (
769
+ `A` int(11) DEFAULT NULL,
770
+ `b` int(11) AS (a) VIRTUAL
771
+ ) ENGINE=InnoDB DEFAULT CHARSET=latin1
772
+ SELECT C.NAME FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS C INNER JOIN
773
+ INFORMATION_SCHEMA.INNODB_SYS_TABLES T ON C.TABLE_ID=T.TABLE_ID
774
+ WHERE T.NAME='test/t1';
775
+ NAME
776
+ a
777
+ DROP TABLE t1;
778
+ # different FOREIGN KEY cases
779
+ CREATE TABLE t1 (
780
+ a INT UNIQUE KEY,
781
+ b INT UNIQUE KEY,
782
+ c INT UNIQUE KEY,
783
+ d INT UNIQUE KEY
784
+ ) ENGINE=INNODB;
785
+ CREATE TABLE t2 (
786
+ aa INT,
787
+ bb INT,
788
+ cc INT,
789
+ dd INT
790
+ ) ENGINE=INNODB;
791
+ INSERT INTO t1 VALUES (1, 1, 1, 1);
792
+ INSERT INTO t2 VALUES (1, 1, 1, 1);
793
+ ALTER TABLE t1 CHANGE a A INT, ALGORITHM=INPLACE;
794
+ ALTER TABLE t1 CHANGE c C INT, ALGORITHM=INPLACE;
795
+ ALTER TABLE t2 CHANGE cc CC INT, ALGORITHM=INPLACE;
796
+ ALTER TABLE t2 CHANGE dd DD INT, ALGORITHM=INPLACE;
797
+ SET foreign_key_checks=0;
798
+ ALTER TABLE t2
799
+ ADD FOREIGN KEY(aa) REFERENCES t1(a),
800
+ ADD FOREIGN KEY(bb) REFERENCES t1(b),
801
+ ADD FOREIGN KEY(cc) REFERENCES t1(c),
802
+ ADD FOREIGN KEY(dd) REFERENCES t1(d),
803
+ ALGORITHM=INPLACE;
804
+ ALTER TABLE t1 CHANGE b B INT, ALGORITHM=INPLACE;
805
+ ALTER TABLE t2 CHANGE aa AA INT, ALGORITHM=INPLACE;
806
+ ALTER TABLE t1 CHANGE d D INT, ALGORITHM=INPLACE;
807
+ ALTER TABLE t2 CHANGE bb BB INT, ALGORITHM=INPLACE;
808
+ SHOW CREATE TABLE t1;
809
+ Table Create Table
810
+ t1 CREATE TABLE `t1` (
811
+ `A` int(11) DEFAULT NULL,
812
+ `B` int(11) DEFAULT NULL,
813
+ `C` int(11) DEFAULT NULL,
814
+ `D` int(11) DEFAULT NULL,
815
+ UNIQUE KEY `a` (`A`),
816
+ UNIQUE KEY `b` (`B`),
817
+ UNIQUE KEY `c` (`C`),
818
+ UNIQUE KEY `d` (`D`)
819
+ ) ENGINE=InnoDB DEFAULT CHARSET=latin1
820
+ SHOW CREATE TABLE t2;
821
+ Table Create Table
822
+ t2 CREATE TABLE `t2` (
823
+ `AA` int(11) DEFAULT NULL,
824
+ `BB` int(11) DEFAULT NULL,
825
+ `CC` int(11) DEFAULT NULL,
826
+ `DD` int(11) DEFAULT NULL,
827
+ KEY `aa` (`AA`),
828
+ KEY `bb` (`BB`),
829
+ KEY `CC` (`CC`),
830
+ KEY `DD` (`DD`),
831
+ CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`aa`) REFERENCES `t1` (`a`),
832
+ CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`bb`) REFERENCES `t1` (`b`),
833
+ CONSTRAINT `t2_ibfk_3` FOREIGN KEY (`cc`) REFERENCES `t1` (`c`),
834
+ CONSTRAINT `t2_ibfk_4` FOREIGN KEY (`dd`) REFERENCES `t1` (`d`)
835
+ ) ENGINE=InnoDB DEFAULT CHARSET=latin1
836
+ DELETE FROM t1 WHERE a=1;
837
+ ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`aa`) REFERENCES `t1` (`a`))
838
+ DELETE FROM t1 WHERE A=1;
839
+ ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`aa`) REFERENCES `t1` (`a`))
840
+ DELETE FROM t1 WHERE b=1;
841
+ ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`aa`) REFERENCES `t1` (`a`))
842
+ DELETE FROM t1 WHERE B=1;
843
+ ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`aa`) REFERENCES `t1` (`a`))
844
+ DELETE FROM t1 WHERE c=1;
845
+ ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`aa`) REFERENCES `t1` (`a`))
846
+ DELETE FROM t1 WHERE C=1;
847
+ ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`aa`) REFERENCES `t1` (`a`))
848
+ DELETE FROM t1 WHERE d=1;
849
+ ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`aa`) REFERENCES `t1` (`a`))
850
+ DELETE FROM t1 WHERE D=1;
851
+ ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`aa`) REFERENCES `t1` (`a`))
852
+ DROP TABLE t2, t1;
853
+ # virtual columns case too
854
+ CREATE TABLE t1 (a INT, b INT GENERATED ALWAYS AS (a) VIRTUAL) ENGINE = InnoDB;
855
+ ALTER TABLE t1 CHANGE COLUMN a A INT;
856
+ SHOW CREATE TABLE t1;
857
+ Table Create Table
858
+ t1 CREATE TABLE `t1` (
859
+ `A` int(11) DEFAULT NULL,
860
+ `b` int(11) AS (a) VIRTUAL
861
+ ) ENGINE=InnoDB DEFAULT CHARSET=latin1
862
+ SELECT C.NAME FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS C INNER JOIN
863
+ INFORMATION_SCHEMA.INNODB_SYS_TABLES T ON C.TABLE_ID=T.TABLE_ID
864
+ WHERE T.NAME='test/t1';
865
+ NAME
866
+ a
867
+ DROP TABLE t1;
744
868
#
745
869
# BUG 20029625 - HANDLE_FATAL_SIGNAL (SIG=11) IN
746
870
# DICT_MEM_TABLE_COL_RENAME_LOW
0 commit comments