Commit 80ce0c1c authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup: ha_checktype()

* error reporting was never needed
* avoid useless transformaton hton to db_type to hton
* in many cases the engine was guaranteed to exist, add asserts
* use ha_default_handlerton() instead of ha_checktype(DB_TYPE_DEFAULT)
parent 06c16904
......@@ -9,7 +9,7 @@ SHOW TABLES;
Tables_in_test
t1
SHOW CREATE TABLE t1;
ERROR HY000: Incorrect information in file: './test/t1.frm'
ERROR HY000: Failed to read from the .par file
DROP TABLE t1;
ERROR 42S02: Unknown table 'test.t1'
t1.frm
......
......@@ -17,7 +17,7 @@ let $MYSQLD_DATADIR= `SELECT @@datadir`;
--copy_file std_data/parts/t1_blackhole.par $MYSQLD_DATADIR/test/t1.par
SHOW TABLES;
--replace_result $MYSQLD_DATADIR ./
--error ER_NOT_FORM_FILE
--error ER_FAILED_READ_FROM_PAR_FILE
SHOW CREATE TABLE t1;
--error ER_BAD_TABLE_ERROR
DROP TABLE t1;
......
......@@ -231,24 +231,13 @@ handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type)
/**
Use other database handler if databasehandler is not compiled in.
*/
handlerton *ha_checktype(THD *thd, enum legacy_db_type database_type,
bool no_substitute, bool report_error)
handlerton *ha_checktype(THD *thd, handlerton *hton, bool no_substitute)
{
handlerton *hton= ha_resolve_by_legacy_type(thd, database_type);
if (ha_storage_engine_is_enabled(hton))
return hton;
if (no_substitute)
{
if (report_error)
{
const char *engine_name= ha_resolve_storage_engine_name(hton);
my_error(ER_FEATURE_DISABLED,MYF(0),engine_name,engine_name);
}
return NULL;
}
(void) RUN_HOOK(transaction, after_rollback, (thd, FALSE));
return ha_default_handlerton(thd);
} /* ha_checktype */
......
......@@ -4061,9 +4061,13 @@ plugin_ref ha_lock_engine(THD *thd, const handlerton *hton);
handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type);
handler *get_new_handler(TABLE_SHARE *share, MEM_ROOT *alloc,
handlerton *db_type);
handlerton *ha_checktype(THD *thd, enum legacy_db_type database_type,
bool no_substitute, bool report_error);
handlerton *ha_checktype(THD *thd, handlerton *hton, bool no_substitute);
static inline handlerton *ha_checktype(THD *thd, enum legacy_db_type type,
bool no_substitute = 0)
{
return ha_checktype(thd, ha_resolve_by_legacy_type(thd, type), no_substitute);
}
static inline enum legacy_db_type ha_legacy_type(const handlerton *db_type)
{
......
......@@ -4452,8 +4452,7 @@ handler *mysql_create_frm_image(THD *thd,
{
if (part_info->default_engine_type == NULL)
{
part_info->default_engine_type= ha_checktype(thd,
DB_TYPE_DEFAULT, 0, 0);
part_info->default_engine_type= ha_default_handlerton(thd);
}
}
}
......@@ -9748,10 +9747,10 @@ static bool check_engine(THD *thd, const char *db_name,
DBUG_ENTER("check_engine");
handlerton **new_engine= &create_info->db_type;
handlerton *req_engine= *new_engine;
bool no_substitution=
MY_TEST(thd->variables.sql_mode & MODE_NO_ENGINE_SUBSTITUTION);
if (!(*new_engine= ha_checktype(thd, ha_legacy_type(req_engine),
no_substitution, 1)))
bool no_substitution= thd->variables.sql_mode & MODE_NO_ENGINE_SUBSTITUTION;
*new_engine= ha_checktype(thd, req_engine, no_substitution);
DBUG_ASSERT(*new_engine);
if (!*new_engine)
DBUG_RETURN(true);
if (req_engine && req_engine != *new_engine)
......
......@@ -1047,8 +1047,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
if (frm_image[61] && !share->default_part_plugin)
{
enum legacy_db_type db_type= (enum legacy_db_type) (uint) frm_image[61];
share->default_part_plugin=
ha_lock_engine(NULL, ha_checktype(thd, db_type, 1, 0));
share->default_part_plugin= ha_lock_engine(NULL, ha_checktype(thd, db_type));
if (!share->default_part_plugin)
goto err;
}
......@@ -1060,7 +1059,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
*/
if (legacy_db_type > DB_TYPE_UNKNOWN &&
legacy_db_type < DB_TYPE_FIRST_DYNAMIC)
se_plugin= ha_lock_engine(NULL, ha_checktype(thd, legacy_db_type, 0, 0));
se_plugin= ha_lock_engine(NULL, ha_checktype(thd, legacy_db_type));
share->db_create_options= db_create_options= uint2korr(frm_image+30);
share->db_options_in_use= share->db_create_options;
share->mysql_version= uint4korr(frm_image+51);
......@@ -3305,8 +3304,8 @@ void prepare_frm_header(THD *thd, uint reclength, uchar *fileinfo,
fileinfo[1]= 1;
fileinfo[2]= FRM_VER + 3 + MY_TEST(create_info->varchar);
fileinfo[3]= (uchar) ha_legacy_type(
ha_checktype(thd,ha_legacy_type(create_info->db_type),0,0));
DBUG_ASSERT(ha_storage_engine_is_enabled(create_info->db_type));
fileinfo[3]= (uchar) ha_legacy_type(create_info->db_type);
/*
Keep in sync with pack_keys() in unireg.cc
......
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