From 8b19f521f10282b75b2a1009a7a8241ca341f6f9 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 24 May 2022 17:27:18 +0200 Subject: [PATCH] move alter_table combinations to a separate test file no need to run all alter tests three times with no changes whatsoever --- mysql-test/main/alter_table.result | 324 ------------------ mysql-test/main/alter_table.test | 285 --------------- ...ff => alter_table_combinations,aria.rdiff} | 8 +- ...ff => alter_table_combinations,heap.rdiff} | 28 +- ... => alter_table_combinations.combinations} | 1 + .../main/alter_table_combinations.result | 324 ++++++++++++++++++ mysql-test/main/alter_table_combinations.test | 263 ++++++++++++++ 7 files changed, 615 insertions(+), 618 deletions(-) rename mysql-test/main/{alter_table,aria.rdiff => alter_table_combinations,aria.rdiff} (75%) rename mysql-test/main/{alter_table,heap.rdiff => alter_table_combinations,heap.rdiff} (70%) rename mysql-test/main/{alter_table.combinations => alter_table_combinations.combinations} (78%) create mode 100644 mysql-test/main/alter_table_combinations.result create mode 100644 mysql-test/main/alter_table_combinations.test diff --git a/mysql-test/main/alter_table.result b/mysql-test/main/alter_table.result index 755de4336b9..a73fde559e5 100644 --- a/mysql-test/main/alter_table.result +++ b/mysql-test/main/alter_table.result @@ -1,5 +1,3 @@ -drop table if exists t1,t2; -drop database if exists mysqltest; set @save_max_allowed_packet=@@global.max_allowed_packet; create table t1 ( col1 int not null auto_increment primary key, @@ -2588,22 +2586,6 @@ set max_statement_time= 0; drop table t1; drop view v1; # -# MDEV-25803 Inplace ALTER breaks MyISAM/Aria tables when order of keys is changed -# -set @save_default_engine= @@default_storage_engine; -create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x)) engine myisam; -alter table t1 change x xx int, algorithm=inplace; -check table t1; -Table Op Msg_type Msg_text -test.t1 check status OK -create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x)); -alter table t1 change x xx int, algorithm=inplace; -check table t1; -Table Op Msg_type Msg_text -test.t1 check status OK -drop table t1; -set @@default_storage_engine= @save_default_engine; -# # End of 10.3 tests # # @@ -2650,296 +2632,6 @@ DROP TABLE t1; # End of 10.4 tests # # -# MDEV-16290 ALTER TABLE ... RENAME COLUMN syntax -# -SET @save_default_engine= @@DEFAULT_STORAGE_ENGINE; -CREATE TABLE t1(a INT, b VARCHAR(30), c FLOAT); -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` int(11) DEFAULT NULL, - `b` varchar(30) DEFAULT NULL, - `c` float DEFAULT NULL -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -INSERT INTO t1 VALUES(1,'abcd',1.234); -CREATE TABLE t2(a INT, b VARCHAR(30), c FLOAT) ENGINE=MyIsam; -SHOW CREATE TABLE t2; -Table Create Table -t2 CREATE TABLE `t2` ( - `a` int(11) DEFAULT NULL, - `b` varchar(30) DEFAULT NULL, - `c` float DEFAULT NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -INSERT INTO t2 VALUES(1,'abcd',1.234); -ALTER TABLE t1 RENAME COLUMN a TO a; -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` int(11) DEFAULT NULL, - `b` varchar(30) DEFAULT NULL, - `c` float DEFAULT NULL -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -ALTER TABLE t1 RENAME COLUMN a TO m; -ALTER TABLE t1 RENAME COLUMN a TO m; -ERROR 42S22: Unknown column 'a' in 't1' -ALTER TABLE t1 RENAME COLUMN IF EXISTS a TO m; -Warnings: -Note 1054 Unknown column 'a' in 't1' -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `m` int(11) DEFAULT NULL, - `b` varchar(30) DEFAULT NULL, - `c` float DEFAULT NULL -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -SELECT * FROM t1; -m b c -1 abcd 1.234 -ALTER TABLE t1 RENAME COLUMN m TO x, -RENAME COLUMN b TO y, -RENAME COLUMN c TO z; -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `x` int(11) DEFAULT NULL, - `y` varchar(30) DEFAULT NULL, - `z` float DEFAULT NULL -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -SELECT * FROM t1; -x y z -1 abcd 1.234 -ALTER TABLE t2 RENAME COLUMN a TO d, RENAME COLUMN b TO e, RENAME COLUMN c to f; -SHOW CREATE TABLE t2; -Table Create Table -t2 CREATE TABLE `t2` ( - `d` int(11) DEFAULT NULL, - `e` varchar(30) DEFAULT NULL, - `f` float DEFAULT NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -SELECT * FROM t2; -d e f -1 abcd 1.234 -ALTER TABLE t1 CHANGE COLUMN x a INT, RENAME COLUMN y TO b; -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` int(11) DEFAULT NULL, - `b` varchar(30) DEFAULT NULL, - `z` float DEFAULT NULL -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -ALTER TABLE t1 CHANGE COLUMN z c DOUBLE, RENAME COLUMN b to b; -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `a` int(11) DEFAULT NULL, - `b` varchar(30) DEFAULT NULL, - `c` double DEFAULT NULL -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -ALTER TABLE t1 CHANGE COLUMN a b int, RENAME COLUMN b TO c, CHANGE COLUMN c d FLOAT; -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `b` int(11) DEFAULT NULL, - `c` varchar(30) DEFAULT NULL, - `d` float DEFAULT NULL -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -ALTER TABLE t1 ADD COLUMN zz INT, RENAME COLUMN d TO f; -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `b` int(11) DEFAULT NULL, - `c` varchar(30) DEFAULT NULL, - `f` float DEFAULT NULL, - `zz` int(11) DEFAULT NULL -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -ALTER TABLE t1 DROP COLUMN zz, RENAME COLUMN c TO zz; -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `b` int(11) DEFAULT NULL, - `zz` varchar(30) DEFAULT NULL, - `f` float DEFAULT NULL -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -ALTER TABLE t1 RENAME COLUMN zz to c, DROP COLUMN f; -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `b` int(11) DEFAULT NULL, - `c` varchar(30) DEFAULT NULL -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -ALTER TABLE t1 ADD COLUMN d INT DEFAULT 5, RENAME COLUMN c TO b, DROP COLUMN b; -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `b` varchar(30) DEFAULT NULL, - `d` int(11) DEFAULT 5 -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -ALTER TABLE t1 RENAME COLUMN b TO d, RENAME COLUMN d TO b; -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `d` varchar(30) DEFAULT NULL, - `b` int(11) DEFAULT 5 -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -ALTER TABLE t1 ADD KEY(b); -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `d` varchar(30) DEFAULT NULL, - `b` int(11) DEFAULT 5, - KEY `b` (`b`) -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -ALTER TABLE t1 RENAME COLUMN b TO bb; -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `d` varchar(30) DEFAULT NULL, - `bb` int(11) DEFAULT 5, - KEY `b` (`bb`) -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -SELECT * FROM t1; -d bb -abcd 5 -CREATE TABLE t3(a int, b int, KEY(b)); -ALTER TABLE t3 ADD CONSTRAINT FOREIGN KEY(b) REFERENCES t1(bb); -SHOW CREATE TABLE t3; -Table Create Table -t3 CREATE TABLE `t3` ( - `a` int(11) DEFAULT NULL, - `b` int(11) DEFAULT NULL, - KEY `b` (`b`), - CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`bb`) -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -ALTER TABLE t1 RENAME COLUMN bb TO b; -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `d` varchar(30) DEFAULT NULL, - `b` int(11) DEFAULT 5, - KEY `b` (`b`) -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -ALTER TABLE t3 RENAME COLUMN b TO c; -SHOW CREATE TABLE t3; -Table Create Table -t3 CREATE TABLE `t3` ( - `a` int(11) DEFAULT NULL, - `c` int(11) DEFAULT NULL, - KEY `b` (`c`), - CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`c`) REFERENCES `t1` (`b`) -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -CREATE TABLE t4(a int); -ALTER TABLE t4 RENAME COLUMN a TO aa, ALGORITHM = INPLACE; -SHOW CREATE TABLE t4; -Table Create Table -t4 CREATE TABLE `t4` ( - `aa` int(11) DEFAULT NULL -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -ALTER TABLE t4 RENAME COLUMN aa TO a, ALGORITHM = COPY; -SHOW CREATE TABLE t4; -Table Create Table -t4 CREATE TABLE `t4` ( - `a` int(11) DEFAULT NULL -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -DROP TABLE t4; -CREATE VIEW v1 AS SELECT d,e,f FROM t2; -CREATE TRIGGER trg1 BEFORE UPDATE on t2 FOR EACH ROW SET NEW.d=OLD.d + 10; -CREATE PROCEDURE sp1() INSERT INTO t2(d) VALUES(10); -ALTER TABLE t2 RENAME COLUMN d TO g; -SHOW CREATE TABLE t2; -Table Create Table -t2 CREATE TABLE `t2` ( - `g` int(11) DEFAULT NULL, - `e` varchar(30) DEFAULT NULL, - `f` float DEFAULT NULL -) ENGINE=MyISAM DEFAULT CHARSET=latin1 -SHOW CREATE VIEW v1; -View Create View character_set_client collation_connection -v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `test`.`t2`.`d` AS `d`,`test`.`t2`.`e` AS `e`,`test`.`t2`.`f` AS `f` from `t2` koi8r koi8r_general_ci -Warnings: -Warning 1356 View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them -SELECT * FROM v1; -ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them -UPDATE t2 SET f = f + 10; -ERROR 42S22: Unknown column 'd' in 'OLD' -CALL sp1(); -ERROR 42S22: Unknown column 'd' in 'field list' -DROP TRIGGER trg1; -DROP PROCEDURE sp1; -CREATE TABLE t_gen(a INT, b DOUBLE GENERATED ALWAYS AS (SQRT(a))); -INSERT INTO t_gen(a) VALUES(4); -SELECT * FROM t_gen; -a b -4 2 -SHOW CREATE TABLE t_gen; -Table Create Table -t_gen CREATE TABLE `t_gen` ( - `a` int(11) DEFAULT NULL, - `b` double GENERATED ALWAYS AS (sqrt(`a`)) VIRTUAL -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -ALTER TABLE t_gen RENAME COLUMN a TO c, CHANGE COLUMN b b DOUBLE GENERATED ALWAYS AS (SQRT(c)); -SELECT * FROM t_gen; -c b -4 2 -SHOW CREATE TABLE t_gen; -Table Create Table -t_gen CREATE TABLE `t_gen` ( - `c` int(11) DEFAULT NULL, - `b` double GENERATED ALWAYS AS (sqrt(`c`)) VIRTUAL -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -ALTER TABLE t_gen CHANGE COLUMN c x INT; -show create table t_gen; -Table Create Table -t_gen CREATE TABLE `t_gen` ( - `x` int(11) DEFAULT NULL, - `b` double GENERATED ALWAYS AS (sqrt(`x`)) VIRTUAL -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -ALTER TABLE t_gen RENAME COLUMN x TO a; -DROP TABLE t_gen; -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `d` varchar(30) DEFAULT NULL, - `b` int(11) DEFAULT 5, - KEY `b` (`b`) -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -ALTER TABLE t1 RENAME COLUMN b z; -ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'z' at line 1 -ALTER TABLE t1 RENAME COLUMN FROM b TO z; -ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM b TO z' at line 1 -ALTER TABLE t1 RENAME COLUMN b TO 1; -ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '1' at line 1 -ALTER TABLE t1 RENAME COLUMN b TO e, RENAME COLUMN c TO e; -ERROR 42S22: Unknown column 'c' in 't1' -ALTER TABLE t1 ADD COLUMN z INT, RENAME COLUMN b TO z; -ERROR 42S21: Duplicate column name 'z' -ALTER TABLE t1 DROP COLUMN b, RENAME COLUMN b TO z; -ERROR 42S22: Unknown column 'b' in 't1' -ALTER TABLE t1 RENAME COLUMN b TO b, RENAME COLUMN b TO b; -ERROR 42S22: Unknown column 'b' in 't1' -ALTER TABLE t1 RENAME COLUMN b TO c3, DROP COLUMN c3; -ERROR 42000: Can't DROP COLUMN `c3`; check that it exists -ALTER TABLE t1 ADD COLUMN z INT, CHANGE COLUMN z y INT, DROP COLUMN y; -ERROR 42S22: Unknown column 'z' in 't1' -ALTER TABLE t1 ADD COLUMN z INT, RENAME COLUMN z TO y, DROP COLUMN y; -ERROR 42S22: Unknown column 'z' in 't1' -ALTER TABLE t1 RENAME COLUMN b TO `nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn`; -ERROR 42000: Incorrect column name 'nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn' -ALTER TABLE t1 CHANGE b `nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn` int; -ERROR 42000: Identifier name 'nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn' is too long -SHOW CREATE TABLE t1; -Table Create Table -t1 CREATE TABLE `t1` ( - `d` varchar(30) DEFAULT NULL, - `b` int(11) DEFAULT 5, - KEY `b` (`b`) -) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 -SELECT * FROM t1; -d b -abcd 5 -DROP VIEW v1; -DROP TABLE t3,t1,t2; -SET DEFAULT_STORAGE_ENGINE= @save_default_engine; -# # MDEV-7318 RENAME INDEX # # @@ -3389,22 +3081,6 @@ t1 CREATE TABLE `t1` ( ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; # -# MDEV-25803 Inplace ALTER breaks MyISAM/Aria tables when order of keys is changed -# -set @save_default_engine= @@default_storage_engine; -create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x)) engine myisam; -alter table t1 change x xx int, algorithm=inplace; -check table t1; -Table Op Msg_type Msg_text -test.t1 check status OK -create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x)); -alter table t1 change x xx int, algorithm=inplace; -check table t1; -Table Op Msg_type Msg_text -test.t1 check status OK -drop table t1; -set @@default_storage_engine= @save_default_engine; -# # MDEV-25555 Server crashes in tree_record_pos after INPLACE-recreating index on HEAP table # create table t1 (a int, key idx1(a), key idx2 using btree(a)) engine=memory; diff --git a/mysql-test/main/alter_table.test b/mysql-test/main/alter_table.test index 1bff20a7bd7..b339da5edb2 100644 --- a/mysql-test/main/alter_table.test +++ b/mysql-test/main/alter_table.test @@ -2,10 +2,6 @@ # # Test of alter table # ---disable_warnings -drop table if exists t1,t2; -drop database if exists mysqltest; ---enable_warnings set @save_max_allowed_packet=@@global.max_allowed_packet; create table t1 ( @@ -2099,47 +2095,6 @@ set max_statement_time= 0; drop table t1; drop view v1; ---echo # ---echo # MDEV-25803 Inplace ALTER breaks MyISAM/Aria tables when order of keys is changed ---echo # -set @save_default_engine= @@default_storage_engine; ---disable_query_log -if ($MTR_COMBINATION_INNODB) -{ - set default_storage_engine= innodb; -} -if ($MTR_COMBINATION_ARIA) -{ - set default_storage_engine= aria; -} ---enable_query_log - -if (!$MTR_COMBINATION_INNODB) -{ - --disable_query_log - --disable_result_log - # There is no inplace ADD INDEX for MyISAM/Aria: - create or replace table t1 (x int); - --error ER_ALTER_OPERATION_NOT_SUPPORTED - alter table t1 add unique (x), algorithm=inplace; - --error ER_ALTER_OPERATION_NOT_SUPPORTED - alter table t1 add primary key(x), algorithm=inplace; - --error ER_ALTER_OPERATION_NOT_SUPPORTED - alter table t1 add index(x), algorithm=inplace; - --enable_query_log - --enable_result_log -} - -create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x)) engine myisam; -alter table t1 change x xx int, algorithm=inplace; -check table t1; -create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x)); -alter table t1 change x xx int, algorithm=inplace; -check table t1; -# cleanup -drop table t1; -set @@default_storage_engine= @save_default_engine; - --echo # --echo # End of 10.3 tests --echo # @@ -2192,205 +2147,6 @@ DROP TABLE t1; --echo # End of 10.4 tests --echo # ---echo # ---echo # MDEV-16290 ALTER TABLE ... RENAME COLUMN syntax ---echo # -SET @save_default_engine= @@DEFAULT_STORAGE_ENGINE; ---disable_query_log -if ($MTR_COMBINATION_INNODB) -{ -SET DEFAULT_STORAGE_ENGINE= INNODB; -} -if ($MTR_COMBINATION_ARIA) -{ -SET DEFAULT_STORAGE_ENGINE= ARIA; -} -if ($MTR_COMBINATION_HEAP) -{ -SET DEFAULT_STORAGE_ENGINE= MEMORY; -} ---enable_query_log -let $default_engine= `select @@default_storage_engine`; - -CREATE TABLE t1(a INT, b VARCHAR(30), c FLOAT); ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t1; -INSERT INTO t1 VALUES(1,'abcd',1.234); -CREATE TABLE t2(a INT, b VARCHAR(30), c FLOAT) ENGINE=MyIsam; -SHOW CREATE TABLE t2; -INSERT INTO t2 VALUES(1,'abcd',1.234); - -# Rename one column -ALTER TABLE t1 RENAME COLUMN a TO a; ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t1; -ALTER TABLE t1 RENAME COLUMN a TO m; ---error ER_BAD_FIELD_ERROR -ALTER TABLE t1 RENAME COLUMN a TO m; -ALTER TABLE t1 RENAME COLUMN IF EXISTS a TO m; ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t1; -SELECT * FROM t1; - -# Rename multiple column -ALTER TABLE t1 RENAME COLUMN m TO x, - RENAME COLUMN b TO y, - RENAME COLUMN c TO z; ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t1; -SELECT * FROM t1; - -# Rename multiple columns with MyIsam Engine -ALTER TABLE t2 RENAME COLUMN a TO d, RENAME COLUMN b TO e, RENAME COLUMN c to f; -SHOW CREATE TABLE t2; -SELECT * FROM t2; - -# Mix different ALTER operations with RENAME COLUMN -ALTER TABLE t1 CHANGE COLUMN x a INT, RENAME COLUMN y TO b; ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t1; -ALTER TABLE t1 CHANGE COLUMN z c DOUBLE, RENAME COLUMN b to b; ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t1; -ALTER TABLE t1 CHANGE COLUMN a b int, RENAME COLUMN b TO c, CHANGE COLUMN c d FLOAT; ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t1; -ALTER TABLE t1 ADD COLUMN zz INT, RENAME COLUMN d TO f; ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t1; -ALTER TABLE t1 DROP COLUMN zz, RENAME COLUMN c TO zz; ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t1; -ALTER TABLE t1 RENAME COLUMN zz to c, DROP COLUMN f; ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t1; -ALTER TABLE t1 ADD COLUMN d INT DEFAULT 5, RENAME COLUMN c TO b, DROP COLUMN b; ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t1; - -#Cyclic Rename -ALTER TABLE t1 RENAME COLUMN b TO d, RENAME COLUMN d TO b; ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t1; - -# Rename with Indexes -ALTER TABLE t1 ADD KEY(b); ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t1; -ALTER TABLE t1 RENAME COLUMN b TO bb; ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t1; -SELECT * FROM t1; - -# Rename with Foreign keys. -CREATE TABLE t3(a int, b int, KEY(b)); -ALTER TABLE t3 ADD CONSTRAINT FOREIGN KEY(b) REFERENCES t1(bb); ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t3; -ALTER TABLE t1 RENAME COLUMN bb TO b; ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t1; -ALTER TABLE t3 RENAME COLUMN b TO c; ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t3; - -# Different Algorithm -CREATE TABLE t4(a int); -ALTER TABLE t4 RENAME COLUMN a TO aa, ALGORITHM = INPLACE; ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t4; -ALTER TABLE t4 RENAME COLUMN aa TO a, ALGORITHM = COPY; ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t4; -DROP TABLE t4; - -# View, Trigger and SP -CREATE VIEW v1 AS SELECT d,e,f FROM t2; -CREATE TRIGGER trg1 BEFORE UPDATE on t2 FOR EACH ROW SET NEW.d=OLD.d + 10; -CREATE PROCEDURE sp1() INSERT INTO t2(d) VALUES(10); -ALTER TABLE t2 RENAME COLUMN d TO g; ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t2; -SHOW CREATE VIEW v1; ---error ER_VIEW_INVALID -SELECT * FROM v1; ---error ER_BAD_FIELD_ERROR -UPDATE t2 SET f = f + 10; ---error ER_BAD_FIELD_ERROR -CALL sp1(); -DROP TRIGGER trg1; -DROP PROCEDURE sp1; - -# Generated Columns -if (!$MTR_COMBINATION_HEAP) -{ -CREATE TABLE t_gen(a INT, b DOUBLE GENERATED ALWAYS AS (SQRT(a))); -INSERT INTO t_gen(a) VALUES(4); -SELECT * FROM t_gen; ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t_gen; -ALTER TABLE t_gen RENAME COLUMN a TO c, CHANGE COLUMN b b DOUBLE GENERATED ALWAYS AS (SQRT(c)); -SELECT * FROM t_gen; ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t_gen; -#--error ER_DEPENDENT_BY_GENERATED_COLUMN -ALTER TABLE t_gen CHANGE COLUMN c x INT; ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -show create table t_gen; -#--error ER_DEPENDENT_BY_GENERATED_COLUMN -ALTER TABLE t_gen RENAME COLUMN x TO a; -DROP TABLE t_gen; -} - - -# -# Negative tests -# ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t1; - -# Invalid Syntax ---error ER_PARSE_ERROR -ALTER TABLE t1 RENAME COLUMN b z; ---error ER_PARSE_ERROR -ALTER TABLE t1 RENAME COLUMN FROM b TO z; ---error ER_PARSE_ERROR -ALTER TABLE t1 RENAME COLUMN b TO 1; - -# Duplicate column name ---error ER_BAD_FIELD_ERROR -ALTER TABLE t1 RENAME COLUMN b TO e, RENAME COLUMN c TO e; ---error ER_DUP_FIELDNAME -ALTER TABLE t1 ADD COLUMN z INT, RENAME COLUMN b TO z; - -# Multiple operation on same column ---error ER_BAD_FIELD_ERROR -ALTER TABLE t1 DROP COLUMN b, RENAME COLUMN b TO z; ---error ER_BAD_FIELD_ERROR -ALTER TABLE t1 RENAME COLUMN b TO b, RENAME COLUMN b TO b; ---error ER_CANT_DROP_FIELD_OR_KEY -ALTER TABLE t1 RENAME COLUMN b TO c3, DROP COLUMN c3; ---error ER_BAD_FIELD_ERROR -ALTER TABLE t1 ADD COLUMN z INT, CHANGE COLUMN z y INT, DROP COLUMN y; ---error ER_BAD_FIELD_ERROR -ALTER TABLE t1 ADD COLUMN z INT, RENAME COLUMN z TO y, DROP COLUMN y; - -# Invalid column name while renaming ---error ER_WRONG_COLUMN_NAME -ALTER TABLE t1 RENAME COLUMN b TO `nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn`; -# This error is different compared to ALTER TABLE ... CHANGE command ---error ER_TOO_LONG_IDENT -ALTER TABLE t1 CHANGE b `nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn` int; - ---replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" -SHOW CREATE TABLE t1; -SELECT * FROM t1; - -# Cleanup -DROP VIEW v1; -DROP TABLE t3,t1,t2; -SET DEFAULT_STORAGE_ENGINE= @save_default_engine; - --echo # --echo # MDEV-7318 RENAME INDEX --echo # @@ -2608,47 +2364,6 @@ alter table t1 rename column abc to ABC; show create table t1; drop table t1; ---echo # ---echo # MDEV-25803 Inplace ALTER breaks MyISAM/Aria tables when order of keys is changed ---echo # -set @save_default_engine= @@default_storage_engine; ---disable_query_log -if ($MTR_COMBINATION_INNODB) -{ - set default_storage_engine= innodb; -} -if ($MTR_COMBINATION_ARIA) -{ - set default_storage_engine= aria; -} ---enable_query_log - -if (!$MTR_COMBINATION_INNODB) -{ - --disable_query_log - --disable_result_log - # There is no inplace ADD INDEX for MyISAM/Aria: - create or replace table t1 (x int); - --error ER_ALTER_OPERATION_NOT_SUPPORTED - alter table t1 add unique (x), algorithm=inplace; - --error ER_ALTER_OPERATION_NOT_SUPPORTED - alter table t1 add primary key(x), algorithm=inplace; - --error ER_ALTER_OPERATION_NOT_SUPPORTED - alter table t1 add index(x), algorithm=inplace; - --enable_query_log - --enable_result_log -} - -create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x)) engine myisam; -alter table t1 change x xx int, algorithm=inplace; -check table t1; -create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x)); -alter table t1 change x xx int, algorithm=inplace; -check table t1; -# cleanup -drop table t1; -set @@default_storage_engine= @save_default_engine; - --echo # --echo # MDEV-25555 Server crashes in tree_record_pos after INPLACE-recreating index on HEAP table --echo # diff --git a/mysql-test/main/alter_table,aria.rdiff b/mysql-test/main/alter_table_combinations,aria.rdiff similarity index 75% rename from mysql-test/main/alter_table,aria.rdiff rename to mysql-test/main/alter_table_combinations,aria.rdiff index 40bbf95494c..c549f307d1f 100644 --- a/mysql-test/main/alter_table,aria.rdiff +++ b/mysql-test/main/alter_table_combinations,aria.rdiff @@ -1,6 +1,6 @@ ---- ./mysql-test/main/alter_table.result 2020-02-27 19:35:41.279992329 +0300 -+++ ./mysql-test/main/alter_table,aria.reject 2020-02-27 19:37:13.251994491 +0300 -@@ -2716,8 +2716,7 @@ +--- main/alter_table_combinations.result 2022-05-24 17:16:56.769146869 +0200 ++++ main/alter_table_combinations.reject 2022-05-24 17:25:20.847126357 +0200 +@@ -173,8 +173,7 @@ t3 CREATE TABLE `t3` ( `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL, @@ -10,7 +10,7 @@ ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 ALTER TABLE t1 RENAME COLUMN bb TO b; SHOW CREATE TABLE t1; -@@ -2733,8 +2732,7 @@ +@@ -190,8 +189,7 @@ t3 CREATE TABLE `t3` ( `a` int(11) DEFAULT NULL, `c` int(11) DEFAULT NULL, diff --git a/mysql-test/main/alter_table,heap.rdiff b/mysql-test/main/alter_table_combinations,heap.rdiff similarity index 70% rename from mysql-test/main/alter_table,heap.rdiff rename to mysql-test/main/alter_table_combinations,heap.rdiff index ad6fd194cc9..ed84bbe73c1 100644 --- a/mysql-test/main/alter_table,heap.rdiff +++ b/mysql-test/main/alter_table_combinations,heap.rdiff @@ -1,6 +1,15 @@ ---- ./mysql-test/main/alter_table.result 2020-02-27 19:35:41.279992329 +0300 -+++ ./mysql-test/main/alter_table,heap.reject 2020-02-27 19:39:44.175998039 +0300 -@@ -2716,8 +2716,7 @@ +--- main/alter_table_combinations.result 2022-05-24 17:16:56.769146869 +0200 ++++ main/alter_table_combinations.reject 2022-05-24 17:25:01.216127156 +0200 +@@ -11,7 +11,7 @@ + alter table t1 change x xx int, algorithm=inplace; + check table t1; + Table Op Msg_type Msg_text +-test.t1 check status OK ++test.t1 check note The storage engine for the table doesn't support check + drop table t1; + # + # End of 10.3 tests +@@ -173,8 +173,7 @@ t3 CREATE TABLE `t3` ( `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL, @@ -10,7 +19,7 @@ ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 ALTER TABLE t1 RENAME COLUMN bb TO b; SHOW CREATE TABLE t1; -@@ -2733,8 +2732,7 @@ +@@ -190,8 +189,7 @@ t3 CREATE TABLE `t3` ( `a` int(11) DEFAULT NULL, `c` int(11) DEFAULT NULL, @@ -20,7 +29,7 @@ ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 CREATE TABLE t4(a int); ALTER TABLE t4 RENAME COLUMN a TO aa, ALGORITHM = INPLACE; -@@ -2774,36 +2772,6 @@ +@@ -231,36 +229,6 @@ ERROR 42S22: Unknown column 'd' in 'field list' DROP TRIGGER trg1; DROP PROCEDURE sp1; @@ -57,3 +66,12 @@ SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( +@@ -316,7 +284,7 @@ + alter table t1 change x xx int, algorithm=inplace; + check table t1; + Table Op Msg_type Msg_text +-test.t1 check status OK ++test.t1 check note The storage engine for the table doesn't support check + drop table t1; + # + # End of 10.5 tests diff --git a/mysql-test/main/alter_table.combinations b/mysql-test/main/alter_table_combinations.combinations similarity index 78% rename from mysql-test/main/alter_table.combinations rename to mysql-test/main/alter_table_combinations.combinations index 824e0a3be04..01c0e4b31b2 100644 --- a/mysql-test/main/alter_table.combinations +++ b/mysql-test/main/alter_table_combinations.combinations @@ -1,4 +1,5 @@ [innodb] +innodb [aria] diff --git a/mysql-test/main/alter_table_combinations.result b/mysql-test/main/alter_table_combinations.result new file mode 100644 index 00000000000..459447f343e --- /dev/null +++ b/mysql-test/main/alter_table_combinations.result @@ -0,0 +1,324 @@ +set @save_default_engine= @@default_storage_engine; +# +# MDEV-25803 Inplace ALTER breaks MyISAM/Aria tables when order of keys is changed +# +create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x)) engine myisam; +alter table t1 change x xx int, algorithm=inplace; +check table t1; +Table Op Msg_type Msg_text +test.t1 check status OK +create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x)); +alter table t1 change x xx int, algorithm=inplace; +check table t1; +Table Op Msg_type Msg_text +test.t1 check status OK +drop table t1; +# +# End of 10.3 tests +# +# +# MDEV-16290 ALTER TABLE ... RENAME COLUMN syntax +# +CREATE TABLE t1(a INT, b VARCHAR(30), c FLOAT); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` varchar(30) DEFAULT NULL, + `c` float DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +INSERT INTO t1 VALUES(1,'abcd',1.234); +CREATE TABLE t2(a INT, b VARCHAR(30), c FLOAT) ENGINE=MyIsam; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` int(11) DEFAULT NULL, + `b` varchar(30) DEFAULT NULL, + `c` float DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +INSERT INTO t2 VALUES(1,'abcd',1.234); +ALTER TABLE t1 RENAME COLUMN a TO a; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` varchar(30) DEFAULT NULL, + `c` float DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +ALTER TABLE t1 RENAME COLUMN a TO m; +ALTER TABLE t1 RENAME COLUMN a TO m; +ERROR 42S22: Unknown column 'a' in 't1' +ALTER TABLE t1 RENAME COLUMN IF EXISTS a TO m; +Warnings: +Note 1054 Unknown column 'a' in 't1' +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `m` int(11) DEFAULT NULL, + `b` varchar(30) DEFAULT NULL, + `c` float DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +SELECT * FROM t1; +m b c +1 abcd 1.234 +ALTER TABLE t1 RENAME COLUMN m TO x, +RENAME COLUMN b TO y, +RENAME COLUMN c TO z; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `x` int(11) DEFAULT NULL, + `y` varchar(30) DEFAULT NULL, + `z` float DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +SELECT * FROM t1; +x y z +1 abcd 1.234 +ALTER TABLE t2 RENAME COLUMN a TO d, RENAME COLUMN b TO e, RENAME COLUMN c to f; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `d` int(11) DEFAULT NULL, + `e` varchar(30) DEFAULT NULL, + `f` float DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2; +d e f +1 abcd 1.234 +ALTER TABLE t1 CHANGE COLUMN x a INT, RENAME COLUMN y TO b; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` varchar(30) DEFAULT NULL, + `z` float DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +ALTER TABLE t1 CHANGE COLUMN z c DOUBLE, RENAME COLUMN b to b; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `b` varchar(30) DEFAULT NULL, + `c` double DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +ALTER TABLE t1 CHANGE COLUMN a b int, RENAME COLUMN b TO c, CHANGE COLUMN c d FLOAT; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` int(11) DEFAULT NULL, + `c` varchar(30) DEFAULT NULL, + `d` float DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +ALTER TABLE t1 ADD COLUMN zz INT, RENAME COLUMN d TO f; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` int(11) DEFAULT NULL, + `c` varchar(30) DEFAULT NULL, + `f` float DEFAULT NULL, + `zz` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +ALTER TABLE t1 DROP COLUMN zz, RENAME COLUMN c TO zz; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` int(11) DEFAULT NULL, + `zz` varchar(30) DEFAULT NULL, + `f` float DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +ALTER TABLE t1 RENAME COLUMN zz to c, DROP COLUMN f; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` int(11) DEFAULT NULL, + `c` varchar(30) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +ALTER TABLE t1 ADD COLUMN d INT DEFAULT 5, RENAME COLUMN c TO b, DROP COLUMN b; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` varchar(30) DEFAULT NULL, + `d` int(11) DEFAULT 5 +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +ALTER TABLE t1 RENAME COLUMN b TO d, RENAME COLUMN d TO b; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `d` varchar(30) DEFAULT NULL, + `b` int(11) DEFAULT 5 +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +ALTER TABLE t1 ADD KEY(b); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `d` varchar(30) DEFAULT NULL, + `b` int(11) DEFAULT 5, + KEY `b` (`b`) +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +ALTER TABLE t1 RENAME COLUMN b TO bb; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `d` varchar(30) DEFAULT NULL, + `bb` int(11) DEFAULT 5, + KEY `b` (`bb`) +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +SELECT * FROM t1; +d bb +abcd 5 +CREATE TABLE t3(a int, b int, KEY(b)); +ALTER TABLE t3 ADD CONSTRAINT FOREIGN KEY(b) REFERENCES t1(bb); +SHOW CREATE TABLE t3; +Table Create Table +t3 CREATE TABLE `t3` ( + `a` int(11) DEFAULT NULL, + `b` int(11) DEFAULT NULL, + KEY `b` (`b`), + CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`bb`) +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +ALTER TABLE t1 RENAME COLUMN bb TO b; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `d` varchar(30) DEFAULT NULL, + `b` int(11) DEFAULT 5, + KEY `b` (`b`) +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +ALTER TABLE t3 RENAME COLUMN b TO c; +SHOW CREATE TABLE t3; +Table Create Table +t3 CREATE TABLE `t3` ( + `a` int(11) DEFAULT NULL, + `c` int(11) DEFAULT NULL, + KEY `b` (`c`), + CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`c`) REFERENCES `t1` (`b`) +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +CREATE TABLE t4(a int); +ALTER TABLE t4 RENAME COLUMN a TO aa, ALGORITHM = INPLACE; +SHOW CREATE TABLE t4; +Table Create Table +t4 CREATE TABLE `t4` ( + `aa` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +ALTER TABLE t4 RENAME COLUMN aa TO a, ALGORITHM = COPY; +SHOW CREATE TABLE t4; +Table Create Table +t4 CREATE TABLE `t4` ( + `a` int(11) DEFAULT NULL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +DROP TABLE t4; +CREATE VIEW v1 AS SELECT d,e,f FROM t2; +CREATE TRIGGER trg1 BEFORE UPDATE on t2 FOR EACH ROW SET NEW.d=OLD.d + 10; +CREATE PROCEDURE sp1() INSERT INTO t2(d) VALUES(10); +ALTER TABLE t2 RENAME COLUMN d TO g; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `g` int(11) DEFAULT NULL, + `e` varchar(30) DEFAULT NULL, + `f` float DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SHOW CREATE VIEW v1; +View Create View character_set_client collation_connection +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `test`.`t2`.`d` AS `d`,`test`.`t2`.`e` AS `e`,`test`.`t2`.`f` AS `f` from `t2` latin1 latin1_swedish_ci +Warnings: +Warning 1356 View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them +SELECT * FROM v1; +ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them +UPDATE t2 SET f = f + 10; +ERROR 42S22: Unknown column 'd' in 'OLD' +CALL sp1(); +ERROR 42S22: Unknown column 'd' in 'field list' +DROP TRIGGER trg1; +DROP PROCEDURE sp1; +CREATE TABLE t_gen(a INT, b DOUBLE GENERATED ALWAYS AS (SQRT(a))); +INSERT INTO t_gen(a) VALUES(4); +SELECT * FROM t_gen; +a b +4 2 +SHOW CREATE TABLE t_gen; +Table Create Table +t_gen CREATE TABLE `t_gen` ( + `a` int(11) DEFAULT NULL, + `b` double GENERATED ALWAYS AS (sqrt(`a`)) VIRTUAL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +ALTER TABLE t_gen RENAME COLUMN a TO c, CHANGE COLUMN b b DOUBLE GENERATED ALWAYS AS (SQRT(c)); +SELECT * FROM t_gen; +c b +4 2 +SHOW CREATE TABLE t_gen; +Table Create Table +t_gen CREATE TABLE `t_gen` ( + `c` int(11) DEFAULT NULL, + `b` double GENERATED ALWAYS AS (sqrt(`c`)) VIRTUAL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +ALTER TABLE t_gen CHANGE COLUMN c x INT; +show create table t_gen; +Table Create Table +t_gen CREATE TABLE `t_gen` ( + `x` int(11) DEFAULT NULL, + `b` double GENERATED ALWAYS AS (sqrt(`x`)) VIRTUAL +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +ALTER TABLE t_gen RENAME COLUMN x TO a; +DROP TABLE t_gen; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `d` varchar(30) DEFAULT NULL, + `b` int(11) DEFAULT 5, + KEY `b` (`b`) +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +ALTER TABLE t1 RENAME COLUMN b z; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'z' at line 1 +ALTER TABLE t1 RENAME COLUMN FROM b TO z; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM b TO z' at line 1 +ALTER TABLE t1 RENAME COLUMN b TO 1; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '1' at line 1 +ALTER TABLE t1 RENAME COLUMN b TO e, RENAME COLUMN c TO e; +ERROR 42S22: Unknown column 'c' in 't1' +ALTER TABLE t1 ADD COLUMN z INT, RENAME COLUMN b TO z; +ERROR 42S21: Duplicate column name 'z' +ALTER TABLE t1 DROP COLUMN b, RENAME COLUMN b TO z; +ERROR 42S22: Unknown column 'b' in 't1' +ALTER TABLE t1 RENAME COLUMN b TO b, RENAME COLUMN b TO b; +ERROR 42S22: Unknown column 'b' in 't1' +ALTER TABLE t1 RENAME COLUMN b TO c3, DROP COLUMN c3; +ERROR 42000: Can't DROP COLUMN `c3`; check that it exists +ALTER TABLE t1 ADD COLUMN z INT, CHANGE COLUMN z y INT, DROP COLUMN y; +ERROR 42S22: Unknown column 'z' in 't1' +ALTER TABLE t1 ADD COLUMN z INT, RENAME COLUMN z TO y, DROP COLUMN y; +ERROR 42S22: Unknown column 'z' in 't1' +ALTER TABLE t1 RENAME COLUMN b TO `nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn`; +ERROR 42000: Incorrect column name 'nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn' +ALTER TABLE t1 CHANGE b `nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn` int; +ERROR 42000: Identifier name 'nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn' is too long +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `d` varchar(30) DEFAULT NULL, + `b` int(11) DEFAULT 5, + KEY `b` (`b`) +) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 +SELECT * FROM t1; +d b +abcd 5 +DROP VIEW v1; +DROP TABLE t3,t1,t2; +# +# MDEV-25803 Inplace ALTER breaks MyISAM/Aria tables when order of keys is changed +# +create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x)) engine myisam; +alter table t1 change x xx int, algorithm=inplace; +check table t1; +Table Op Msg_type Msg_text +test.t1 check status OK +create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x)); +alter table t1 change x xx int, algorithm=inplace; +check table t1; +Table Op Msg_type Msg_text +test.t1 check status OK +drop table t1; +# +# End of 10.5 tests +# +set @@default_storage_engine= @save_default_engine; diff --git a/mysql-test/main/alter_table_combinations.test b/mysql-test/main/alter_table_combinations.test new file mode 100644 index 00000000000..7c8d7f42096 --- /dev/null +++ b/mysql-test/main/alter_table_combinations.test @@ -0,0 +1,263 @@ +set @save_default_engine= @@default_storage_engine; +--disable_query_log +if ($MTR_COMBINATION_INNODB) +{ +set default_storage_engine= innodb; +} +if ($MTR_COMBINATION_ARIA) +{ +set default_storage_engine= aria; +} +if ($MTR_COMBINATION_HEAP) +{ +set default_storage_engine= memory; +} +--enable_query_log +let $default_engine= `select @@default_storage_engine`; + +--echo # +--echo # MDEV-25803 Inplace ALTER breaks MyISAM/Aria tables when order of keys is changed +--echo # + +if (!$MTR_COMBINATION_INNODB) +{ + --disable_query_log + --disable_result_log + # There is no inplace ADD INDEX for MyISAM/Aria: + create or replace table t1 (x int); + --error ER_ALTER_OPERATION_NOT_SUPPORTED + alter table t1 add unique (x), algorithm=inplace; + --error ER_ALTER_OPERATION_NOT_SUPPORTED + alter table t1 add primary key(x), algorithm=inplace; + --error ER_ALTER_OPERATION_NOT_SUPPORTED + alter table t1 add index(x), algorithm=inplace; + --enable_query_log + --enable_result_log +} + +create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x)) engine myisam; +alter table t1 change x xx int, algorithm=inplace; +check table t1; +create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x)); +alter table t1 change x xx int, algorithm=inplace; +check table t1; +drop table t1; + +--echo # +--echo # End of 10.3 tests +--echo # + +--echo # +--echo # MDEV-16290 ALTER TABLE ... RENAME COLUMN syntax +--echo # + +CREATE TABLE t1(a INT, b VARCHAR(30), c FLOAT); +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES(1,'abcd',1.234); +CREATE TABLE t2(a INT, b VARCHAR(30), c FLOAT) ENGINE=MyIsam; +SHOW CREATE TABLE t2; +INSERT INTO t2 VALUES(1,'abcd',1.234); + +# Rename one column +ALTER TABLE t1 RENAME COLUMN a TO a; +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t1; +ALTER TABLE t1 RENAME COLUMN a TO m; +--error ER_BAD_FIELD_ERROR +ALTER TABLE t1 RENAME COLUMN a TO m; +ALTER TABLE t1 RENAME COLUMN IF EXISTS a TO m; +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t1; +SELECT * FROM t1; + +# Rename multiple column +ALTER TABLE t1 RENAME COLUMN m TO x, + RENAME COLUMN b TO y, + RENAME COLUMN c TO z; +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t1; +SELECT * FROM t1; + +# Rename multiple columns with MyIsam Engine +ALTER TABLE t2 RENAME COLUMN a TO d, RENAME COLUMN b TO e, RENAME COLUMN c to f; +SHOW CREATE TABLE t2; +SELECT * FROM t2; + +# Mix different ALTER operations with RENAME COLUMN +ALTER TABLE t1 CHANGE COLUMN x a INT, RENAME COLUMN y TO b; +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t1; +ALTER TABLE t1 CHANGE COLUMN z c DOUBLE, RENAME COLUMN b to b; +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t1; +ALTER TABLE t1 CHANGE COLUMN a b int, RENAME COLUMN b TO c, CHANGE COLUMN c d FLOAT; +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t1; +ALTER TABLE t1 ADD COLUMN zz INT, RENAME COLUMN d TO f; +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t1; +ALTER TABLE t1 DROP COLUMN zz, RENAME COLUMN c TO zz; +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t1; +ALTER TABLE t1 RENAME COLUMN zz to c, DROP COLUMN f; +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t1; +ALTER TABLE t1 ADD COLUMN d INT DEFAULT 5, RENAME COLUMN c TO b, DROP COLUMN b; +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t1; + +#Cyclic Rename +ALTER TABLE t1 RENAME COLUMN b TO d, RENAME COLUMN d TO b; +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t1; + +# Rename with Indexes +ALTER TABLE t1 ADD KEY(b); +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t1; +ALTER TABLE t1 RENAME COLUMN b TO bb; +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t1; +SELECT * FROM t1; + +# Rename with Foreign keys. +CREATE TABLE t3(a int, b int, KEY(b)); +ALTER TABLE t3 ADD CONSTRAINT FOREIGN KEY(b) REFERENCES t1(bb); +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t3; +ALTER TABLE t1 RENAME COLUMN bb TO b; +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t1; +ALTER TABLE t3 RENAME COLUMN b TO c; +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t3; + +# Different Algorithm +CREATE TABLE t4(a int); +ALTER TABLE t4 RENAME COLUMN a TO aa, ALGORITHM = INPLACE; +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t4; +ALTER TABLE t4 RENAME COLUMN aa TO a, ALGORITHM = COPY; +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t4; +DROP TABLE t4; + +# View, Trigger and SP +CREATE VIEW v1 AS SELECT d,e,f FROM t2; +CREATE TRIGGER trg1 BEFORE UPDATE on t2 FOR EACH ROW SET NEW.d=OLD.d + 10; +CREATE PROCEDURE sp1() INSERT INTO t2(d) VALUES(10); +ALTER TABLE t2 RENAME COLUMN d TO g; +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t2; +SHOW CREATE VIEW v1; +--error ER_VIEW_INVALID +SELECT * FROM v1; +--error ER_BAD_FIELD_ERROR +UPDATE t2 SET f = f + 10; +--error ER_BAD_FIELD_ERROR +CALL sp1(); +DROP TRIGGER trg1; +DROP PROCEDURE sp1; + +# Generated Columns +if (!$MTR_COMBINATION_HEAP) +{ +CREATE TABLE t_gen(a INT, b DOUBLE GENERATED ALWAYS AS (SQRT(a))); +INSERT INTO t_gen(a) VALUES(4); +SELECT * FROM t_gen; +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t_gen; +ALTER TABLE t_gen RENAME COLUMN a TO c, CHANGE COLUMN b b DOUBLE GENERATED ALWAYS AS (SQRT(c)); +SELECT * FROM t_gen; +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t_gen; +#--error ER_DEPENDENT_BY_GENERATED_COLUMN +ALTER TABLE t_gen CHANGE COLUMN c x INT; +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +show create table t_gen; +#--error ER_DEPENDENT_BY_GENERATED_COLUMN +ALTER TABLE t_gen RENAME COLUMN x TO a; +DROP TABLE t_gen; +} + +# +# Negative tests +# +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t1; + +# Invalid Syntax +--error ER_PARSE_ERROR +ALTER TABLE t1 RENAME COLUMN b z; +--error ER_PARSE_ERROR +ALTER TABLE t1 RENAME COLUMN FROM b TO z; +--error ER_PARSE_ERROR +ALTER TABLE t1 RENAME COLUMN b TO 1; + +# Duplicate column name +--error ER_BAD_FIELD_ERROR +ALTER TABLE t1 RENAME COLUMN b TO e, RENAME COLUMN c TO e; +--error ER_DUP_FIELDNAME +ALTER TABLE t1 ADD COLUMN z INT, RENAME COLUMN b TO z; + +# Multiple operation on same column +--error ER_BAD_FIELD_ERROR +ALTER TABLE t1 DROP COLUMN b, RENAME COLUMN b TO z; +--error ER_BAD_FIELD_ERROR +ALTER TABLE t1 RENAME COLUMN b TO b, RENAME COLUMN b TO b; +--error ER_CANT_DROP_FIELD_OR_KEY +ALTER TABLE t1 RENAME COLUMN b TO c3, DROP COLUMN c3; +--error ER_BAD_FIELD_ERROR +ALTER TABLE t1 ADD COLUMN z INT, CHANGE COLUMN z y INT, DROP COLUMN y; +--error ER_BAD_FIELD_ERROR +ALTER TABLE t1 ADD COLUMN z INT, RENAME COLUMN z TO y, DROP COLUMN y; + +# Invalid column name while renaming +--error ER_WRONG_COLUMN_NAME +ALTER TABLE t1 RENAME COLUMN b TO `nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn`; +# This error is different compared to ALTER TABLE ... CHANGE command +--error ER_TOO_LONG_IDENT +ALTER TABLE t1 CHANGE b `nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn` int; + +--replace_result $default_engine DEFAULT_ENGINE " PAGE_CHECKSUM=1" "" +SHOW CREATE TABLE t1; +SELECT * FROM t1; + +# Cleanup +DROP VIEW v1; +DROP TABLE t3,t1,t2; + +--echo # +--echo # MDEV-25803 Inplace ALTER breaks MyISAM/Aria tables when order of keys is changed +--echo # + +if (!$MTR_COMBINATION_INNODB) +{ + --disable_query_log + --disable_result_log + # There is no inplace ADD INDEX for MyISAM/Aria: + create or replace table t1 (x int); + --error ER_ALTER_OPERATION_NOT_SUPPORTED + alter table t1 add unique (x), algorithm=inplace; + --error ER_ALTER_OPERATION_NOT_SUPPORTED + alter table t1 add primary key(x), algorithm=inplace; + --error ER_ALTER_OPERATION_NOT_SUPPORTED + alter table t1 add index(x), algorithm=inplace; + --enable_query_log + --enable_result_log +} + +create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x)) engine myisam; +alter table t1 change x xx int, algorithm=inplace; +check table t1; +create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x)); +alter table t1 change x xx int, algorithm=inplace; +check table t1; +drop table t1; + +--echo # +--echo # End of 10.5 tests +--echo # + +set @@default_storage_engine= @save_default_engine;