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.
This commit is contained in:
Monty 2023-10-14 15:46:29 +03:00
parent ec277a70e8
commit 1c554459b3
4 changed files with 48 additions and 1 deletions

View File

@ -3093,3 +3093,31 @@ drop table t1;
# #
# End of 10.5 tests # 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
#

View File

@ -2382,3 +2382,21 @@ drop table t1;
--echo # --echo #
--echo # End of 10.5 tests --echo # End of 10.5 tests
--echo # --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 #

View File

@ -199,6 +199,7 @@ public:
Alter_info() : Alter_info() :
flags(0), partition_flags(0), flags(0), partition_flags(0),
keys_onoff(LEAVE_AS_IS), keys_onoff(LEAVE_AS_IS),
original_table(0),
num_parts(0), num_parts(0),
requested_algorithm(ALTER_TABLE_ALGORITHM_NONE), requested_algorithm(ALTER_TABLE_ALGORITHM_NONE),
requested_lock(ALTER_TABLE_LOCK_DEFAULT) requested_lock(ALTER_TABLE_LOCK_DEFAULT)

View File

@ -2898,7 +2898,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
key_iterator.rewind(); key_iterator.rewind();
while ((key=key_iterator++)) 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 */ /* The key was replaced by another key */
if (alter_info->add_stat_drop_index(thd, &key->name)) if (alter_info->add_stat_drop_index(thd, &key->name))