Commit 050d7d6d authored by Sergei Golubchik's avatar Sergei Golubchik

optimize discovery for cases when the storage engine is known in advance

parent 3a8e1a22
......@@ -4162,6 +4162,8 @@ int ha_create_table(THD *thd, const char *path,
else
{
// open an frm file
share.db_plugin= ha_lock_engine(thd, create_info->db_type);
if (open_table_def(thd, &share))
goto err;
}
......@@ -4343,12 +4345,17 @@ static my_bool discover_handlerton(THD *thd, plugin_ref plugin,
int ha_discover_table(THD *thd, TABLE_SHARE *share)
{
DBUG_ENTER("ha_discover_table");
int found;
DBUG_ASSERT(share->error == OPEN_FRM_OPEN_ERROR); // share is not OK yet
DBUG_ASSERT(!share->db_plugin);
if (!plugin_foreach(thd, discover_handlerton,
MYSQL_STORAGE_ENGINE_PLUGIN, share))
if (share->db_plugin)
found= discover_handlerton(thd, share->db_plugin, share);
else
found= plugin_foreach(thd, discover_handlerton,
MYSQL_STORAGE_ENGINE_PLUGIN, share);
if (!found)
open_table_error(share, OPEN_FRM_OPEN_ERROR, ENOENT); // not found
DBUG_RETURN(share->error != OPEN_FRM_OK);
......
......@@ -5908,6 +5908,8 @@ void close_tables_for_reopen(THD *thd, TABLE_LIST **tables,
the opened TABLE instance will be addded to THD::temporary_tables list.
@param thd Thread context.
@param hton Storage engine of the table, if known,
or NULL otherwise.
@param path Path (without .frm)
@param db Database name.
@param table_name Table name.
......@@ -5923,7 +5925,8 @@ void close_tables_for_reopen(THD *thd, TABLE_LIST **tables,
@retval NULL on error.
*/
TABLE *open_table_uncached(THD *thd, const char *path, const char *db,
TABLE *open_table_uncached(THD *thd, handlerton *hton,
const char *path, const char *db,
const char *table_name,
bool add_to_temporary_tables_list)
{
......@@ -5953,6 +5956,7 @@ TABLE *open_table_uncached(THD *thd, const char *path, const char *db,
init_tmp_table_share(thd, share, saved_cache_key, key_length,
strend(saved_cache_key)+1, tmp_path);
share->db_plugin= ha_lock_engine(thd, hton);
if (open_table_def(thd, share, GTS_TABLE | GTS_FORCE_DISCOVERY) ||
open_table_from_share(thd, share, table_name,
......
......@@ -195,8 +195,8 @@ bool open_new_frm(THD *thd, TABLE_SHARE *share, const char *alias,
bool get_key_map_from_key_list(key_map *map, TABLE *table,
List<String> *index_list);
TABLE *open_table_uncached(THD *thd, const char *path, const char *db,
const char *table_name,
TABLE *open_table_uncached(THD *thd, handlerton *hton, const char *path,
const char *db, const char *table_name,
bool add_to_temporary_tables_list);
TABLE *find_locked_table(TABLE *list, const char *db, const char *table_name);
TABLE *find_write_locked_table(TABLE *list, const char *db,
......
......@@ -4536,7 +4536,7 @@ uint prep_alter_part_table(THD *thd, TABLE *table, Alter_info *alter_info,
*/
DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE, db, table_name,
MDL_INTENTION_EXCLUSIVE));
new_table= open_table_uncached(thd, path, db, table_name, 0);
new_table= open_table_uncached(thd, old_db_type, path, db, table_name, 0);
if (!new_table)
DBUG_RETURN(TRUE);
......
......@@ -2303,7 +2303,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
Let's lock the plugin till the end of the statement.
*/
if (table_type && table_type != view_pseudo_hton)
plugin_lock(thd, plugin_int_to_ref(hton2plugin[table_type->slot]));
ha_lock_engine(thd, table_type);
if (thd->locked_tables_mode)
{
......@@ -4052,6 +4052,7 @@ static bool check_if_created_table_can_be_opened(THD *thd,
return TRUE;
init_tmp_table_share(thd, &share, db, 0, table_name, path);
share.db_plugin= ha_lock_engine(thd, file->ht);
result= (open_table_def(thd, &share) ||
open_table_from_share(thd, &share, "", 0, (uint) READ_ALL,
......@@ -4401,7 +4402,7 @@ bool mysql_create_table_no_lock(THD *thd,
/* prepare everything for discovery */
share.field= &no_fields;
share.db_plugin= plugin_int_to_ref(hton2plugin[hton->slot]);
share.db_plugin= ha_lock_engine(thd, hton);
share.option_list= create_info->option_list;
share.connect_string= create_info->connect_string;
......@@ -4435,7 +4436,8 @@ bool mysql_create_table_no_lock(THD *thd,
THD::temporary_tables list.
*/
TABLE *table= open_table_uncached(thd, path, db, table_name, TRUE);
TABLE *table= open_table_uncached(thd, create_info->db_type, path,
db, table_name, TRUE);
if (!table)
{
......@@ -6779,7 +6781,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
build_table_filename(path, sizeof(path) - 1, new_db, tmp_name, "",
FN_IS_TMP);
/* Open our intermediate table. */
new_table= open_table_uncached(thd, path, new_db, tmp_name, TRUE);
new_table= open_table_uncached(thd, new_db_type, path,
new_db, tmp_name, TRUE);
}
if (!new_table)
goto err_new_table_cleanup;
......
......@@ -269,7 +269,7 @@ static bool recreate_temporary_table(THD *thd, TABLE *table)
dd_recreate_table(thd, share->db.str, share->table_name.str,
share->normalized_path.str);
if (open_table_uncached(thd, share->path.str, share->db.str,
if (open_table_uncached(thd, table_type, share->path.str, share->db.str,
share->table_name.str, TRUE))
{
error= FALSE;
......
......@@ -1101,10 +1101,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
plugin_ref tmp_plugin= ha_resolve_by_name(thd, &name);
if (tmp_plugin != NULL && !plugin_equals(tmp_plugin, se_plugin))
{
if (legacy_db_type > DB_TYPE_UNKNOWN &&
legacy_db_type < DB_TYPE_FIRST_DYNAMIC &&
legacy_db_type != ha_legacy_type(
plugin_data(tmp_plugin, handlerton *)))
if (se_plugin)
{
/* bad file, legacy_db_type did not match the name */
goto err;
......@@ -1236,6 +1233,9 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
}
share->key_block_size= uint2korr(frm_image+62);
if (share->db_plugin && !plugin_equals(share->db_plugin, se_plugin))
goto err; // wrong engine (someone changed the frm under our feet?)
extra_rec_buf_length= uint2korr(frm_image+59);
rec_buff_length= ALIGN_SIZE(share->reclength + 1 + extra_rec_buf_length);
share->rec_buff_length= rec_buff_length;
......@@ -1955,7 +1955,6 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
(void) my_hash_check(&share->name_hash);
#endif
DBUG_ASSERT(!share->db_plugin || plugin_equals(share->db_plugin, se_plugin));
share->db_plugin= se_plugin;
share->error= OPEN_FRM_OK;
thd->status_var.opened_shares++;
......
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