Commit 2e462c8f authored by Alexander Nozdrin's avatar Alexander Nozdrin

Bug#27480 (Extend CREATE TEMPORARY TABLES privilege

to allow temp table operations) -- prerequisite patch #2.

Introduce a new form of find_temporary_table() function:
find_temporary_table() by a table key. It will be used
in further patches.

Replace find_temporary_table(table_list->db, table_list->name)
by more appropiate find_temporary_table(table_list) across
the codebase.
parent a92ca267
......@@ -247,7 +247,8 @@ static void check_unused(void)
Length of key
*/
uint create_table_def_key(THD *thd, char *key, TABLE_LIST *table_list,
uint create_table_def_key(THD *thd, char *key,
const TABLE_LIST *table_list,
bool tmp_table)
{
uint key_length= (uint) (strmov(strmov(key, table_list->db)+1,
......@@ -1987,39 +1988,60 @@ void update_non_unique_table_error(TABLE_LIST *update,
}
/**
Find temporary table specified by database and table names in the
THD::temporary_tables list.
@return TABLE instance if a temporary table has been found; NULL otherwise.
*/
TABLE *find_temporary_table(THD *thd, const char *db, const char *table_name)
{
TABLE_LIST table_list;
TABLE_LIST tl;
table_list.db= (char*) db;
table_list.table_name= (char*) table_name;
return find_temporary_table(thd, &table_list);
tl.db= (char*) db;
tl.table_name= (char*) table_name;
return find_temporary_table(thd, &tl);
}
TABLE *find_temporary_table(THD *thd, TABLE_LIST *table_list)
/**
Find a temporary table specified by TABLE_LIST instance in the
THD::temporary_tables list.
@return TABLE instance if a temporary table has been found; NULL otherwise.
*/
TABLE *find_temporary_table(THD *thd, const TABLE_LIST *tl)
{
char key[MAX_DBKEY_LENGTH];
uint key_length;
TABLE *table;
DBUG_ENTER("find_temporary_table");
DBUG_PRINT("enter", ("table: '%s'.'%s'",
table_list->db, table_list->table_name));
uint key_length= create_table_def_key(thd, key, tl, 1);
key_length= create_table_def_key(thd, key, table_list, 1);
for (table=thd->temporary_tables ; table ; table= table->next)
return find_temporary_table(thd, key, key_length);
}
/**
Find a temporary table specified by a key in the THD::temporary_tables list.
@return TABLE instance if a temporary table has been found; NULL otherwise.
*/
TABLE *find_temporary_table(THD *thd,
const char *table_key,
uint table_key_length)
{
for (TABLE *table= thd->temporary_tables; table; table= table->next)
{
if (table->s->table_cache_key.length == key_length &&
!memcmp(table->s->table_cache_key.str, key, key_length))
if (table->s->table_cache_key.length == table_key_length &&
!memcmp(table->s->table_cache_key.str, table_key, table_key_length))
{
DBUG_PRINT("info",
("Found table. server_id: %u pseudo_thread_id: %lu",
(uint) thd->server_id,
(ulong) thd->variables.pseudo_thread_id));
DBUG_RETURN(table);
return table;
}
}
DBUG_RETURN(0); // Not a temporary table
return NULL;
}
......
......@@ -79,7 +79,8 @@ 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, TABLE_LIST *table_list,
uint create_table_def_key(THD *thd, char *key,
const TABLE_LIST *table_list,
bool tmp_table);
TABLE_SHARE *get_table_share(THD *thd, TABLE_LIST *table_list, char *key,
uint key_length, uint db_flags, int *error,
......@@ -159,7 +160,9 @@ TABLE_LIST *find_table_in_list(TABLE_LIST *table,
const char *db_name,
const char *table_name);
TABLE *find_temporary_table(THD *thd, const char *db, const char *table_name);
TABLE *find_temporary_table(THD *thd, TABLE_LIST *table_list);
TABLE *find_temporary_table(THD *thd, const TABLE_LIST *tl);
TABLE *find_temporary_table(THD *thd, const char *table_key,
uint table_key_length);
void close_thread_tables(THD *thd);
bool fill_record_n_invoke_before_triggers(THD *thd, List<Item> &fields,
List<Item> &values,
......
......@@ -177,8 +177,7 @@ static bool some_non_temp_table_to_be_updated(THD *thd, TABLE_LIST *tables)
for (TABLE_LIST *table= tables; table; table= table->next_global)
{
DBUG_ASSERT(table->db && table->table_name);
if (table->updating &&
!find_temporary_table(thd, table->db, table->table_name))
if (table->updating && !find_temporary_table(thd, table))
return 1;
}
return 0;
......
......@@ -2008,7 +2008,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
{
for (table= tables; table; table= table->next_local)
if (table->open_type != OT_BASE_ONLY &&
find_temporary_table(thd, table->db, table->table_name))
find_temporary_table(thd, table))
{
/*
A temporary table.
......
......@@ -458,7 +458,7 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
DBUG_ASSERT(tables->next_global == 0);
/* We do not allow creation of triggers on temporary tables. */
if (create && find_temporary_table(thd, tables->db, tables->table_name))
if (create && find_temporary_table(thd, tables))
{
my_error(ER_TRG_ON_VIEW_OR_TEMP_TABLE, MYF(0), tables->alias);
goto end;
......
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