diff options
author | Sergei Golubchik <serg@mariadb.org> | 2020-06-13 21:23:19 +0200 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2020-07-04 01:44:46 +0200 |
commit | c55c292832e2776d37e06c43174ac006e00143a2 (patch) | |
tree | e83cc7fd44b132de7a4c33975737825ccd18907e /sql/handler.cc | |
parent | f17f7a43ba7da44608618f9e612f9808d363da23 (diff) | |
download | mariadb-git-c55c292832e2776d37e06c43174ac006e00143a2.tar.gz |
introduce hton->drop_table() method
first step in moving drop table out of the handler.
todo: other methods that don't need an open table
for now hton->drop_table is optional, for backward compatibility
reasons
Diffstat (limited to 'sql/handler.cc')
-rw-r--r-- | sql/handler.cc | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/sql/handler.cc b/sql/handler.cc index c2fb7da384c..8642c773007 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -546,6 +546,26 @@ static void update_discovery_counters(handlerton *hton, int val) engines_with_discover+= val; } +int ha_drop_table(THD *thd, handlerton *hton, const char *path) +{ + if (ha_check_if_updates_are_ignored(thd, hton, "DROP")) + return 0; // Simulate dropped + return hton->drop_table(hton, path); +} + +static int hton_drop_table(handlerton *hton, const char *path) +{ + char tmp_path[FN_REFLEN]; + handler *file= get_new_handler(nullptr, current_thd->mem_root, hton); + if (!file) + return ENOMEM; + path= get_canonical_filename(file, path, tmp_path); + int error= file->delete_table(path); + delete file; + return error; +} + + int ha_finalize_handlerton(st_plugin_int *plugin) { handlerton *hton= (handlerton *)plugin->data; @@ -616,6 +636,7 @@ int ha_initialize_handlerton(st_plugin_int *plugin) hton->tablefile_extensions= no_exts; hton->discover_table_names= hton_ext_based_table_discovery; + hton->drop_table= hton_drop_table; hton->slot= HA_SLOT_UNDEF; /* Historical Requirement */ @@ -2724,29 +2745,19 @@ const char *get_canonical_filename(handler *file, const char *path, The .frm file should be deleted by the caller only if we return <= 0. */ -int ha_delete_table(THD *thd, handlerton *table_type, const char *path, +int ha_delete_table(THD *thd, handlerton *hton, const char *path, const LEX_CSTRING *db, const LEX_CSTRING *alias, bool generate_warning) { - handler *file; - char tmp_path[FN_REFLEN]; int error; - TABLE dummy_table; - TABLE_SHARE dummy_share; bool is_error= thd->is_error(); DBUG_ENTER("ha_delete_table"); - /* table_type is NULL in ALTER TABLE when renaming only .frm files */ - if (table_type == NULL || table_type == view_pseudo_hton || - ! (file=get_new_handler((TABLE_SHARE*)0, thd->mem_root, table_type))) - DBUG_RETURN(-1); - - bzero((char*) &dummy_table, sizeof(dummy_table)); - bzero((char*) &dummy_share, sizeof(dummy_share)); - dummy_table.s= &dummy_share; + /* hton is NULL in ALTER TABLE when renaming only .frm files */ + if (hton == NULL || hton == view_pseudo_hton) + DBUG_RETURN(0); - path= get_canonical_filename(file, path, tmp_path); - if (unlikely((error= file->ha_delete_table(path)))) + if (unlikely((error= hton->drop_table(hton, path)))) { /* It's not an error if the table doesn't exist in the engine. @@ -2757,15 +2768,21 @@ int ha_delete_table(THD *thd, handlerton *table_type, const char *path, if ((!intercept || generate_warning) && ! thd->is_error()) { - /* Fill up strucutures that print_error may need */ + TABLE dummy_table; + TABLE_SHARE dummy_share; + handler *file= get_new_handler(nullptr, thd->mem_root, hton); + bzero((char*) &dummy_table, sizeof(dummy_table)); + bzero((char*) &dummy_share, sizeof(dummy_share)); dummy_share.path.str= (char*) path; dummy_share.path.length= strlen(path); dummy_share.normalized_path= dummy_share.path; dummy_share.db= *db; dummy_share.table_name= *alias; + dummy_table.s= &dummy_share; dummy_table.alias.set(alias->str, alias->length, table_alias_charset); file->change_table_ptr(&dummy_table, &dummy_share); file->print_error(error, MYF(intercept ? ME_WARNING : 0)); + delete file; } if (intercept) { @@ -2775,7 +2792,6 @@ int ha_delete_table(THD *thd, handlerton *table_type, const char *path, error= -1; } } - delete file; DBUG_RETURN(error); } @@ -4586,8 +4602,8 @@ void handler::mark_trx_read_write_internal() if (ha_info->is_started()) { /* - table_share can be NULL in ha_delete_table(). See implementation - of standalone function ha_delete_table() in sql_base.cc. + table_share can be NULL, for example, in ha_delete_table() or + ha_rename_table(). */ if (table_share == NULL || table_share->tmp_table == NO_TMP_TABLE) ha_info->set_trx_read_write(); @@ -4948,22 +4964,6 @@ handler::ha_rename_table(const char *from, const char *to) /** - Delete table: public interface. - - @sa handler::delete_table() -*/ - -int -handler::ha_delete_table(const char *name) -{ - if (ha_check_if_updates_are_ignored(ha_thd(), ht, "DROP")) - return 0; // Simulate dropped - mark_trx_read_write(); - return delete_table(name); -} - - -/** Drop table in the engine: public interface. @sa handler::drop_table() |