summaryrefslogtreecommitdiff
path: root/mysql-test/main
diff options
context:
space:
mode:
authorAleksey Midenkov <midenok@gmail.com>2021-11-03 12:31:47 +0300
committerAleksey Midenkov <midenok@gmail.com>2021-11-03 12:31:47 +0300
commitb3bdc1c1425948295156b35b1dbed3f18deb4865 (patch)
treeefd0b498a78ea9e8a56aabf3f3820ff220815822 /mysql-test/main
parenta8ded395578ccab9c256b9beee7e62d4ada08522 (diff)
downloadmariadb-git-b3bdc1c1425948295156b35b1dbed3f18deb4865.tar.gz
MDEV-25803 Inplace ALTER breaks MyISAM/Aria table when order of keys is changed
mysql_prepare_create_table() does my_qsort(sort_keys) on key info. This sorting is indeterministic: a table is created with one order and inplace alter may overwrite frm with another order. Since inplace alter does nothing about key info for MyISAM/Aria storage engines this results in discrepancy between frm and storage engine key definitions. The fix avoids the sorting of keys when no new keys added by ALTER (and this is ok for MyISAM/Aria since it cannot add new keys inplace). There is a case when implicit primary key may be changed when removing NOT NULL from the part of unique key. In that case we update modified_primary_key which is then used to not skip key sorting. According to is_candidate_key() there is no other cases when primary key may be changed implicitly. Notes: mi_keydef_write()/mi_keyseg_write() are used only in mi_create(). They should be used in ha_inplace_alter_table() as well. Aria corruption detection is unimplemented: maria_check_definition() is never used! MySQL 8.0 has this bug as well as of 8.0.26.
Diffstat (limited to 'mysql-test/main')
-rw-r--r--mysql-test/main/alter_table.result16
-rw-r--r--mysql-test/main/alter_table.test41
2 files changed, 57 insertions, 0 deletions
diff --git a/mysql-test/main/alter_table.result b/mysql-test/main/alter_table.result
index a43d9845947..4c64578b974 100644
--- a/mysql-test/main/alter_table.result
+++ b/mysql-test/main/alter_table.result
@@ -3373,5 +3373,21 @@ 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;
+#
# End of 10.5 tests
#
diff --git a/mysql-test/main/alter_table.test b/mysql-test/main/alter_table.test
index e65a4edf13e..85725820677 100644
--- a/mysql-test/main/alter_table.test
+++ b/mysql-test/main/alter_table.test
@@ -2568,5 +2568,46 @@ 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 # End of 10.5 tests
--echo #