1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

MDEV-11412 Ensure that table is truly dropped when using DROP TABLE

don't do table discovery on DROP. DROP falls back to "force"
approach when a table isn't found and will try to drop in all
engines anyway. That is, trying to discover in all engines before
the drop is redundant and may be expensive.
This commit is contained in:
Sergei Golubchik
2020-06-16 10:33:48 +02:00
parent 79a3f96166
commit 7c2ba9e9d7
6 changed files with 85 additions and 73 deletions

View File

@ -45,6 +45,7 @@
#include "sql_audit.h"
#include "ha_sequence.h"
#include "rowid_filter.h"
#include "mysys_err.h"
#ifdef WITH_PARTITION_STORAGE_ENGINE
#include "ha_partition.h"
@ -2771,18 +2772,20 @@ int ha_delete_table(THD *thd, handlerton *hton, const char *path,
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 (file) {
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)
{
@ -4455,10 +4458,6 @@ int handler::delete_table(const char *name)
bool some_file_deleted= 0;
DBUG_ENTER("handler::delete_table");
// For discovery tables, it's ok if first file doesn't exists
if (ht->discover_table)
saved_error= 0;
for (const char **ext= bas_ext(); *ext ; ext++)
{
int err= mysql_file_delete_with_symlink(key_file_misc, name, *ext, MYF(0));
@ -4522,7 +4521,9 @@ void handler::drop_table(const char *name)
bool non_existing_table_error(int error)
{
return (error == ENOENT || error == HA_ERR_NO_SUCH_TABLE ||
return (error == ENOENT ||
(error == EE_DELETE && my_errno == ENOENT) ||
error == HA_ERR_NO_SUCH_TABLE ||
error == HA_ERR_UNSUPPORTED ||
error == ER_NO_SUCH_TABLE ||
error == ER_NO_SUCH_TABLE_IN_ENGINE ||
@ -5002,12 +5003,11 @@ static my_bool delete_table_force(THD *thd, plugin_ref plugin, void *arg)
/*
We have to ignore HEAP tables as these may not have been created yet
We also remove engines that is using discovery (as these will recrate
any missing .frm if needed) and tables marked with
We also remove engines marked with
HTON_AUTOMATIC_DELETE_TABLE as for these we can't check if the table
ever existed.
*/
if (!hton->discover_table && hton->db_type != DB_TYPE_HEAP &&
if (hton->db_type != DB_TYPE_HEAP &&
!(hton->flags & HTON_AUTOMATIC_DELETE_TABLE))
{
int error;