don't use I_S constants for open_table_def and get_table_share,
have a specially defined enum with clearly named values
This commit is contained in:
parent
cda52b2cb2
commit
5ad68a0d2f
@ -4104,7 +4104,7 @@ int ha_create_table(THD *thd, const char *path,
|
||||
DBUG_ENTER("ha_create_table");
|
||||
|
||||
init_tmp_table_share(thd, &share, db, 0, table_name, path);
|
||||
if (open_table_def(thd, &share, 0) ||
|
||||
if (open_table_def(thd, &share) ||
|
||||
open_table_from_share(thd, &share, "", 0, (uint) READ_ALL, 0, &table,
|
||||
TRUE))
|
||||
goto err;
|
||||
@ -4171,7 +4171,7 @@ int ha_create_table_from_engine(THD* thd, const char *db, const char *name)
|
||||
DBUG_RETURN(2);
|
||||
|
||||
init_tmp_table_share(thd, &share, db, 0, name, path);
|
||||
if (open_table_def(thd, &share, 0))
|
||||
if (open_table_def(thd, &share))
|
||||
{
|
||||
DBUG_RETURN(3);
|
||||
}
|
||||
|
@ -128,8 +128,8 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list,
|
||||
|
||||
hash_value= my_calc_hash(&table_def_cache, (uchar*) key, key_length);
|
||||
mysql_mutex_lock(&LOCK_open);
|
||||
share= get_table_share(thd, table_list, key, key_length, 0,
|
||||
&error, hash_value);
|
||||
share= get_table_share(thd, table_list, key, key_length,
|
||||
FRM_READ_TABLE_ONLY, &error, hash_value);
|
||||
mysql_mutex_unlock(&LOCK_open);
|
||||
if (share == NULL)
|
||||
DBUG_RETURN(0); // Can't open frm file
|
||||
|
@ -575,7 +575,7 @@ static void table_def_unuse_table(TABLE *table)
|
||||
*/
|
||||
|
||||
TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
|
||||
uint key_length, uint db_flags, int *error,
|
||||
uint key_length, enum read_frm_op op, int *error,
|
||||
my_hash_value_type hash_value)
|
||||
{
|
||||
TABLE_SHARE *share;
|
||||
@ -622,7 +622,7 @@ TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
|
||||
free_table_share(share);
|
||||
DBUG_RETURN(0); // return error
|
||||
}
|
||||
if (open_table_def(thd, share, db_flags))
|
||||
if (open_table_def(thd, share, op))
|
||||
{
|
||||
*error= share->error;
|
||||
(void) my_hash_delete(&table_def_cache, (uchar*) share);
|
||||
@ -644,7 +644,7 @@ found:
|
||||
open_table_error(share, share->error, share->open_errno, share->errarg);
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
if (share->is_view && !(db_flags & OPEN_VIEW))
|
||||
if (share->is_view && op != FRM_READ_NO_ERROR_FOR_VIEW)
|
||||
{
|
||||
open_table_error(share, 1, ENOENT, 0);
|
||||
DBUG_RETURN(0);
|
||||
@ -685,7 +685,7 @@ found:
|
||||
static TABLE_SHARE *
|
||||
get_table_share_with_discover(THD *thd, TABLE_LIST *table_list,
|
||||
char *key, uint key_length,
|
||||
uint db_flags, int *error,
|
||||
enum read_frm_op op, int *error,
|
||||
my_hash_value_type hash_value)
|
||||
|
||||
{
|
||||
@ -693,7 +693,7 @@ get_table_share_with_discover(THD *thd, TABLE_LIST *table_list,
|
||||
bool exists;
|
||||
DBUG_ENTER("get_table_share_with_discover");
|
||||
|
||||
share= get_table_share(thd, table_list, key, key_length, db_flags, error,
|
||||
share= get_table_share(thd, table_list, key, key_length, op, error,
|
||||
hash_value);
|
||||
/*
|
||||
If share is not NULL, we found an existing share.
|
||||
@ -3014,10 +3014,9 @@ retry_share:
|
||||
|
||||
mysql_mutex_lock(&LOCK_open);
|
||||
|
||||
if (!(share= get_table_share_with_discover(thd, table_list, key,
|
||||
key_length, OPEN_VIEW,
|
||||
&error,
|
||||
hash_value)))
|
||||
if (!(share= get_table_share_with_discover(thd, table_list, key, key_length,
|
||||
FRM_READ_NO_ERROR_FOR_VIEW,
|
||||
&error, hash_value)))
|
||||
{
|
||||
mysql_mutex_unlock(&LOCK_open);
|
||||
/*
|
||||
@ -3856,10 +3855,8 @@ bool tdc_open_view(THD *thd, TABLE_LIST *table_list, const char *alias,
|
||||
cache_key_length);
|
||||
mysql_mutex_lock(&LOCK_open);
|
||||
|
||||
if (!(share= get_table_share(thd, table_list, cache_key,
|
||||
cache_key_length,
|
||||
OPEN_VIEW, &error,
|
||||
hash_value)))
|
||||
if (!(share= get_table_share(thd, table_list, cache_key, cache_key_length,
|
||||
FRM_READ_NO_ERROR_FOR_VIEW, &error, hash_value)))
|
||||
goto err;
|
||||
|
||||
if (share->is_view &&
|
||||
@ -3949,9 +3946,8 @@ static bool auto_repair_table(THD *thd, TABLE_LIST *table_list)
|
||||
cache_key_length);
|
||||
mysql_mutex_lock(&LOCK_open);
|
||||
|
||||
if (!(share= get_table_share(thd, table_list, cache_key,
|
||||
cache_key_length,
|
||||
OPEN_VIEW, ¬_used,
|
||||
if (!(share= get_table_share(thd, table_list, cache_key, cache_key_length,
|
||||
FRM_READ_NO_ERROR_FOR_VIEW, ¬_used,
|
||||
hash_value)))
|
||||
goto end_unlock;
|
||||
|
||||
@ -6117,7 +6113,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);
|
||||
|
||||
if (open_table_def(thd, share, 0) ||
|
||||
if (open_table_def(thd, share) ||
|
||||
open_table_from_share(thd, share, table_name,
|
||||
(uint) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE |
|
||||
HA_GET_INDEX),
|
||||
@ -9249,7 +9245,7 @@ my_bool mysql_rm_tmp_tables(void)
|
||||
memcpy(filePathCopy, filePath, filePath_len - ext_len);
|
||||
filePathCopy[filePath_len - ext_len]= 0;
|
||||
init_tmp_table_share(thd, &share, "", 0, "", filePathCopy);
|
||||
if (!open_table_def(thd, &share, 0) &&
|
||||
if (!open_table_def(thd, &share) &&
|
||||
((handler_file= get_new_handler(&share, thd->mem_root,
|
||||
share.db_type()))))
|
||||
{
|
||||
|
@ -108,7 +108,7 @@ create_table_def_key(char *key, const char *db, const char *table_name)
|
||||
}
|
||||
|
||||
TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
|
||||
uint key_length, uint db_flags, int *error,
|
||||
uint key_length, enum read_frm_op op, int *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);
|
||||
|
@ -4383,8 +4383,8 @@ 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);
|
||||
mysql_mutex_lock(&LOCK_open);
|
||||
share= get_table_share(thd, &table_list, key,
|
||||
key_length, OPEN_VIEW, ¬_used, hash_value);
|
||||
share= get_table_share(thd, &table_list, key, key_length,
|
||||
FRM_READ_NO_ERROR_FOR_VIEW, ¬_used, hash_value);
|
||||
if (!share)
|
||||
{
|
||||
res= 0;
|
||||
|
@ -4023,7 +4023,7 @@ static bool check_if_created_table_can_be_opened(THD *thd,
|
||||
|
||||
init_tmp_table_share(thd, &share, db, 0, table_name, path);
|
||||
|
||||
result= (open_table_def(thd, &share, 0) ||
|
||||
result= (open_table_def(thd, &share) ||
|
||||
open_table_from_share(thd, &share, "", 0, (uint) READ_ALL,
|
||||
0, &table, TRUE));
|
||||
if (! result)
|
||||
|
12
sql/table.cc
12
sql/table.cc
@ -619,7 +619,7 @@ static bool has_disabled_path_chars(const char *str)
|
||||
6 Unknown .frm version
|
||||
*/
|
||||
|
||||
int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags)
|
||||
int open_table_def(THD *thd, TABLE_SHARE *share, enum read_frm_op op)
|
||||
{
|
||||
int error, table_type;
|
||||
bool error_given;
|
||||
@ -693,17 +693,11 @@ int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags)
|
||||
if (head[2] == FRM_VER || head[2] == FRM_VER+1 ||
|
||||
(head[2] >= FRM_VER+3 && head[2] <= FRM_VER+4))
|
||||
{
|
||||
/* Open view only */
|
||||
if (db_flags & OPEN_VIEW_ONLY)
|
||||
{
|
||||
error_given= 1;
|
||||
goto err;
|
||||
}
|
||||
table_type= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
error= 6; // Unkown .frm version
|
||||
error= 6; // Unknown .frm version
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
@ -713,7 +707,7 @@ int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags)
|
||||
if (memcmp(head+5,"VIEW",4) == 0)
|
||||
{
|
||||
share->is_view= 1;
|
||||
if (db_flags & OPEN_VIEW)
|
||||
if (op == FRM_READ_NO_ERROR_FOR_VIEW)
|
||||
error= 0;
|
||||
}
|
||||
goto err;
|
||||
|
@ -2433,10 +2433,13 @@ static inline void dbug_tmp_restore_column_maps(MY_BITMAP *read_set,
|
||||
#endif
|
||||
}
|
||||
|
||||
enum read_frm_op {
|
||||
FRM_READ_TABLE_ONLY,
|
||||
FRM_READ_NO_ERROR_FOR_VIEW
|
||||
};
|
||||
|
||||
size_t max_row_length(TABLE *table, const uchar *data);
|
||||
|
||||
|
||||
void init_mdl_requests(TABLE_LIST *table_list);
|
||||
|
||||
int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias,
|
||||
@ -2451,7 +2454,8 @@ void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key,
|
||||
uint key_length,
|
||||
const char *table_name, const char *path);
|
||||
void free_table_share(TABLE_SHARE *share);
|
||||
int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags);
|
||||
int open_table_def(THD *thd, TABLE_SHARE *share,
|
||||
enum read_frm_op op = FRM_READ_TABLE_ONLY);
|
||||
void open_table_error(TABLE_SHARE *share, int error, int db_errno, int errarg);
|
||||
void update_create_info_from_table(HA_CREATE_INFO *info, TABLE *form);
|
||||
bool check_and_convert_db_name(LEX_STRING *db, bool preserve_lettercase);
|
||||
|
Loading…
x
Reference in New Issue
Block a user