mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 12:02:42 +01:00
convenience helpers for get_table_share() and tdc_open_view().
Pass db and table_name into a function instead of the table_list, when only db and table name are needed.
This commit is contained in:
parent
b0a5dd73fa
commit
934115184b
7 changed files with 82 additions and 87 deletions
|
@ -100,8 +100,6 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list,
|
|||
|
||||
if (!(table= table_list->table))
|
||||
{
|
||||
char key[MAX_DBKEY_LENGTH];
|
||||
uint key_length;
|
||||
/*
|
||||
If the table didn't exist, we have a shared metadata lock
|
||||
on it that is left from mysql_admin_table()'s attempt to
|
||||
|
@ -114,9 +112,7 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list,
|
|||
Attempt to do full-blown table open in mysql_admin_table() has failed.
|
||||
Let us try to open at least a .FRM for this table.
|
||||
*/
|
||||
my_hash_value_type hash_value;
|
||||
|
||||
key_length= create_table_def_key(thd, key, table_list, 0);
|
||||
table_list->mdl_request.init(MDL_key::TABLE,
|
||||
table_list->db, table_list->table_name,
|
||||
MDL_EXCLUSIVE, MDL_TRANSACTION);
|
||||
|
@ -127,9 +123,8 @@ static int prepare_for_repair(THD *thd, TABLE_LIST *table_list,
|
|||
DBUG_RETURN(0);
|
||||
has_mdl_lock= TRUE;
|
||||
|
||||
hash_value= my_calc_hash(&table_def_cache, (uchar*) key, key_length);
|
||||
share= get_table_share(thd, table_list, key, key_length,
|
||||
FRM_READ_TABLE_ONLY, ¬_used, hash_value);
|
||||
share= get_table_share(thd, table_list->db, table_list->table_name,
|
||||
FRM_READ_TABLE_ONLY, ¬_used);
|
||||
if (share == NULL)
|
||||
DBUG_RETURN(0); // Can't open frm file
|
||||
|
||||
|
|
|
@ -320,18 +320,18 @@ static void check_unused(THD *thd)
|
|||
Create a table cache key
|
||||
|
||||
SYNOPSIS
|
||||
create_table_def_key()
|
||||
create_tmp_table_def_key()
|
||||
thd Thread handler
|
||||
key Create key here (must be of size MAX_DBKEY_LENGTH)
|
||||
table_list Table definition
|
||||
tmp_table Set if table is a tmp table
|
||||
db Database name.
|
||||
table_name Table name.
|
||||
|
||||
IMPLEMENTATION
|
||||
The table cache_key is created from:
|
||||
db_name + \0
|
||||
table_name + \0
|
||||
|
||||
if the table is a tmp table, we add the following to make each tmp table
|
||||
additionally we add the following to make each tmp table
|
||||
unique on the slave:
|
||||
|
||||
4 bytes for master thread id
|
||||
|
@ -341,19 +341,13 @@ static void check_unused(THD *thd)
|
|||
Length of key
|
||||
*/
|
||||
|
||||
uint create_table_def_key(THD *thd, char *key,
|
||||
const TABLE_LIST *table_list,
|
||||
bool tmp_table)
|
||||
uint create_tmp_table_def_key(THD *thd, char *key,
|
||||
const char *db, const char *table_name)
|
||||
{
|
||||
uint key_length= create_table_def_key(key, table_list->db,
|
||||
table_list->table_name);
|
||||
|
||||
if (tmp_table)
|
||||
{
|
||||
int4store(key + key_length, thd->server_id);
|
||||
int4store(key + key_length + 4, thd->variables.pseudo_thread_id);
|
||||
key_length+= TMP_TABLE_KEY_EXTRA;
|
||||
}
|
||||
uint key_length= create_table_def_key(key, db, table_name);
|
||||
int4store(key + key_length, thd->server_id);
|
||||
int4store(key + key_length + 4, thd->variables.pseudo_thread_id);
|
||||
key_length+= TMP_TABLE_KEY_EXTRA;
|
||||
return key_length;
|
||||
}
|
||||
|
||||
|
@ -587,9 +581,9 @@ static void table_def_unuse_table(TABLE *table)
|
|||
# Share for table
|
||||
*/
|
||||
|
||||
TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
|
||||
uint key_length, enum read_frm_op op,
|
||||
enum open_frm_error *error,
|
||||
TABLE_SHARE *get_table_share(THD *thd, const char *db, const char *table_name,
|
||||
char *key, uint key_length,
|
||||
enum read_frm_op op, enum open_frm_error *error,
|
||||
my_hash_value_type hash_value)
|
||||
{
|
||||
bool open_failed;
|
||||
|
@ -604,9 +598,7 @@ TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
|
|||
To be able perform any operation on table we should own
|
||||
some kind of metadata lock on it.
|
||||
*/
|
||||
DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE,
|
||||
table_list->db,
|
||||
table_list->table_name,
|
||||
DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE, db, table_name,
|
||||
MDL_SHARED));
|
||||
|
||||
/* Read table definition from cache */
|
||||
|
@ -614,7 +606,7 @@ TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
|
|||
hash_value, (uchar*) key, key_length);
|
||||
if (!share)
|
||||
{
|
||||
if (!(share= alloc_table_share(table_list, key, key_length)))
|
||||
if (!(share= alloc_table_share(db, table_name, key, key_length)))
|
||||
goto err;
|
||||
|
||||
/*
|
||||
|
@ -2071,7 +2063,7 @@ TABLE *find_temporary_table(THD *thd, const char *db, const char *table_name)
|
|||
TABLE *find_temporary_table(THD *thd, const TABLE_LIST *tl)
|
||||
{
|
||||
char key[MAX_DBKEY_LENGTH];
|
||||
uint key_length= create_table_def_key(thd, key, tl, 1);
|
||||
uint key_length= create_tmp_table_def_key(thd, key, tl->db, tl->table_name);
|
||||
|
||||
return find_temporary_table(thd, key, key_length);
|
||||
}
|
||||
|
@ -2251,15 +2243,12 @@ bool rename_temporary_table(THD* thd, TABLE *table, const char *db,
|
|||
char *key;
|
||||
uint key_length;
|
||||
TABLE_SHARE *share= table->s;
|
||||
TABLE_LIST table_list;
|
||||
DBUG_ENTER("rename_temporary_table");
|
||||
|
||||
if (!(key=(char*) alloc_root(&share->mem_root, MAX_DBKEY_LENGTH)))
|
||||
DBUG_RETURN(1); /* purecov: inspected */
|
||||
|
||||
table_list.db= (char*) db;
|
||||
table_list.table_name= (char*) table_name;
|
||||
key_length= create_table_def_key(thd, key, &table_list, 1);
|
||||
key_length= create_tmp_table_def_key(thd, key, db, table_name);
|
||||
share->set_table_cache_key(key, key_length);
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
|
@ -2686,8 +2675,9 @@ bool open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
|
|||
if (thd->killed)
|
||||
DBUG_RETURN(TRUE);
|
||||
|
||||
key_length= (create_table_def_key(thd, key, table_list, 1) -
|
||||
TMP_TABLE_KEY_EXTRA);
|
||||
key_length= create_tmp_table_def_key(thd, key, table_list->db,
|
||||
table_list->table_name) -
|
||||
TMP_TABLE_KEY_EXTRA;
|
||||
|
||||
/*
|
||||
Unless requested otherwise, try to resolve this table in the list
|
||||
|
@ -2954,8 +2944,8 @@ bool open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
|
|||
|
||||
retry_share:
|
||||
|
||||
share= get_table_share(thd, table_list, key, key_length,
|
||||
read_op, &error, hash_value);
|
||||
share= get_table_share(thd, table_list->db, table_list->table_name,
|
||||
key, key_length, read_op, &error, hash_value);
|
||||
|
||||
if (!share)
|
||||
{
|
||||
|
@ -3779,13 +3769,11 @@ bool tdc_open_view(THD *thd, TABLE_LIST *table_list, const char *alias,
|
|||
{
|
||||
TABLE not_used;
|
||||
enum open_frm_error error;
|
||||
my_hash_value_type hash_value;
|
||||
TABLE_SHARE *share;
|
||||
|
||||
hash_value= my_calc_hash(&table_def_cache, (uchar*) cache_key,
|
||||
cache_key_length);
|
||||
if (!(share= get_table_share(thd, table_list, cache_key, cache_key_length,
|
||||
FRM_READ_VIEW_ONLY, &error, hash_value)))
|
||||
if (!(share= get_table_share(thd, table_list->db, table_list->table_name,
|
||||
cache_key, cache_key_length,
|
||||
FRM_READ_VIEW_ONLY, &error)))
|
||||
return TRUE;
|
||||
|
||||
DBUG_ASSERT(share->is_view);
|
||||
|
@ -3854,27 +3842,18 @@ static bool open_table_entry_fini(THD *thd, TABLE_SHARE *share, TABLE *entry)
|
|||
|
||||
static bool auto_repair_table(THD *thd, TABLE_LIST *table_list)
|
||||
{
|
||||
char cache_key[MAX_DBKEY_LENGTH];
|
||||
uint cache_key_length;
|
||||
TABLE_SHARE *share;
|
||||
TABLE *entry;
|
||||
enum open_frm_error not_used;
|
||||
bool result= TRUE;
|
||||
my_hash_value_type hash_value;
|
||||
|
||||
cache_key_length= create_table_def_key(thd, cache_key, table_list, 0);
|
||||
|
||||
thd->clear_error();
|
||||
|
||||
if (!(entry= (TABLE*)my_malloc(sizeof(TABLE), MYF(MY_WME))))
|
||||
return result;
|
||||
|
||||
hash_value= my_calc_hash(&table_def_cache, (uchar*) cache_key,
|
||||
cache_key_length);
|
||||
|
||||
if (!(share= get_table_share(thd, table_list, cache_key, cache_key_length,
|
||||
FRM_READ_TABLE_ONLY, ¬_used,
|
||||
hash_value)))
|
||||
if (!(share= get_table_share(thd, table_list->db, table_list->table_name,
|
||||
FRM_READ_TABLE_ONLY, ¬_used)))
|
||||
goto end_free;
|
||||
|
||||
DBUG_ASSERT(! share->is_view);
|
||||
|
@ -5995,7 +5974,6 @@ TABLE *open_table_uncached(THD *thd, const char *path, const char *db,
|
|||
TABLE_SHARE *share;
|
||||
char cache_key[MAX_DBKEY_LENGTH], *saved_cache_key, *tmp_path;
|
||||
uint key_length;
|
||||
TABLE_LIST table_list;
|
||||
DBUG_ENTER("open_table_uncached");
|
||||
DBUG_PRINT("enter",
|
||||
("table: '%s'.'%s' path: '%s' server_id: %u "
|
||||
|
@ -6003,10 +5981,8 @@ TABLE *open_table_uncached(THD *thd, const char *path, const char *db,
|
|||
db, table_name, path,
|
||||
(uint) thd->server_id, (ulong) thd->variables.pseudo_thread_id));
|
||||
|
||||
table_list.db= (char*) db;
|
||||
table_list.table_name= (char*) table_name;
|
||||
/* Create the cache_key for temporary tables */
|
||||
key_length= create_table_def_key(thd, cache_key, &table_list, 1);
|
||||
key_length= create_tmp_table_def_key(thd, cache_key, db, table_name);
|
||||
|
||||
if (!(tmp_table= (TABLE*) my_malloc(sizeof(*tmp_table) + sizeof(*share) +
|
||||
strlen(path)+1 + key_length,
|
||||
|
|
|
@ -69,6 +69,8 @@ enum enum_tdc_remove_table_type {TDC_RT_REMOVE_ALL, TDC_RT_REMOVE_NOT_OWN,
|
|||
#define RTFC_WAIT_OTHER_THREAD_FLAG 0x0002
|
||||
#define RTFC_CHECK_KILLED_FLAG 0x0004
|
||||
|
||||
extern HASH table_def_cache;
|
||||
|
||||
bool check_dup(const char *db, const char *name, TABLE_LIST *tables);
|
||||
extern mysql_mutex_t LOCK_open;
|
||||
bool table_cache_init(void);
|
||||
|
@ -79,9 +81,6 @@ void table_def_start_shutdown(void);
|
|||
void assign_new_table_id(TABLE_SHARE *share);
|
||||
uint cached_open_tables(void);
|
||||
uint cached_table_definitions(void);
|
||||
uint create_table_def_key(THD *thd, char *key,
|
||||
const TABLE_LIST *table_list,
|
||||
bool tmp_table);
|
||||
|
||||
/**
|
||||
Create a table cache key for non-temporary table.
|
||||
|
@ -107,12 +106,38 @@ create_table_def_key(char *key, const char *db, const char *table_name)
|
|||
NAME_LEN) - key + 1);
|
||||
}
|
||||
|
||||
TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
|
||||
uint key_length, enum read_frm_op op,
|
||||
uint create_tmp_table_def_key(THD *thd, char *key, const char *db,
|
||||
const char *table_name);
|
||||
TABLE_SHARE *get_table_share(THD *thd, const char *db, const char *table_name,
|
||||
char *key, uint key_length, enum read_frm_op op,
|
||||
enum open_frm_error *error,
|
||||
my_hash_value_type hash_value);
|
||||
void release_table_share(TABLE_SHARE *share);
|
||||
|
||||
|
||||
// convenience helper: call get_table_share() without precomputed hash_value
|
||||
static inline TABLE_SHARE *get_table_share(THD *thd, const char *db,
|
||||
const char *table_name,
|
||||
char *key, uint key_length,
|
||||
enum read_frm_op op,
|
||||
enum open_frm_error *error)
|
||||
{
|
||||
return get_table_share(thd, db, table_name, key, key_length, op, error,
|
||||
my_calc_hash(&table_def_cache, (uchar*) key, key_length));
|
||||
}
|
||||
|
||||
// convenience helper: call get_table_share() without precomputed cache key
|
||||
static inline TABLE_SHARE *get_table_share(THD *thd, const char *db,
|
||||
const char *table_name,
|
||||
enum read_frm_op op,
|
||||
enum open_frm_error *error)
|
||||
{
|
||||
char key[MAX_DBKEY_LENGTH];
|
||||
uint key_length;
|
||||
key_length= create_table_def_key(key, db, table_name);
|
||||
return get_table_share(thd, db, table_name, key, key_length, op, error);
|
||||
}
|
||||
|
||||
TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update,
|
||||
uint lock_flags);
|
||||
|
||||
|
@ -327,6 +352,17 @@ void tdc_remove_table(THD *thd, enum_tdc_remove_table_type remove_type,
|
|||
bool tdc_open_view(THD *thd, TABLE_LIST *table_list, const char *alias,
|
||||
char *cache_key, uint cache_key_length,
|
||||
MEM_ROOT *mem_root, uint flags);
|
||||
|
||||
static inline bool tdc_open_view(THD *thd, TABLE_LIST *table_list,
|
||||
const char *alias, MEM_ROOT *mem_root,
|
||||
uint flags)
|
||||
{
|
||||
char key[MAX_DBKEY_LENGTH];
|
||||
uint key_length;
|
||||
key_length= create_table_def_key(key, table_list->db, table_list->table_name);
|
||||
return tdc_open_view(thd, table_list, alias, key, key_length, mem_root, flags);
|
||||
}
|
||||
|
||||
void tdc_flush_unused_tables();
|
||||
TABLE *find_table_for_mdl_upgrade(THD *thd, const char *db,
|
||||
const char *table_name,
|
||||
|
@ -356,7 +392,6 @@ extern TABLE *unused_tables;
|
|||
extern Item **not_found_item;
|
||||
extern Field *not_found_field;
|
||||
extern Field *view_ref_found;
|
||||
extern HASH table_def_cache;
|
||||
|
||||
/**
|
||||
clean/setup table fields and map.
|
||||
|
|
|
@ -4308,9 +4308,6 @@ static int fill_schema_table_from_frm(THD *thd, TABLE_LIST *tables,
|
|||
TABLE_LIST table_list;
|
||||
uint res= 0;
|
||||
enum open_frm_error not_used;
|
||||
my_hash_value_type hash_value;
|
||||
char key[MAX_DBKEY_LENGTH];
|
||||
uint key_length;
|
||||
char db_name_buff[NAME_LEN + 1], table_name_buff[NAME_LEN + 1];
|
||||
|
||||
bzero((char*) &table_list, sizeof(TABLE_LIST));
|
||||
|
@ -4382,10 +4379,8 @@ static int fill_schema_table_from_frm(THD *thd, TABLE_LIST *tables,
|
|||
goto end;
|
||||
}
|
||||
|
||||
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_TABLE_OR_VIEW, ¬_used, hash_value);
|
||||
share= get_table_share(thd, table_list.db, table_list.table_name,
|
||||
FRM_READ_TABLE_OR_VIEW, ¬_used);
|
||||
if (!share)
|
||||
{
|
||||
res= 0;
|
||||
|
|
|
@ -211,16 +211,12 @@ static void make_valid_column_names(List<Item> &item_list)
|
|||
static bool
|
||||
fill_defined_view_parts (THD *thd, TABLE_LIST *view)
|
||||
{
|
||||
char key[MAX_DBKEY_LENGTH];
|
||||
uint key_length;
|
||||
LEX *lex= thd->lex;
|
||||
TABLE_LIST decoy;
|
||||
|
||||
memcpy (&decoy, view, sizeof (TABLE_LIST));
|
||||
key_length= create_table_def_key(thd, key, view, 0);
|
||||
|
||||
if (tdc_open_view(thd, &decoy, decoy.alias, key, key_length,
|
||||
thd->mem_root, OPEN_VIEW_NO_PARSE))
|
||||
if (tdc_open_view(thd, &decoy, decoy.alias, thd->mem_root,
|
||||
OPEN_VIEW_NO_PARSE))
|
||||
return TRUE;
|
||||
|
||||
if (!lex->definer)
|
||||
|
|
10
sql/table.cc
10
sql/table.cc
|
@ -285,8 +285,8 @@ TABLE_CATEGORY get_table_category(const LEX_STRING *db, const LEX_STRING *name)
|
|||
# Share
|
||||
*/
|
||||
|
||||
TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key,
|
||||
uint key_length)
|
||||
TABLE_SHARE *alloc_table_share(const char *db, const char *table_name,
|
||||
char *key, uint key_length)
|
||||
{
|
||||
MEM_ROOT mem_root;
|
||||
TABLE_SHARE *share;
|
||||
|
@ -294,12 +294,10 @@ TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key,
|
|||
char path[FN_REFLEN];
|
||||
uint path_length;
|
||||
DBUG_ENTER("alloc_table_share");
|
||||
DBUG_PRINT("enter", ("table: '%s'.'%s'",
|
||||
table_list->db, table_list->table_name));
|
||||
DBUG_PRINT("enter", ("table: '%s'.'%s'", db, table_name));
|
||||
|
||||
path_length= build_table_filename(path, sizeof(path) - 1,
|
||||
table_list->db,
|
||||
table_list->table_name, "", 0);
|
||||
db, table_name, "", 0);
|
||||
init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0, MYF(0));
|
||||
if (multi_alloc_root(&mem_root,
|
||||
&share, sizeof(*share),
|
||||
|
|
|
@ -1624,7 +1624,7 @@ struct TABLE_LIST
|
|||
|
||||
/**
|
||||
Prepare TABLE_LIST that consists of one table instance to use in
|
||||
simple_open_and_lock_tables
|
||||
open_and_lock_tables
|
||||
*/
|
||||
inline void init_one_table(const char *db_name_arg,
|
||||
size_t db_length_arg,
|
||||
|
@ -2464,8 +2464,8 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share,
|
|||
bool unpack_vcol_info_from_frm(THD *thd, MEM_ROOT *mem_root,
|
||||
TABLE *table, Field *field,
|
||||
LEX_STRING *vcol_expr, bool *error_reported);
|
||||
TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key,
|
||||
uint key_length);
|
||||
TABLE_SHARE *alloc_table_share(const char *db, const char *table_name,
|
||||
char *key, uint key_length);
|
||||
void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key,
|
||||
uint key_length,
|
||||
const char *table_name, const char *path);
|
||||
|
|
Loading…
Reference in a new issue