Commit 1799caa3 authored by Monty's avatar Monty

MDEV-24422 Server crashes in ha_connect::GetRealType upon ALTER TABLE

The problem was that the CONNECT engine is trying to open the .frm file
during drop_table(), which the code did not take into account.
Fixed by adding the HA_REUSES_FILE_NAMES table flag to CONNECT.

Other things:
- Fixed a wrong test of HA_REUSE_FILE_NAMES of in mysql_alter_table()
  (Comment was correct, no the code)
- Added a test in the connect engine that if the .frm it tries to use in
  delete is not made for connect, it will generate an error instead of
  crash.
parent 322129df
...@@ -307,7 +307,11 @@ enum chf_create_flags { ...@@ -307,7 +307,11 @@ enum chf_create_flags {
#define HA_PERSISTENT_TABLE (1ULL << 48) #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) #define HA_REUSES_FILE_NAMES (1ULL << 49)
/* /*
......
...@@ -10900,12 +10900,11 @@ do_continue:; ...@@ -10900,12 +10900,11 @@ do_continue:;
The above is mainly true for the sequence and the partition engine. The above is mainly true for the sequence and the partition engine.
*/ */
engine_changed= ((new_table->file->ht != table->file->ht) && engine_changed= ((new_table->file->ht != table->file->ht) &&
(((!(new_table->file->ha_table_flags() & HA_FILE_BASED) || ((!(new_table->file->ha_table_flags() & HA_FILE_BASED) ||
!(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) && !(table->file->ha_table_flags() & HA_REUSES_FILE_NAMES) &&
!(new_table->file->ha_table_flags() & !(new_table->file->ha_table_flags() &
HA_REUSES_FILE_NAMES)))); HA_REUSES_FILE_NAMES));
/* /*
Close the intermediate table that will be the new table, but do Close the intermediate table that will be the new table, but do
not delete it! Even though MERGE tables do not have their children not delete it! Even though MERGE tables do not have their children
......
...@@ -1169,7 +1169,8 @@ ulonglong ha_connect::table_flags() const ...@@ -1169,7 +1169,8 @@ ulonglong ha_connect::table_flags() const
// HA_NULL_IN_KEY | not implemented yet // HA_NULL_IN_KEY | not implemented yet
// HA_FAST_KEY_READ | causes error when sorting (???) // HA_FAST_KEY_READ | causes error when sorting (???)
HA_NO_TRANSACTIONS | HA_DUPLICATE_KEY_NOT_IN_ORDER | 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; ha_connect *hp= (ha_connect*)this;
PTOS pos= hp->GetTableOptionStruct(); PTOS pos= hp->GetTableOptionStruct();
...@@ -5244,6 +5245,14 @@ int ha_connect::delete_or_rename_table(const char *name, const char *to) ...@@ -5244,6 +5245,14 @@ int ha_connect::delete_or_rename_table(const char *name, const char *to)
thd->push_internal_handler(&error_handler); thd->push_internal_handler(&error_handler);
bool got_error= open_table_def(thd, share); bool got_error= open_table_def(thd, share);
thd->pop_internal_handler(); 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) { if (!got_error) {
// Now we can work // Now we can work
if ((pos= share->option_struct)) { if ((pos= share->option_struct)) {
......
#
# 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;
--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;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment