diff options
author | Sergei Golubchik <sergii@pisem.net> | 2013-04-09 16:20:48 +0200 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2013-04-09 16:20:48 +0200 |
commit | 050d7d6d75cbeb2f048dd0786c702452d2d7c18f (patch) | |
tree | 6106cc984e739698cab322cf8cf719b09a97fc1c | |
parent | 3a8e1a2205b6e4147a484c598d59f01a9c8b720b (diff) | |
download | mariadb-git-050d7d6d75cbeb2f048dd0786c702452d2d7c18f.tar.gz |
optimize discovery for cases when the storage engine is known in advance
-rw-r--r-- | sql/handler.cc | 13 | ||||
-rw-r--r-- | sql/sql_base.cc | 6 | ||||
-rw-r--r-- | sql/sql_base.h | 4 | ||||
-rw-r--r-- | sql/sql_partition.cc | 2 | ||||
-rw-r--r-- | sql/sql_table.cc | 11 | ||||
-rw-r--r-- | sql/sql_truncate.cc | 2 | ||||
-rw-r--r-- | sql/table.cc | 9 |
7 files changed, 30 insertions, 17 deletions
diff --git a/sql/handler.cc b/sql/handler.cc index b9480e8611d..f890c2c8324 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -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); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 15eab7f32df..72a9e69b042 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -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, diff --git a/sql/sql_base.h b/sql/sql_base.h index fc95ecb0119..95d9bf21fe8 100644 --- a/sql/sql_base.h +++ b/sql/sql_base.h @@ -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, diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index ecd8315b80d..b2e2016b47d 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -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); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 09220a41983..8862fcc7d0e 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -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; diff --git a/sql/sql_truncate.cc b/sql/sql_truncate.cc index 92c4d150433..19ce553f5ce 100644 --- a/sql/sql_truncate.cc +++ b/sql/sql_truncate.cc @@ -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; diff --git a/sql/table.cc b/sql/table.cc index f927b3febce..ccb763847d6 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -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++; |