From 1c554459b382479cca3045b4cc6b5d1e3a858664 Mon Sep 17 00:00:00 2001 From: Monty Date: Sat, 14 Oct 2023 15:46:29 +0300 Subject: [PATCH] MDEV-32449 Server crashes in Alter_info::add_stat_drop_index upon CREATE TABLE Fixed missing initialization of Alter_info() This could cause crashes in some create table like scenarios where some generated indexes where automatically dropped. I also added a test that we do not try to drop from index_stats for temporary tables. --- mysql-test/main/alter_table.result | 28 ++++++++++++++++++++++++++++ mysql-test/main/alter_table.test | 18 ++++++++++++++++++ sql/sql_alter.h | 1 + sql/sql_table.cc | 2 +- 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/alter_table.result b/mysql-test/main/alter_table.result index 21998597cad..084b757530a 100644 --- a/mysql-test/main/alter_table.result +++ b/mysql-test/main/alter_table.result @@ -3093,3 +3093,31 @@ drop table t1; # # End of 10.5 tests # +# +# MDEV-32449 Server crashes in Alter_info::add_stat_drop_index upon CREATE TABLE +# +CREATE TABLE t1 ( +`altcol1` blob DEFAULT '', +KEY `altcol1` (`altcol1`(2300)) +) ROW_FORMAT=PAGE, ENGINE=Aria; +ALTER TABLE t1 ADD FOREIGN KEY h (`altcol1`) REFERENCES t1 (`altcol1`) ON UPDATE SET DEFAULT, ALGORITHM=COPY; +Warnings: +Note 1071 Specified key was too long; max key length is 2300 bytes +create or replace table t2 like t1; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `altcol1` blob DEFAULT '', + KEY `altcol1` (`altcol1`(2300)), + KEY `h` (`altcol1`(2300)) +) ENGINE=Aria DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci PAGE_CHECKSUM=1 ROW_FORMAT=PAGE +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `altcol1` blob DEFAULT '', + KEY `altcol1` (`altcol1`(2300)) +) ENGINE=Aria DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci PAGE_CHECKSUM=1 ROW_FORMAT=PAGE +drop table t1,t2; +# +# End of 10.6 tests +# diff --git a/mysql-test/main/alter_table.test b/mysql-test/main/alter_table.test index 2867fc74f03..c8ad4c23e5c 100644 --- a/mysql-test/main/alter_table.test +++ b/mysql-test/main/alter_table.test @@ -2382,3 +2382,21 @@ drop table t1; --echo # --echo # End of 10.5 tests --echo # + +--echo # +--echo # MDEV-32449 Server crashes in Alter_info::add_stat_drop_index upon CREATE TABLE +--echo # + +CREATE TABLE t1 ( + `altcol1` blob DEFAULT '', + KEY `altcol1` (`altcol1`(2300)) +) ROW_FORMAT=PAGE, ENGINE=Aria; +ALTER TABLE t1 ADD FOREIGN KEY h (`altcol1`) REFERENCES t1 (`altcol1`) ON UPDATE SET DEFAULT, ALGORITHM=COPY; +create or replace table t2 like t1; +show create table t1; +show create table t2; +drop table t1,t2; + +--echo # +--echo # End of 10.6 tests +--echo # diff --git a/sql/sql_alter.h b/sql/sql_alter.h index 24203716cb2..4bec6801147 100644 --- a/sql/sql_alter.h +++ b/sql/sql_alter.h @@ -199,6 +199,7 @@ public: Alter_info() : flags(0), partition_flags(0), keys_onoff(LEAVE_AS_IS), + original_table(0), num_parts(0), requested_algorithm(ALTER_TABLE_ALGORITHM_NONE), requested_lock(ALTER_TABLE_LOCK_DEFAULT) diff --git a/sql/sql_table.cc b/sql/sql_table.cc index bac8b6c4243..1ae4d2c88f0 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2898,7 +2898,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, key_iterator.rewind(); while ((key=key_iterator++)) { - if (key->type == Key::IGNORE_KEY) + if (key->type == Key::IGNORE_KEY && !create_info->tmp_table()) { /* The key was replaced by another key */ if (alter_info->add_stat_drop_index(thd, &key->name))