Skip to content

Commit 1799caa

Browse files
committed
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.
1 parent 322129d commit 1799caa

File tree

5 files changed

+42
-8
lines changed

5 files changed

+42
-8
lines changed

sql/handler.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,11 @@ enum chf_create_flags {
307307

308308
#define HA_PERSISTENT_TABLE (1ULL << 48)
309309

310-
/* If storage engine uses another engine as a base */
310+
/*
311+
If storage engine uses another engine as a base
312+
This flag is also needed if the table tries to open the .frm file
313+
as part of drop table.
314+
*/
311315
#define HA_REUSES_FILE_NAMES (1ULL << 49)
312316

313317
/*

sql/sql_table.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10900,12 +10900,11 @@ do_continue:;
1090010900
The above is mainly true for the sequence and the partition engine.
1090110901
*/
1090210902
engine_changed= ((new_table->file->ht != table->file->ht) &&
10903-
(((!(new_table->file->ha_table_flags() & HA_FILE_BASED) ||
10904-
!(table->file->ha_table_flags() & HA_FILE_BASED))) ||
10905-
(!(table->file->ha_table_flags() & HA_REUSES_FILE_NAMES) &&
10906-
!(new_table->file->ha_table_flags() &
10907-
HA_REUSES_FILE_NAMES))));
10908-
10903+
((!(new_table->file->ha_table_flags() & HA_FILE_BASED) ||
10904+
!(table->file->ha_table_flags() & HA_FILE_BASED))) &&
10905+
!(table->file->ha_table_flags() & HA_REUSES_FILE_NAMES) &&
10906+
!(new_table->file->ha_table_flags() &
10907+
HA_REUSES_FILE_NAMES));
1090910908
/*
1091010909
Close the intermediate table that will be the new table, but do
1091110910
not delete it! Even though MERGE tables do not have their children

storage/connect/ha_connect.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,8 @@ ulonglong ha_connect::table_flags() const
11691169
// HA_NULL_IN_KEY | not implemented yet
11701170
// HA_FAST_KEY_READ | causes error when sorting (???)
11711171
HA_NO_TRANSACTIONS | HA_DUPLICATE_KEY_NOT_IN_ORDER |
1172-
HA_NO_BLOBS | HA_MUST_USE_TABLE_CONDITION_PUSHDOWN;
1172+
HA_NO_BLOBS | HA_MUST_USE_TABLE_CONDITION_PUSHDOWN |
1173+
HA_REUSES_FILE_NAMES;
11731174
ha_connect *hp= (ha_connect*)this;
11741175
PTOS pos= hp->GetTableOptionStruct();
11751176

@@ -5244,6 +5245,14 @@ int ha_connect::delete_or_rename_table(const char *name, const char *to)
52445245
thd->push_internal_handler(&error_handler);
52455246
bool got_error= open_table_def(thd, share);
52465247
thd->pop_internal_handler();
5248+
if (!got_error && share->db_type() != connect_hton)
5249+
{
5250+
/* The .frm file is not for the connect engine. Something is wrong! */
5251+
got_error= 1;
5252+
rc= HA_ERR_INTERNAL_ERROR;
5253+
my_error(HA_ERR_INTERNAL_ERROR, MYF(0),
5254+
"TABLE_SHARE is not for the CONNECT engine");
5255+
}
52475256
if (!got_error) {
52485257
// Now we can work
52495258
if ((pos= share->option_struct)) {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#
2+
# MDEV-24422 Server crashes in GetTypeID / ha_connect::GetRealType upon
3+
# altering table engine
4+
#
5+
CREATE TABLE t1 (f INT) ENGINE=CONNECT;
6+
Warnings:
7+
Warning 1105 No table_type. Will be set to DOS
8+
Warning 1105 No file name. Table will use t1.dos
9+
ALTER TABLE t1 ENGINE InnoDB;
10+
ALTER TABLE t1 ENGINE CONNECT;
11+
DROP TABLE t1;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--source include/have_innodb.inc
2+
3+
--echo #
4+
--echo # MDEV-24422 Server crashes in GetTypeID / ha_connect::GetRealType upon
5+
--echo # altering table engine
6+
--echo #
7+
8+
CREATE TABLE t1 (f INT) ENGINE=CONNECT;
9+
ALTER TABLE t1 ENGINE InnoDB;
10+
ALTER TABLE t1 ENGINE CONNECT;
11+
DROP TABLE t1;

0 commit comments

Comments
 (0)