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.
This commit is contained in:
Sergei Golubchik 2017-03-03 15:27:19 +01:00
parent 48b1d17534
commit 8f1ca5e311
2 changed files with 33 additions and 6 deletions

View file

@ -10,7 +10,7 @@ table_name t1
select table_schema, table_name, engine, version from information_schema.tables where table_name like 't1';
table_schema test
table_name t1
engine NULL
engine ARCHIVE
version NULL
Warnings:
Level Warning
@ -19,7 +19,7 @@ Message Unknown storage engine 'ARCHIVE'
select table_schema, table_name, engine, row_format from information_schema.tables where table_name like 't1';
table_schema test
table_name t1
engine NULL
engine ARCHIVE
row_format NULL
Warnings:
Level Warning

View file

@ -4056,6 +4056,22 @@ make_table_name_list(THD *thd, Dynamic_array<LEX_STRING*> *table_names,
}
static void get_table_engine_for_i_s(THD *thd, char *buf, TABLE_LIST *tl,
LEX_STRING *db, LEX_STRING *table)
{
LEX_STRING engine_name= { buf, 0 };
if (thd->get_stmt_da()->sql_errno() == ER_UNKNOWN_STORAGE_ENGINE)
{
char path[FN_REFLEN];
build_table_filename(path, sizeof(path) - 1,
db->str, table->str, reg_ext, 0);
if (dd_frm_type(thd, path, &engine_name) == FRMTYPE_TABLE)
tl->option= engine_name.str;
}
}
/**
Fill I_S table with data obtained by performing full-blown table open.
@ -4126,9 +4142,9 @@ fill_schema_table_by_open(THD *thd, bool is_show_fields_or_keys,
/*
Since make_table_list() might change database and table name passed
to it we create copies of orig_db_name and orig_table_name here.
These copies are used for make_table_list() while unaltered values
are passed to process_table() functions.
to it (if lower_case_table_names) we create copies of orig_db_name and
orig_table_name here. These copies are used for make_table_list()
while unaltered values are passed to process_table() functions.
*/
if (!thd->make_lex_string(&db_name,
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,
}
else
{
char buf[NAME_CHAR_LEN + 1];
if (thd->is_error())
get_table_engine_for_i_s(thd, buf, table_list, &db_name, &table_name);
result= schema_table->process_table(thd, table_list,
table, result,
orig_db_name,
@ -4525,7 +4545,9 @@ static int fill_schema_table_from_frm(THD *thd, TABLE *table,
}
else
{
table_list.table= &tbl;
char buf[NAME_CHAR_LEN + 1];
get_table_engine_for_i_s(thd, buf, &table_list, db_name, table_name);
res= schema_table->process_table(thd, &table_list, table,
true, db_name, table_name);
}
@ -4939,6 +4961,11 @@ static int get_schema_tables_record(THD *thd, TABLE_LIST *tables,
else
table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
if (tables->option)
{
table->field[4]->store(tables->option, strlen(tables->option), cs);
table->field[4]->set_notnull();
}
goto err;
}