Commit 5ad68a0d authored by Sergei Golubchik's avatar Sergei Golubchik

don't use I_S constants for open_table_def and get_table_share,

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