summaryrefslogtreecommitdiff
path: root/sql/sql_alter.cc
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 /sql/sql_alter.cc
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 'sql/sql_alter.cc')
-rw-r--r--sql/sql_alter.cc4
1 files changed, 2 insertions, 2 deletions
diff --git a/sql/sql_alter.cc b/sql/sql_alter.cc
index 7901c9b5e32..8562643df97 100644
--- a/sql/sql_alter.cc
+++ b/sql/sql_alter.cc
@@ -259,7 +259,7 @@ Alter_table_ctx::Alter_table_ctx()
db(null_clex_str), table_name(null_clex_str), alias(null_clex_str),
new_db(null_clex_str), new_name(null_clex_str), new_alias(null_clex_str),
fk_error_if_delete_row(false), fk_error_id(NULL),
- fk_error_table(NULL)
+ fk_error_table(NULL), modified_primary_key(false)
#ifdef DBUG_ASSERT_EXISTS
, tmp_table(false)
#endif
@@ -279,7 +279,7 @@ Alter_table_ctx::Alter_table_ctx(THD *thd, TABLE_LIST *table_list,
tables_opened(tables_opened_arg),
new_db(*new_db_arg), new_name(*new_name_arg),
fk_error_if_delete_row(false), fk_error_id(NULL),
- fk_error_table(NULL)
+ fk_error_table(NULL), modified_primary_key(false)
#ifdef DBUG_ASSERT_EXISTS
, tmp_table(false)
#endif