mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
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
This commit is contained in:
@ -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);
|
||||
/* hton is NULL in ALTER TABLE when renaming only .frm files */
|
||||
if (hton == NULL || hton == view_pseudo_hton)
|
||||
DBUG_RETURN(0);
|
||||
|
||||
bzero((char*) &dummy_table, sizeof(dummy_table));
|
||||
bzero((char*) &dummy_share, sizeof(dummy_share));
|
||||
dummy_table.s= &dummy_share;
|
||||
|
||||
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();
|
||||
@ -4947,22 +4963,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.
|
||||
|
||||
|
Reference in New Issue
Block a user