From 43cb98b42070dc209063792ac06e4e24484d45f3 Mon Sep 17 00:00:00 2001 From: Nikita Malyavin Date: Wed, 28 Jun 2023 14:37:47 +0300 Subject: [PATCH] fix main.mysql57_virtual, main.alter_table, innodb.alter_algorithm The correct (best) algorithm is now chosen for ALGORITHM=DEFAULT and alter_algorithm=DEFAULT See also MDEV-30906 --- mysql-test/main/alter_table.result | 4 ++-- mysql-test/main/mysql57_virtual.result | 2 +- mysql-test/main/mysql57_virtual.test | 2 +- .../innodb/r/alter_algorithm,INPLACE.rdiff | 9 ++------- .../innodb/r/alter_algorithm,INSTANT.rdiff | 9 ++------- .../innodb/r/alter_algorithm,NOCOPY.rdiff | 9 ++------- .../suite/innodb/r/alter_algorithm.result | 4 ++-- mysql-test/suite/versioning/r/online.result | 4 ++-- sql/sql_alter.cc | 8 ++++++++ sql/sql_alter.h | 1 + sql/sql_table.cc | 20 +++++++------------ 11 files changed, 30 insertions(+), 42 deletions(-) diff --git a/mysql-test/main/alter_table.result b/mysql-test/main/alter_table.result index 6ebd9add34e..6904f76ff88 100644 --- a/mysql-test/main/alter_table.result +++ b/mysql-test/main/alter_table.result @@ -1662,8 +1662,8 @@ ALTER TABLE t1 ADD INDEX i1(b); affected rows: 2 info: Records: 2 Duplicates: 0 Warnings: 0 ALTER TABLE t1 ADD INDEX i2(b), ALGORITHM= DEFAULT; -affected rows: 2 -info: Records: 2 Duplicates: 0 Warnings: 1 +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 1 Warnings: Note 1831 Duplicate index `i2`. This is deprecated and will be disallowed in a future release ALTER TABLE t1 ADD INDEX i3(b), ALGORITHM= COPY; diff --git a/mysql-test/main/mysql57_virtual.result b/mysql-test/main/mysql57_virtual.result index 68a7b7feb9d..2bf5ee400cc 100644 --- a/mysql-test/main/mysql57_virtual.result +++ b/mysql-test/main/mysql57_virtual.result @@ -14,7 +14,7 @@ a b c 1 2 4 2 3 5 alter online table mysql57_virtual comment "I am now a MariaDB table", algorithm=nocopy; -ERROR 0A000: LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED +ERROR 0A000: ALGORITHM=INPLACE is not supported for this operation. Try ALGORITHM=COPY alter table mysql57_virtual comment "I am now a MariaDB table"; SHOW CREATE TABLE mysql57_virtual; Table Create Table diff --git a/mysql-test/main/mysql57_virtual.test b/mysql-test/main/mysql57_virtual.test index 5dfab2bdfc6..987a8f1a3cf 100644 --- a/mysql-test/main/mysql57_virtual.test +++ b/mysql-test/main/mysql57_virtual.test @@ -13,7 +13,7 @@ insert into mysql57_virtual (a) values (1),(2); select * from mysql57_virtual; # We can't do online changes, as the MariaDB storage is incompatible with MySQL ---error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON +--error ER_ALTER_OPERATION_NOT_SUPPORTED alter online table mysql57_virtual comment "I am now a MariaDB table", algorithm=nocopy; alter table mysql57_virtual comment "I am now a MariaDB table"; diff --git a/mysql-test/suite/innodb/r/alter_algorithm,INPLACE.rdiff b/mysql-test/suite/innodb/r/alter_algorithm,INPLACE.rdiff index 79b3d8854fa..6c0b1badcf8 100644 --- a/mysql-test/suite/innodb/r/alter_algorithm,INPLACE.rdiff +++ b/mysql-test/suite/innodb/r/alter_algorithm,INPLACE.rdiff @@ -1,6 +1,6 @@ --- alter_algorithm.result +++ alter_algorithm.reject -@@ -7,43 +7,43 @@ +@@ -7,40 +7,40 @@ INSERT INTO t1(f1, f2, f3) VALUES(1, 1, 1); SELECT @@alter_algorithm; @@alter_algorithm @@ -56,13 +56,8 @@ +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 ALTER TABLE t1 FORCE, ALGORITHM=DEFAULT; --affected rows: 1 --info: Records: 1 Duplicates: 0 Warnings: 0 -+affected rows: 0 -+info: Records: 0 Duplicates: 0 Warnings: 0 - DROP TABLE t1; affected rows: 0 - CREATE TABLE t1(f1 INT PRIMARY KEY, f2 INT NOT NULL, + info: Records: 0 Duplicates: 0 Warnings: 0 @@ -56,22 +56,22 @@ FOREIGN KEY fidx(f1) REFERENCES t1(f1))ENGINE=INNODB; INSERT INTO t1(f1, f2, f4, f5) VALUES(1, 2, 3, 4); diff --git a/mysql-test/suite/innodb/r/alter_algorithm,INSTANT.rdiff b/mysql-test/suite/innodb/r/alter_algorithm,INSTANT.rdiff index fbcb5ca8704..6a09338dea2 100644 --- a/mysql-test/suite/innodb/r/alter_algorithm,INSTANT.rdiff +++ b/mysql-test/suite/innodb/r/alter_algorithm,INSTANT.rdiff @@ -1,6 +1,6 @@ --- alter_algorithm.result +++ alter_algorithm.reject -@@ -7,43 +7,35 @@ +@@ -7,40 +7,32 @@ INSERT INTO t1(f1, f2, f3) VALUES(1, 1, 1); SELECT @@alter_algorithm; @@alter_algorithm @@ -48,13 +48,8 @@ -info: Records: 1 Duplicates: 0 Warnings: 0 +Got one of the listed errors ALTER TABLE t1 FORCE, ALGORITHM=DEFAULT; --affected rows: 1 --info: Records: 1 Duplicates: 0 Warnings: 0 -+affected rows: 0 -+info: Records: 0 Duplicates: 0 Warnings: 0 - DROP TABLE t1; affected rows: 0 - CREATE TABLE t1(f1 INT PRIMARY KEY, f2 INT NOT NULL, + info: Records: 0 Duplicates: 0 Warnings: 0 @@ -56,22 +48,17 @@ FOREIGN KEY fidx(f1) REFERENCES t1(f1))ENGINE=INNODB; INSERT INTO t1(f1, f2, f4, f5) VALUES(1, 2, 3, 4); diff --git a/mysql-test/suite/innodb/r/alter_algorithm,NOCOPY.rdiff b/mysql-test/suite/innodb/r/alter_algorithm,NOCOPY.rdiff index 44e9f63a5f4..317958638f1 100644 --- a/mysql-test/suite/innodb/r/alter_algorithm,NOCOPY.rdiff +++ b/mysql-test/suite/innodb/r/alter_algorithm,NOCOPY.rdiff @@ -1,6 +1,6 @@ --- alter_algorithm.result +++ alter_algorithm.reject -@@ -7,43 +7,35 @@ +@@ -7,40 +7,32 @@ INSERT INTO t1(f1, f2, f3) VALUES(1, 1, 1); SELECT @@alter_algorithm; @@alter_algorithm @@ -48,13 +48,8 @@ -info: Records: 1 Duplicates: 0 Warnings: 0 +Got one of the listed errors ALTER TABLE t1 FORCE, ALGORITHM=DEFAULT; --affected rows: 1 --info: Records: 1 Duplicates: 0 Warnings: 0 -+affected rows: 0 -+info: Records: 0 Duplicates: 0 Warnings: 0 - DROP TABLE t1; affected rows: 0 - CREATE TABLE t1(f1 INT PRIMARY KEY, f2 INT NOT NULL, + info: Records: 0 Duplicates: 0 Warnings: 0 @@ -56,22 +48,22 @@ FOREIGN KEY fidx(f1) REFERENCES t1(f1))ENGINE=INNODB; INSERT INTO t1(f1, f2, f4, f5) VALUES(1, 2, 3, 4); diff --git a/mysql-test/suite/innodb/r/alter_algorithm.result b/mysql-test/suite/innodb/r/alter_algorithm.result index 717d31de6a0..8d85aeb1921 100644 --- a/mysql-test/suite/innodb/r/alter_algorithm.result +++ b/mysql-test/suite/innodb/r/alter_algorithm.result @@ -42,8 +42,8 @@ ALTER TABLE t1 ENGINE=INNODB; affected rows: 1 info: Records: 1 Duplicates: 0 Warnings: 0 ALTER TABLE t1 FORCE, ALGORITHM=DEFAULT; -affected rows: 1 -info: Records: 1 Duplicates: 0 Warnings: 0 +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 DROP TABLE t1; affected rows: 0 CREATE TABLE t1(f1 INT PRIMARY KEY, f2 INT NOT NULL, diff --git a/mysql-test/suite/versioning/r/online.result b/mysql-test/suite/versioning/r/online.result index 8a588b64940..b31957021f4 100644 --- a/mysql-test/suite/versioning/r/online.result +++ b/mysql-test/suite/versioning/r/online.result @@ -7,7 +7,7 @@ ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: Not implemented for sys alter table t add system versioning, lock=shared; alter table t add column b int, change column a a int without system versioning, lock=none; alter table t drop system versioning, lock=none; -ERROR 0A000: LOCK=NONE is not supported. Reason: Not implemented for system-versioned operations. Try LOCK=SHARED +ERROR 0A000: LOCK=NONE is not supported. Reason: DROP SYSTEM VERSIONING. Try LOCK=SHARED alter table t drop system versioning, algorithm=inplace; create or replace table t ( a int, b int, @@ -127,7 +127,7 @@ alter table t drop column b, algorithm=instant; alter table t add index idx(a), lock=none; alter table t drop column s, drop column e; alter table t drop system versioning, lock=none; -ERROR 0A000: LOCK=NONE is not supported. Reason: Not implemented for system-versioned operations. Try LOCK=SHARED +ERROR 0A000: LOCK=NONE is not supported. Reason: DROP SYSTEM VERSIONING. Try LOCK=SHARED # # MDEV-17697 Broken versioning info after instant drop column # diff --git a/sql/sql_alter.cc b/sql/sql_alter.cc index 45e2993e356..78a43945557 100644 --- a/sql/sql_alter.cc +++ b/sql/sql_alter.cc @@ -260,6 +260,14 @@ Alter_info::algorithm(const THD *thd) const return requested_algorithm; } +bool Alter_info::algorithm_is_nocopy(const THD *thd) const +{ + auto alg= algorithm(thd); + return alg == ALTER_TABLE_ALGORITHM_INPLACE + || alg == ALTER_TABLE_ALGORITHM_INSTANT + || alg == ALTER_TABLE_ALGORITHM_NOCOPY; +} + Alter_table_ctx::Alter_table_ctx() : db(null_clex_str), table_name(null_clex_str), alias(null_clex_str), diff --git a/sql/sql_alter.h b/sql/sql_alter.h index 2fece8bcc38..1220db18924 100644 --- a/sql/sql_alter.h +++ b/sql/sql_alter.h @@ -233,6 +233,7 @@ public: algorithm then return alter_algorithm variable value. */ enum_alter_table_algorithm algorithm(const THD *thd) const; + bool algorithm_is_nocopy(const THD *thd) const; private: Alter_info &operator=(const Alter_info &rhs); // not implemented diff --git a/sql/sql_table.cc b/sql/sql_table.cc index c8ca8c0efd0..77a401f8263 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -10676,31 +10676,25 @@ do_continue:; #endif /* - Use copy algorithm if: - - old_alter_table system variable is set without in-place requested using - the ALGORITHM clause. - - Or if in-place is impossible for given operation. + We can use only copy algorithm if one of the following is true: + - In-place is impossible for given operation. - Changes to partitioning which were not handled by fast_alter_part_table() needs to be handled using table copying algorithm unless the engine supports auto-partitioning as such engines can do some changes using in-place API. */ - if ((thd->variables.alter_algorithm == Alter_info::ALTER_TABLE_ALGORITHM_COPY && - alter_info->algorithm(thd) != - Alter_info::ALTER_TABLE_ALGORITHM_INPLACE) - || is_inplace_alter_impossible(table, create_info, alter_info) + if (is_inplace_alter_impossible(table, create_info, alter_info) || IF_PARTITIONING((partition_changed && - !(old_db_type->partition_flags() & HA_USE_AUTO_PARTITION)), 0)) + !(old_db_type->partition_flags() & HA_USE_AUTO_PARTITION)), 0)) { - if (alter_info->algorithm(thd) == - Alter_info::ALTER_TABLE_ALGORITHM_INPLACE) + if (alter_info->algorithm_is_nocopy(thd)) { my_error(ER_ALTER_OPERATION_NOT_SUPPORTED, MYF(0), "ALGORITHM=INPLACE", "ALGORITHM=COPY"); DBUG_RETURN(true); } - alter_info->set_requested_algorithm( - Alter_info::ALTER_TABLE_ALGORITHM_COPY); + + alter_info->set_requested_algorithm(Alter_info::ALTER_TABLE_ALGORITHM_COPY); } /*