-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDEV-33087 ALTER TABLE...ALGORITHM=COPY should build indexes more eff…
…iciently - During copy algorithm, InnoDB should use bulk insert operation for row by row insert operation. By doing this, copy algorithm can effectively build indexes. This optimization is disabled for temporary table, versioning table and table which has foreign key relation. Introduced the variable innodb_alter_copy_bulk to allow the bulk insert operation for copy alter operation inside InnoDB. This is enabled by default ha_innobase::extra(): HA_EXTRA_END_ALTER_COPY mode tries to apply the buffered bulk insert operation, updates the non-persistent table stats. row_merge_bulk_t::write_to_index(): Update stat_n_rows after applying the bulk insert operation row_ins_clust_index_entry_low(): In case of copy algorithm, switch to bulk insert operation. copy_data_error_ignore(): Handles the error while copying the data from source to target file.
- Loading branch information
1 parent
3a06964
commit 55fb366
Showing
18 changed files
with
318 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- bulk_copy_alter.result | ||
+++ bulk_copy_alter,non_bulk_alter_copy.result | ||
@@ -5,7 +5,7 @@ | ||
INSERT INTO t1 SELECT repeat('b', 200), seq FROM seq_3_to_65536; | ||
ALTER TABLE t1 ADD INDEX(f2); | ||
ALTER TABLE t1 ADD PRIMARY KEY(f1(2)); | ||
-ERROR 23000: Duplicate entry 'bb' for key 'PRIMARY' | ||
+ERROR 23000: Duplicate entry 'aa' for key 'PRIMARY' | ||
INSERT INTO t1 VALUES(repeat('a', 200), 1); | ||
ALTER TABLE t1 ADD UNIQUE KEY(f2); | ||
ERROR 23000: Duplicate entry '1' for key 'f2_2' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
SET @@alter_algorithm=COPY; | ||
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; | ||
ALTER TABLE t1 FORCE; | ||
INSERT INTO t1 SELECT repeat('b', 200), seq FROM seq_3_to_65536; | ||
ALTER TABLE t1 ADD INDEX(f2); | ||
ALTER TABLE t1 ADD PRIMARY KEY(f1(2)); | ||
ERROR 23000: Duplicate entry 'bb' for key 'PRIMARY' | ||
INSERT INTO t1 VALUES(repeat('a', 200), 1); | ||
ALTER TABLE t1 ADD UNIQUE KEY(f2); | ||
ERROR 23000: Duplicate entry '1' for key 'f2_2' | ||
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); | ||
ALTER TABLE t2 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; | ||
ALTER TABLE t1 FORCE; | ||
INSERT INTO t1 SELECT seq, seq * 2 FROM seq_3_to_65536; | ||
ALTER TABLE t1 ADD INDEX(f2); | ||
DROP TABLE t1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[ON] | ||
--innodb_alter_copy_bulk=ON | ||
|
||
[OFF] | ||
--innodb_alter_copy_bulk=OFF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--source include/have_innodb.inc | ||
--source include/have_partition.inc | ||
--source include/have_sequence.inc | ||
SET @@alter_algorithm=COPY; | ||
|
||
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 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 ADD INDEX(f2); | ||
|
||
# Error while buffering the insert operation | ||
--error ER_DUP_ENTRY | ||
ALTER TABLE t1 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 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 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 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 ADD INDEX(f2); | ||
DROP TABLE t1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.