diff --git a/sql/handler.h b/sql/handler.h index b00643d0ace..4c013733833 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -307,7 +307,11 @@ enum chf_create_flags { #define HA_PERSISTENT_TABLE (1ULL << 48) -/* If storage engine uses another engine as a base */ +/* + If storage engine uses another engine as a base + This flag is also needed if the table tries to open the .frm file + as part of drop table. +*/ #define HA_REUSES_FILE_NAMES (1ULL << 49) /* diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 0824672df4a..91051df29b7 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -10900,12 +10900,11 @@ do_continue:; The above is mainly true for the sequence and the partition engine. */ engine_changed= ((new_table->file->ht != table->file->ht) && - (((!(new_table->file->ha_table_flags() & HA_FILE_BASED) || - !(table->file->ha_table_flags() & HA_FILE_BASED))) || - (!(table->file->ha_table_flags() & HA_REUSES_FILE_NAMES) && - !(new_table->file->ha_table_flags() & - HA_REUSES_FILE_NAMES)))); - + ((!(new_table->file->ha_table_flags() & HA_FILE_BASED) || + !(table->file->ha_table_flags() & HA_FILE_BASED))) && + !(table->file->ha_table_flags() & HA_REUSES_FILE_NAMES) && + !(new_table->file->ha_table_flags() & + HA_REUSES_FILE_NAMES)); /* Close the intermediate table that will be the new table, but do not delete it! Even though MERGE tables do not have their children diff --git a/storage/connect/ha_connect.cc b/storage/connect/ha_connect.cc index 2206cfc271d..b1449af9636 100644 --- a/storage/connect/ha_connect.cc +++ b/storage/connect/ha_connect.cc @@ -1169,7 +1169,8 @@ ulonglong ha_connect::table_flags() const // HA_NULL_IN_KEY | not implemented yet // HA_FAST_KEY_READ | causes error when sorting (???) HA_NO_TRANSACTIONS | HA_DUPLICATE_KEY_NOT_IN_ORDER | - HA_NO_BLOBS | HA_MUST_USE_TABLE_CONDITION_PUSHDOWN; + HA_NO_BLOBS | HA_MUST_USE_TABLE_CONDITION_PUSHDOWN | + HA_REUSES_FILE_NAMES; ha_connect *hp= (ha_connect*)this; PTOS pos= hp->GetTableOptionStruct(); @@ -5244,6 +5245,14 @@ int ha_connect::delete_or_rename_table(const char *name, const char *to) thd->push_internal_handler(&error_handler); bool got_error= open_table_def(thd, share); thd->pop_internal_handler(); + if (!got_error && share->db_type() != connect_hton) + { + /* The .frm file is not for the connect engine. Something is wrong! */ + got_error= 1; + rc= HA_ERR_INTERNAL_ERROR; + my_error(HA_ERR_INTERNAL_ERROR, MYF(0), + "TABLE_SHARE is not for the CONNECT engine"); + } if (!got_error) { // Now we can work if ((pos= share->option_struct)) { diff --git a/storage/connect/mysql-test/connect/r/alter_engine.result b/storage/connect/mysql-test/connect/r/alter_engine.result new file mode 100644 index 00000000000..530574d276d --- /dev/null +++ b/storage/connect/mysql-test/connect/r/alter_engine.result @@ -0,0 +1,11 @@ +# +# MDEV-24422 Server crashes in GetTypeID / ha_connect::GetRealType upon +# altering table engine +# +CREATE TABLE t1 (f INT) ENGINE=CONNECT; +Warnings: +Warning 1105 No table_type. Will be set to DOS +Warning 1105 No file name. Table will use t1.dos +ALTER TABLE t1 ENGINE InnoDB; +ALTER TABLE t1 ENGINE CONNECT; +DROP TABLE t1; diff --git a/storage/connect/mysql-test/connect/t/alter_engine.test b/storage/connect/mysql-test/connect/t/alter_engine.test new file mode 100644 index 00000000000..789a0955d3b --- /dev/null +++ b/storage/connect/mysql-test/connect/t/alter_engine.test @@ -0,0 +1,11 @@ +--source include/have_innodb.inc + +--echo # +--echo # MDEV-24422 Server crashes in GetTypeID / ha_connect::GetRealType upon +--echo # altering table engine +--echo # + +CREATE TABLE t1 (f INT) ENGINE=CONNECT; +ALTER TABLE t1 ENGINE InnoDB; +ALTER TABLE t1 ENGINE CONNECT; +DROP TABLE t1;