Commit b0a5dd73 authored by Sergei Golubchik's avatar Sergei Golubchik

* remove ha_check_if_table_exists() and get_table_share_with_discover().

* rename check_if_table_exists() -> table_exists() and remove unneeded arguments
parent 87a9d60e
......@@ -4203,33 +4203,6 @@ int ha_create_table_from_engine(THD* thd, const char *db, const char *name)
}
/**
Try to find a table in a storage engine.
@param db Normalized table schema name
@param name Normalized table name.
@param[out] exists Only valid if the function succeeded.
@retval TRUE An error is found
@retval FALSE Success, check *exists
*/
bool
ha_check_if_table_exists(THD* thd, const char *db, const char *name,
bool *exists)
{
uchar *frmblob= NULL;
size_t frmlen;
DBUG_ENTER("ha_check_if_table_exists");
*exists= ! ha_discover(thd, db, name, &frmblob, &frmlen);
if (*exists)
my_free(frmblob);
DBUG_RETURN(FALSE);
}
void st_ha_check_opt::init()
{
flags= sql_flags= 0;
......
......@@ -3068,8 +3068,6 @@ bool ha_show_status(THD *thd, handlerton *db_type, enum ha_stat_type stat);
/* discovery */
int ha_create_table_from_engine(THD* thd, const char *db, const char *name);
bool ha_check_if_table_exists(THD* thd, const char *db, const char *name,
bool *exists);
int ha_discover(THD* thd, const char* dbname, const char* name,
uchar** frmblob, size_t* frmlen);
int ha_discover_table_names(THD *thd, LEX_STRING *db, MY_DIR *dirp,
......
This diff is collapsed.
......@@ -112,7 +112,6 @@ TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
enum open_frm_error *error,
my_hash_value_type hash_value);
void release_table_share(TABLE_SHARE *share);
TABLE_SHARE *get_cached_table_share(const char *db, const char *table_name);
TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update,
uint lock_flags);
......@@ -333,8 +332,14 @@ TABLE *find_table_for_mdl_upgrade(THD *thd, const char *db,
const char *table_name,
bool no_error);
void mark_tmp_table_for_reuse(TABLE *table);
bool check_if_table_exists(THD *thd, TABLE_LIST *table, bool fast_check,
bool *exists);
bool table_exists(THD *thd, const char *db, const char *table_name,
const char *path);
static inline bool table_exists(THD *thd, TABLE_LIST *table)
{
return table_exists(thd, table->db, table->table_name, NULL);
}
int update_virtual_fields(THD *thd, TABLE *table,
enum enum_vcol_update_mode vcol_update_mode= VCOL_UPDATE_FOR_READ);
int dynamic_column_error_message(enum_dyncol_func_result rc);
......
......@@ -934,16 +934,10 @@ update_binlog:
for (tbl= tables; tbl; tbl= tbl->next_local)
{
uint tbl_name_len;
bool exists;
char quoted_name[FN_REFLEN+3];
// Only write drop table to the binlog for tables that no longer exist.
if (check_if_table_exists(thd, tbl, 0, &exists))
{
error= true;
goto exit;
}
if (exists)
if (table_exists(thd, tbl))
continue;
my_snprintf(quoted_name, sizeof(quoted_name), "%`s", tbl->table_name);
......
......@@ -4057,12 +4057,14 @@ fill_schema_table_by_open(THD *thd, bool is_show_fields_or_keys,
of backward compatibility.
*/
if (!is_show_fields_or_keys && result && thd->is_error() &&
thd->stmt_da->sql_errno() == ER_NO_SUCH_TABLE)
(thd->stmt_da->sql_errno() == ER_NO_SUCH_TABLE ||
thd->stmt_da->sql_errno() == ER_WRONG_OBJECT))
{
/*
Hide error for a non-existing table.
For example, this error can occur when we use a where condition
with a db name and table, but the table does not exist.
with a db name and table, but the table does not exist or
there is a view with the same name.
*/
result= false;
thd->clear_error();
......@@ -4383,7 +4385,7 @@ static int fill_schema_table_from_frm(THD *thd, TABLE_LIST *tables,
key_length= create_table_def_key(thd, key, &table_list, 0);
hash_value= my_calc_hash(&table_def_cache, (uchar*) key, key_length);
share= get_table_share(thd, &table_list, key, key_length,
FRM_READ_NO_ERROR_FOR_VIEW, &not_used, hash_value);
FRM_READ_TABLE_OR_VIEW, &not_used, hash_value);
if (!share)
{
res= 0;
......@@ -4407,10 +4409,7 @@ static int fill_schema_table_from_frm(THD *thd, TABLE_LIST *tables,
res= 1;
goto end_share;
}
}
if (share->is_view)
{
if (open_new_frm(thd, share, table_name->str,
(uint) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE |
HA_GET_INDEX | HA_TRY_READ_ONLY),
......
......@@ -2279,11 +2279,8 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
}
DEBUG_SYNC(thd, "rm_table_no_locks_before_delete_table");
error= 0;
if (drop_temporary ||
((access(path, F_OK) &&
ha_create_table_from_engine(thd, db, alias)) ||
(!drop_view &&
dd_frm_type(thd, path, &frm_db_type) != FRMTYPE_TABLE)))
if (drop_temporary || !table_exists(thd, db, alias, path) ||
(!drop_view && dd_frm_type(thd, path, &frm_db_type) != FRMTYPE_TABLE))
{
/*
One of the following cases happened:
......@@ -4320,50 +4317,10 @@ bool mysql_create_table_no_lock(THD *thd,
if (!internal_tmp_table && !(create_info->options & HA_LEX_CREATE_TMP_TABLE))
{
if (!access(path,F_OK))
if (table_exists(thd, db, table_name, path))
{
if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS)
goto warn;
my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name);
goto err;
}
/*
We don't assert here, but check the result, because the table could be
in the table definition cache and in the same time the .frm could be
missing from the disk, in case of manual intervention which deletes
the .frm file. The user has to use FLUSH TABLES; to clear the cache.
Then she could create the table. This case is pretty obscure and
therefore we don't introduce a new error message only for it.
*/
mysql_mutex_lock(&LOCK_open);
if (get_cached_table_share(db, table_name))
{
mysql_mutex_unlock(&LOCK_open);
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), table_name);
goto err;
}
mysql_mutex_unlock(&LOCK_open);
}
/*
Check that table with given name does not already
exist in any storage engine. In such a case it should
be discovered and the error ER_TABLE_EXISTS_ERROR be returned
unless user specified CREATE TABLE IF EXISTS
An exclusive metadata lock ensures that no
one else is attempting to discover the table. Since
it's not on disk as a frm file, no one could be using it!
*/
if (!(create_info->options & HA_LEX_CREATE_TMP_TABLE))
{
bool create_if_not_exists =
create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS;
bool exists_in_engine;
ha_check_if_table_exists(thd, db, table_name, &exists_in_engine);
if (exists_in_engine)
{
if (create_if_not_exists)
goto warn;
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), table_name);
goto err;
}
......
......@@ -685,8 +685,8 @@ enum open_frm_error open_table_def(THD *thd, TABLE_SHARE *share,
if (memcmp(head, STRING_WITH_LEN("TYPE=VIEW\n")) == 0)
{
share->is_view= 1;
share->error= op == FRM_READ_NO_ERROR_FOR_VIEW
? OPEN_FRM_OK : OPEN_FRM_NO_VIEWS;
share->error= op == FRM_READ_TABLE_ONLY
? OPEN_FRM_NOT_A_TABLE : OPEN_FRM_OK;
goto err;
}
if (!is_binary_frm_header(head))
......@@ -695,6 +695,11 @@ enum open_frm_error open_table_def(THD *thd, TABLE_SHARE *share,
share->error = OPEN_FRM_CORRUPTED;
goto err;
}
if (op == FRM_READ_VIEW_ONLY)
{
share->error = OPEN_FRM_NOT_A_VIEW;
goto err;
}
if (my_fstat(file, &stats, MYF(0)))
goto err;
......@@ -2802,7 +2807,7 @@ void open_table_error(TABLE_SHARE *share, enum open_frm_error error,
int db_errno)
{
char buff[FN_REFLEN];
myf errortype= ME_ERROR+ME_WAITTANG; // Write fatals error to log
const myf errortype= ME_ERROR+ME_WAITTANG; // Write fatals error to log
DBUG_ENTER("open_table_error");
switch (error) {
......@@ -2825,8 +2830,15 @@ void open_table_error(TABLE_SHARE *share, enum open_frm_error error,
break;
case OPEN_FRM_ERROR_ALREADY_ISSUED:
break;
case OPEN_FRM_NOT_A_VIEW:
my_error(ER_WRONG_OBJECT, MYF(0), share->db.str,
share->table_name.str, "VIEW");
break;
case OPEN_FRM_NOT_A_TABLE:
my_error(ER_WRONG_OBJECT, MYF(0), share->db.str,
share->table_name.str, "TABLE");
break;
case OPEN_FRM_DISCOVER:
case OPEN_FRM_NO_VIEWS:
DBUG_ASSERT(0); // open_table_error() is never called for this one
break;
case OPEN_FRM_CORRUPTED:
......
......@@ -569,7 +569,8 @@ enum open_frm_error {
OPEN_FRM_CORRUPTED,
OPEN_FRM_DISCOVER,
OPEN_FRM_ERROR_ALREADY_ISSUED,
OPEN_FRM_NO_VIEWS,
OPEN_FRM_NOT_A_VIEW,
OPEN_FRM_NOT_A_TABLE
};
/**
......@@ -2448,7 +2449,8 @@ static inline void dbug_tmp_restore_column_maps(MY_BITMAP *read_set,
enum read_frm_op {
FRM_READ_TABLE_ONLY,
FRM_READ_NO_ERROR_FOR_VIEW
FRM_READ_VIEW_ONLY,
FRM_READ_TABLE_OR_VIEW
};
size_t max_row_length(TABLE *table, const uchar *data);
......
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