diff --git a/mysql-test/suite/innodb/r/fk_col_alter.result b/mysql-test/suite/innodb/r/fk_col_alter.result index edd90e05ecd..a6888943523 100644 --- a/mysql-test/suite/innodb/r/fk_col_alter.result +++ b/mysql-test/suite/innodb/r/fk_col_alter.result @@ -75,3 +75,10 @@ ALTER TABLE t1 MODIFY msg VARCHAR(200) CHARSET utf8mb4, ALGORITHM=COPY; ALTER TABLE t2 ADD CONSTRAINT FOREIGN KEY (msg) REFERENCES t1(msg), aLGORITHM=INPLACE; SET FOREIGN_KEY_CHECKS=1; DROP TABLE t2, t1; +# +# MDEV-31869 Server aborts when table does drop column +# +CREATE TABLE t (a VARCHAR(40), b INT, C INT) ENGINE=InnoDB; +ALTER TABLE t MODIFY a VARCHAR(50), DROP b; +DROP TABLE t; +# End of 10.4 tests diff --git a/mysql-test/suite/innodb/t/fk_col_alter.test b/mysql-test/suite/innodb/t/fk_col_alter.test index d8b9afc92ad..169210e12c1 100644 --- a/mysql-test/suite/innodb/t/fk_col_alter.test +++ b/mysql-test/suite/innodb/t/fk_col_alter.test @@ -104,3 +104,11 @@ ALTER TABLE t2 ADD CONSTRAINT FOREIGN KEY (msg) REFERENCES t1(msg), aLGORITHM=IN SET FOREIGN_KEY_CHECKS=1; DROP TABLE t2, t1; + +--echo # +--echo # MDEV-31869 Server aborts when table does drop column +--echo # +CREATE TABLE t (a VARCHAR(40), b INT, C INT) ENGINE=InnoDB; +ALTER TABLE t MODIFY a VARCHAR(50), DROP b; +DROP TABLE t; +--echo # End of 10.4 tests diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 9ec025d6141..a5ccb1957f3 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -8330,14 +8330,21 @@ err_exit: index columns are modified */ if (ha_alter_info->handler_flags & ALTER_COLUMN_TYPE_CHANGE_BY_ENGINE) { - List_iterator it( - ha_alter_info->alter_info->create_list); - for (uint i = 0; i < table->s->fields; i++) { - Field* field = table->field[i]; - Create_field *f= it++; - if (!f->field || field->is_equal(*f)) - continue; + for (uint i= 0; i < table->s->fields; i++) { + Field* field = table->field[i]; + for (const Create_field& new_field : + ha_alter_info->alter_info->create_list) { + if (new_field.field == field) { + if (!field->is_equal(new_field)) { + goto field_changed; + } + break; + } + } + + continue; +field_changed: const char* col_name= field->field_name.str; dict_col_t *col= dict_table_get_nth_col( m_prebuilt->table, i);