--source include/have_innodb.inc --source include/have_partition.inc --source include/have_sequence.inc SET @default_stats_persistent= @@global.innodb_stats_persistent; SET GLOBAL innodb_stats_persistent= 0; CREATE TABLE t1(f1 CHAR(200), f2 INT NOT NULL)engine=InnoDB; INSERT INTO t1 SELECT repeat('a', 200), seq FROM seq_1_to_2; # Buffer fits in the memory ALTER TABLE t1 ALGORITHM=COPY, FORCE; # Insert more entries INSERT INTO t1 SELECT repeat('b', 200), seq FROM seq_3_to_65536; # Alter should use temporary file for sorting ALTER TABLE t1 ALGORITHM=COPY, ADD INDEX(f2); # Error while buffering the insert operation --error ER_DUP_ENTRY ALTER TABLE t1 ALGORITHM=COPY, ADD PRIMARY KEY(f1(2)); INSERT INTO t1 VALUES(repeat('a', 200), 1); # Error while applying the bulk insert operation --error ER_DUP_ENTRY ALTER TABLE t1 ALGORITHM=COPY, ADD UNIQUE KEY(f2); # Ignore shouldn't go through bulk operation ALTER IGNORE TABLE t1 MODIFY f1 CHAR(200) NOT NULL; CREATE TABLE t2(f1 INT NOT NULL, FOREIGN KEY(f1) REFERENCES t1(f2))ENGINE=InnoDB; INSERT INTO t2 VALUES(1); # Bulk operation shouldn't happen because of foreign key constraints ALTER TABLE t2 ALGORITHM=COPY, FORCE; DROP TABLE t2, t1; CREATE TABLE t1 (f1 INT, f2 INT) ENGINE=InnoDB PARTITION BY HASH(f1) PARTITIONS 2; INSERT INTO t1 VALUES(1, 1); INSERT INTO t1 SELECT seq, seq * 2 FROM seq_1_to_2; # Buffer fits in the memory ALTER TABLE t1 ALGORITHM=COPY, FORCE; # Insert more entries INSERT INTO t1 SELECT seq, seq * 2 FROM seq_3_to_65536; # Alter should use temporary file for sorting ALTER TABLE t1 ALGORITHM=COPY, ADD INDEX(f2); DROP TABLE t1; --echo # --echo # MDEV-34756 Validation of new foreign key skipped --echo # if innodb_alter_copy_bulk=ON --echo # CREATE TABLE t1(f1 INT NOT NULL PRIMARY KEY, f2 INT NOT NULL)ENGINE=InnoDB; CREATE TABLE t2(f1 INT NOT NULL PRIMARY KEY, f2 INT NOT NULL)ENGINE=InnoDB; --enable_info ALTER TABLE t2 ADD CONSTRAINT FOREIGN KEY(f1) REFERENCES t1(f1); --disable_info INSERT INTO t1 VALUES (1, 1); INSERT INTO t2 VALUES (1, 2); --replace_regex /#sql-alter-[0-9a-f-]*/#sql-alter/ --error ER_NO_REFERENCED_ROW_2 ALTER TABLE t2 ADD CONSTRAINT FOREIGN KEY(f2) REFERENCES t1(f1); INSERT INTO t1 VALUES(3, 1); --enable_info SET STATEMENT foreign_key_checks=0 FOR ALTER TABLE t2 ALGORITHM=COPY, ADD CONSTRAINT FOREIGN KEY(f2) REFERENCES t1(f1); ALTER TABLE t1 ALGORITHM=COPY, FORCE; ALTER TABLE t2 ALGORITHM=COPY, FORCE; --disable_info DROP TABLE t2, t1; --echo # --echo # MDEV-35237 Bulk insert fails to apply buffered --echo # operation during copy alter --echo # CREATE TABLE t1 (f1 int NOT NULL, f2 tinyint(1) NOT NULL, f3 varchar(80) NOT NULL, PRIMARY KEY(f1), KEY(f2), KEY(f3))ENGINE=InnoDB; INSERT INTO t1 VALUES(1,1,''),(2,0,''), (4,1,'e'); CREATE TABLE t2 (f1 int NOT NULL, f2 int NOT NULL,KEY(f1))ENGINE=InnoDB; INSERT INTO t2 VALUES (1,0),(1,0); CREATE TABLE t engine=innodb SELECT t2.f2 FROM t2 JOIN t1 ON t1.f1 = t2.f1 AND t1.f3 = '' AND t1.f2=1 ; SELECT COUNT(*) FROM t; DROP TABLE t1, t2, t; SET GLOBAL innodb_stats_persistent=@default_stats_persistent;