Commit 43cb98b4 authored by Nikita Malyavin's avatar Nikita Malyavin Committed by Sergei Golubchik

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
parent c382de72
...@@ -1662,8 +1662,8 @@ ALTER TABLE t1 ADD INDEX i1(b); ...@@ -1662,8 +1662,8 @@ ALTER TABLE t1 ADD INDEX i1(b);
affected rows: 2 affected rows: 2
info: Records: 2 Duplicates: 0 Warnings: 0 info: Records: 2 Duplicates: 0 Warnings: 0
ALTER TABLE t1 ADD INDEX i2(b), ALGORITHM= DEFAULT; ALTER TABLE t1 ADD INDEX i2(b), ALGORITHM= DEFAULT;
affected rows: 2 affected rows: 0
info: Records: 2 Duplicates: 0 Warnings: 1 info: Records: 0 Duplicates: 0 Warnings: 1
Warnings: Warnings:
Note 1831 Duplicate index `i2`. This is deprecated and will be disallowed in a future release 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; ALTER TABLE t1 ADD INDEX i3(b), ALGORITHM= COPY;
......
...@@ -14,7 +14,7 @@ a b c ...@@ -14,7 +14,7 @@ a b c
1 2 4 1 2 4
2 3 5 2 3 5
alter online table mysql57_virtual comment "I am now a MariaDB table", algorithm=nocopy; 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"; alter table mysql57_virtual comment "I am now a MariaDB table";
SHOW CREATE TABLE mysql57_virtual; SHOW CREATE TABLE mysql57_virtual;
Table Create Table Table Create Table
......
...@@ -13,7 +13,7 @@ insert into mysql57_virtual (a) values (1),(2); ...@@ -13,7 +13,7 @@ insert into mysql57_virtual (a) values (1),(2);
select * from mysql57_virtual; select * from mysql57_virtual;
# We can't do online changes, as the MariaDB storage is incompatible with MySQL # 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 online table mysql57_virtual comment "I am now a MariaDB table", algorithm=nocopy;
alter table mysql57_virtual comment "I am now a MariaDB table"; alter table mysql57_virtual comment "I am now a MariaDB table";
......
--- alter_algorithm.result --- alter_algorithm.result
+++ alter_algorithm.reject +++ alter_algorithm.reject
@@ -7,43 +7,43 @@ @@ -7,40 +7,40 @@
INSERT INTO t1(f1, f2, f3) VALUES(1, 1, 1); INSERT INTO t1(f1, f2, f3) VALUES(1, 1, 1);
SELECT @@alter_algorithm; SELECT @@alter_algorithm;
@@alter_algorithm @@alter_algorithm
...@@ -56,13 +56,8 @@ ...@@ -56,13 +56,8 @@
+affected rows: 0 +affected rows: 0
+info: Records: 0 Duplicates: 0 Warnings: 0 +info: Records: 0 Duplicates: 0 Warnings: 0
ALTER TABLE t1 FORCE, ALGORITHM=DEFAULT; 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 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 @@ @@ -56,22 +56,22 @@
FOREIGN KEY fidx(f1) REFERENCES t1(f1))ENGINE=INNODB; FOREIGN KEY fidx(f1) REFERENCES t1(f1))ENGINE=INNODB;
INSERT INTO t1(f1, f2, f4, f5) VALUES(1, 2, 3, 4); INSERT INTO t1(f1, f2, f4, f5) VALUES(1, 2, 3, 4);
......
--- alter_algorithm.result --- alter_algorithm.result
+++ alter_algorithm.reject +++ alter_algorithm.reject
@@ -7,43 +7,35 @@ @@ -7,40 +7,32 @@
INSERT INTO t1(f1, f2, f3) VALUES(1, 1, 1); INSERT INTO t1(f1, f2, f3) VALUES(1, 1, 1);
SELECT @@alter_algorithm; SELECT @@alter_algorithm;
@@alter_algorithm @@alter_algorithm
...@@ -48,13 +48,8 @@ ...@@ -48,13 +48,8 @@
-info: Records: 1 Duplicates: 0 Warnings: 0 -info: Records: 1 Duplicates: 0 Warnings: 0
+Got one of the listed errors +Got one of the listed errors
ALTER TABLE t1 FORCE, ALGORITHM=DEFAULT; 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 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 @@ @@ -56,22 +48,17 @@
FOREIGN KEY fidx(f1) REFERENCES t1(f1))ENGINE=INNODB; FOREIGN KEY fidx(f1) REFERENCES t1(f1))ENGINE=INNODB;
INSERT INTO t1(f1, f2, f4, f5) VALUES(1, 2, 3, 4); INSERT INTO t1(f1, f2, f4, f5) VALUES(1, 2, 3, 4);
......
--- alter_algorithm.result --- alter_algorithm.result
+++ alter_algorithm.reject +++ alter_algorithm.reject
@@ -7,43 +7,35 @@ @@ -7,40 +7,32 @@
INSERT INTO t1(f1, f2, f3) VALUES(1, 1, 1); INSERT INTO t1(f1, f2, f3) VALUES(1, 1, 1);
SELECT @@alter_algorithm; SELECT @@alter_algorithm;
@@alter_algorithm @@alter_algorithm
...@@ -48,13 +48,8 @@ ...@@ -48,13 +48,8 @@
-info: Records: 1 Duplicates: 0 Warnings: 0 -info: Records: 1 Duplicates: 0 Warnings: 0
+Got one of the listed errors +Got one of the listed errors
ALTER TABLE t1 FORCE, ALGORITHM=DEFAULT; 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 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 @@ @@ -56,22 +48,22 @@
FOREIGN KEY fidx(f1) REFERENCES t1(f1))ENGINE=INNODB; FOREIGN KEY fidx(f1) REFERENCES t1(f1))ENGINE=INNODB;
INSERT INTO t1(f1, f2, f4, f5) VALUES(1, 2, 3, 4); INSERT INTO t1(f1, f2, f4, f5) VALUES(1, 2, 3, 4);
......
...@@ -42,8 +42,8 @@ ALTER TABLE t1 ENGINE=INNODB; ...@@ -42,8 +42,8 @@ ALTER TABLE t1 ENGINE=INNODB;
affected rows: 1 affected rows: 1
info: Records: 1 Duplicates: 0 Warnings: 0 info: Records: 1 Duplicates: 0 Warnings: 0
ALTER TABLE t1 FORCE, ALGORITHM=DEFAULT; ALTER TABLE t1 FORCE, ALGORITHM=DEFAULT;
affected rows: 1 affected rows: 0
info: Records: 1 Duplicates: 0 Warnings: 0 info: Records: 0 Duplicates: 0 Warnings: 0
DROP TABLE t1; DROP TABLE t1;
affected rows: 0 affected rows: 0
CREATE TABLE t1(f1 INT PRIMARY KEY, f2 INT NOT NULL, CREATE TABLE t1(f1 INT PRIMARY KEY, f2 INT NOT NULL,
......
...@@ -7,7 +7,7 @@ ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: Not implemented for sys ...@@ -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 system versioning, lock=shared;
alter table t add column b int, change column a a int without system versioning, lock=none; 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; 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; alter table t drop system versioning, algorithm=inplace;
create or replace table t ( create or replace table t (
a int, b int, a int, b int,
...@@ -127,7 +127,7 @@ alter table t drop column b, algorithm=instant; ...@@ -127,7 +127,7 @@ alter table t drop column b, algorithm=instant;
alter table t add index idx(a), lock=none; alter table t add index idx(a), lock=none;
alter table t drop column s, drop column e; alter table t drop column s, drop column e;
alter table t drop 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
# #
# MDEV-17697 Broken versioning info after instant drop column # MDEV-17697 Broken versioning info after instant drop column
# #
......
...@@ -260,6 +260,14 @@ Alter_info::algorithm(const THD *thd) const ...@@ -260,6 +260,14 @@ Alter_info::algorithm(const THD *thd) const
return requested_algorithm; 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() Alter_table_ctx::Alter_table_ctx()
: db(null_clex_str), table_name(null_clex_str), alias(null_clex_str), : db(null_clex_str), table_name(null_clex_str), alias(null_clex_str),
......
...@@ -233,6 +233,7 @@ class Alter_info ...@@ -233,6 +233,7 @@ class Alter_info
algorithm then return alter_algorithm variable value. algorithm then return alter_algorithm variable value.
*/ */
enum_alter_table_algorithm algorithm(const THD *thd) const; enum_alter_table_algorithm algorithm(const THD *thd) const;
bool algorithm_is_nocopy(const THD *thd) const;
private: private:
Alter_info &operator=(const Alter_info &rhs); // not implemented Alter_info &operator=(const Alter_info &rhs); // not implemented
......
...@@ -10676,31 +10676,25 @@ do_continue:; ...@@ -10676,31 +10676,25 @@ do_continue:;
#endif #endif
/* /*
Use copy algorithm if: We can use only copy algorithm if one of the following is true:
- old_alter_table system variable is set without in-place requested using - In-place is impossible for given operation.
the ALGORITHM clause.
- Or if in-place is impossible for given operation.
- Changes to partitioning which were not handled by fast_alter_part_table() - Changes to partitioning which were not handled by fast_alter_part_table()
needs to be handled using table copying algorithm unless the engine needs to be handled using table copying algorithm unless the engine
supports auto-partitioning as such engines can do some changes supports auto-partitioning as such engines can do some changes
using in-place API. using in-place API.
*/ */
if ((thd->variables.alter_algorithm == Alter_info::ALTER_TABLE_ALGORITHM_COPY && if (is_inplace_alter_impossible(table, create_info, alter_info)
alter_info->algorithm(thd) !=
Alter_info::ALTER_TABLE_ALGORITHM_INPLACE)
|| is_inplace_alter_impossible(table, create_info, alter_info)
|| IF_PARTITIONING((partition_changed && || 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) == if (alter_info->algorithm_is_nocopy(thd))
Alter_info::ALTER_TABLE_ALGORITHM_INPLACE)
{ {
my_error(ER_ALTER_OPERATION_NOT_SUPPORTED, MYF(0), my_error(ER_ALTER_OPERATION_NOT_SUPPORTED, MYF(0),
"ALGORITHM=INPLACE", "ALGORITHM=COPY"); "ALGORITHM=INPLACE", "ALGORITHM=COPY");
DBUG_RETURN(true); 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);
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment