Skip to content

Commit 8f1ca5e

Browse files
committed
MDEV-11943 I_S.TABLES inconsistencies with tables with unknown storage engine
Try harder to show the table's engine. If the table's engine is not loaded, the table won't open. But we can still read the engine name from frm as a string.
1 parent 48b1d17 commit 8f1ca5e

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

mysql-test/r/drop_bad_db_type.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ table_name t1
1010
select table_schema, table_name, engine, version from information_schema.tables where table_name like 't1';
1111
table_schema test
1212
table_name t1
13-
engine NULL
13+
engine ARCHIVE
1414
version NULL
1515
Warnings:
1616
Level Warning
@@ -19,7 +19,7 @@ Message Unknown storage engine 'ARCHIVE'
1919
select table_schema, table_name, engine, row_format from information_schema.tables where table_name like 't1';
2020
table_schema test
2121
table_name t1
22-
engine NULL
22+
engine ARCHIVE
2323
row_format NULL
2424
Warnings:
2525
Level Warning

sql/sql_show.cc

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4056,6 +4056,22 @@ make_table_name_list(THD *thd, Dynamic_array<LEX_STRING*> *table_names,
40564056
}
40574057

40584058

4059+
static void get_table_engine_for_i_s(THD *thd, char *buf, TABLE_LIST *tl,
4060+
LEX_STRING *db, LEX_STRING *table)
4061+
{
4062+
LEX_STRING engine_name= { buf, 0 };
4063+
4064+
if (thd->get_stmt_da()->sql_errno() == ER_UNKNOWN_STORAGE_ENGINE)
4065+
{
4066+
char path[FN_REFLEN];
4067+
build_table_filename(path, sizeof(path) - 1,
4068+
db->str, table->str, reg_ext, 0);
4069+
if (dd_frm_type(thd, path, &engine_name) == FRMTYPE_TABLE)
4070+
tl->option= engine_name.str;
4071+
}
4072+
}
4073+
4074+
40594075
/**
40604076
Fill I_S table with data obtained by performing full-blown table open.
40614077
@@ -4126,9 +4142,9 @@ fill_schema_table_by_open(THD *thd, bool is_show_fields_or_keys,
41264142

41274143
/*
41284144
Since make_table_list() might change database and table name passed
4129-
to it we create copies of orig_db_name and orig_table_name here.
4130-
These copies are used for make_table_list() while unaltered values
4131-
are passed to process_table() functions.
4145+
to it (if lower_case_table_names) we create copies of orig_db_name and
4146+
orig_table_name here. These copies are used for make_table_list()
4147+
while unaltered values are passed to process_table() functions.
41324148
*/
41334149
if (!thd->make_lex_string(&db_name,
41344150
orig_db_name->str, orig_db_name->length) ||
@@ -4215,6 +4231,10 @@ fill_schema_table_by_open(THD *thd, bool is_show_fields_or_keys,
42154231
}
42164232
else
42174233
{
4234+
char buf[NAME_CHAR_LEN + 1];
4235+
if (thd->is_error())
4236+
get_table_engine_for_i_s(thd, buf, table_list, &db_name, &table_name);
4237+
42184238
result= schema_table->process_table(thd, table_list,
42194239
table, result,
42204240
orig_db_name,
@@ -4525,7 +4545,9 @@ static int fill_schema_table_from_frm(THD *thd, TABLE *table,
45254545
}
45264546
else
45274547
{
4528-
table_list.table= &tbl;
4548+
char buf[NAME_CHAR_LEN + 1];
4549+
get_table_engine_for_i_s(thd, buf, &table_list, db_name, table_name);
4550+
45294551
res= schema_table->process_table(thd, &table_list, table,
45304552
true, db_name, table_name);
45314553
}
@@ -4939,6 +4961,11 @@ static int get_schema_tables_record(THD *thd, TABLE_LIST *tables,
49394961
else
49404962
table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
49414963

4964+
if (tables->option)
4965+
{
4966+
table->field[4]->store(tables->option, strlen(tables->option), cs);
4967+
table->field[4]->set_notnull();
4968+
}
49424969
goto err;
49434970
}
49444971

0 commit comments

Comments
 (0)