Commit d2159e37 authored by Alexander Nozdrin's avatar Alexander Nozdrin

Bug#27480 (Extend CREATE TEMPORARY TABLES privilege

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

Rename open_temporary_table() to open_table_uncached().
open_temporary_table() will be introduced in following patches
to open temporary tables for a statement.
parent 53e566a4
...@@ -5696,35 +5696,37 @@ void close_tables_for_reopen(THD *thd, TABLE_LIST **tables, ...@@ -5696,35 +5696,37 @@ void close_tables_for_reopen(THD *thd, TABLE_LIST **tables,
} }
/* /**
Open a single table without table caching and don't set it in open_list Open a single table without table caching and don't add it to
THD::open_tables. Depending on the 'add_to_temporary_tables_list' value,
SYNPOSIS the opened TABLE instance will be addded to THD::temporary_tables list.
open_temporary_table()
thd Thread object @param thd Thread context.
path Path (without .frm) @param path Path (without .frm)
db database @param db Database name.
table_name Table name @param table_name Table name.
link_in_list 1 if table should be linked into thd->temporary_tables @param add_to_temporary_tables_list Specifies if the opened TABLE
instance should be linked into
NOTES: THD::temporary_tables list.
Used by alter_table to open a temporary table and when creating
a temporary table with CREATE TEMPORARY ... @note This function is used:
- by alter_table() to open a temporary table;
RETURN - when creating a temporary table with CREATE TEMPORARY TABLE.
0 Error
# TABLE object @return TABLE instance for opened table.
@retval NULL on error.
*/ */
TABLE *open_temporary_table(THD *thd, const char *path, const char *db, TABLE *open_table_uncached(THD *thd, const char *path, const char *db,
const char *table_name, bool link_in_list) const char *table_name,
bool add_to_temporary_tables_list)
{ {
TABLE *tmp_table; TABLE *tmp_table;
TABLE_SHARE *share; TABLE_SHARE *share;
char cache_key[MAX_DBKEY_LENGTH], *saved_cache_key, *tmp_path; char cache_key[MAX_DBKEY_LENGTH], *saved_cache_key, *tmp_path;
uint key_length; uint key_length;
TABLE_LIST table_list; TABLE_LIST table_list;
DBUG_ENTER("open_temporary_table"); DBUG_ENTER("open_table_uncached");
DBUG_PRINT("enter", DBUG_PRINT("enter",
("table: '%s'.'%s' path: '%s' server_id: %u " ("table: '%s'.'%s' path: '%s' server_id: %u "
"pseudo_thread_id: %lu", "pseudo_thread_id: %lu",
...@@ -5767,7 +5769,7 @@ TABLE *open_temporary_table(THD *thd, const char *path, const char *db, ...@@ -5767,7 +5769,7 @@ TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
share->tmp_table= (tmp_table->file->has_transactions() ? share->tmp_table= (tmp_table->file->has_transactions() ?
TRANSACTIONAL_TMP_TABLE : NON_TRANSACTIONAL_TMP_TABLE); TRANSACTIONAL_TMP_TABLE : NON_TRANSACTIONAL_TMP_TABLE);
if (link_in_list) if (add_to_temporary_tables_list)
{ {
/* growing temp list at the head */ /* growing temp list at the head */
tmp_table->next= thd->temporary_tables; tmp_table->next= thd->temporary_tables;
......
...@@ -141,8 +141,9 @@ bool open_new_frm(THD *thd, TABLE_SHARE *share, const char *alias, ...@@ -141,8 +141,9 @@ bool open_new_frm(THD *thd, TABLE_SHARE *share, const char *alias,
bool get_key_map_from_key_list(key_map *map, TABLE *table, bool get_key_map_from_key_list(key_map *map, TABLE *table,
List<String> *index_list); List<String> *index_list);
TABLE *open_temporary_table(THD *thd, const char *path, const char *db, TABLE *open_table_uncached(THD *thd, const char *path, const char *db,
const char *table_name, bool link_in_list); const char *table_name,
bool add_to_temporary_tables_list);
TABLE *find_locked_table(TABLE *list, const char *db, const char *table_name); TABLE *find_locked_table(TABLE *list, const char *db, const char *table_name);
TABLE *find_write_locked_table(TABLE *list, const char *db, TABLE *find_write_locked_table(TABLE *list, const char *db,
const char *table_name); const char *table_name);
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include "sql_rename.h" // do_rename #include "sql_rename.h" // do_rename
#include "sql_parse.h" // test_if_data_home_dir #include "sql_parse.h" // test_if_data_home_dir
#include "sql_cache.h" // query_cache_* #include "sql_cache.h" // query_cache_*
#include "sql_base.h" // open_temporary_table, lock_table_names #include "sql_base.h" // open_table_uncached, lock_table_names
#include "lock.h" // wait_if_global_read_lock #include "lock.h" // wait_if_global_read_lock
// start_waiting_global_read_lock, // start_waiting_global_read_lock,
// mysql_unlock_tables // mysql_unlock_tables
...@@ -4224,9 +4224,14 @@ bool mysql_create_table_no_lock(THD *thd, ...@@ -4224,9 +4224,14 @@ bool mysql_create_table_no_lock(THD *thd,
if (create_info->options & HA_LEX_CREATE_TMP_TABLE) if (create_info->options & HA_LEX_CREATE_TMP_TABLE)
{ {
TABLE *table= NULL; /*
/* Open table and put in temporary table list */ Open a table (skipping table cache) and add it into
if (!(table= open_temporary_table(thd, path, db, table_name, 1))) THD::temporary_tables list.
*/
TABLE *table= open_table_uncached(thd, path, db, table_name, TRUE);
if (!table)
{ {
(void) rm_temporary_table(create_info->db_type, path); (void) rm_temporary_table(create_info->db_type, path);
goto err; goto err;
...@@ -6301,8 +6306,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, ...@@ -6301,8 +6306,8 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
/* table is a normal table: Create temporary table in same directory */ /* table is a normal table: Create temporary table in same directory */
build_table_filename(path, sizeof(path) - 1, new_db, tmp_name, "", build_table_filename(path, sizeof(path) - 1, new_db, tmp_name, "",
FN_IS_TMP); FN_IS_TMP);
/* Open our intermediate table */ /* Open our intermediate table. */
new_table= open_temporary_table(thd, path, new_db, tmp_name, 1); new_table= open_table_uncached(thd, path, new_db, tmp_name, TRUE);
} }
if (!new_table) if (!new_table)
goto err_new_table_cleanup; goto err_new_table_cleanup;
...@@ -6642,7 +6647,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, ...@@ -6642,7 +6647,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
char path[FN_REFLEN]; char path[FN_REFLEN];
TABLE *t_table; TABLE *t_table;
build_table_filename(path + 1, sizeof(path) - 1, new_db, table_name, "", 0); build_table_filename(path + 1, sizeof(path) - 1, new_db, table_name, "", 0);
t_table= open_temporary_table(thd, path, new_db, tmp_name, 0); t_table= open_table_uncached(thd, path, new_db, tmp_name, FALSE);
if (t_table) if (t_table)
{ {
intern_close_table(t_table); intern_close_table(t_table);
......
...@@ -208,8 +208,8 @@ static bool recreate_temporary_table(THD *thd, TABLE *table) ...@@ -208,8 +208,8 @@ static bool recreate_temporary_table(THD *thd, TABLE *table)
ha_create_table(thd, share->normalized_path.str, share->db.str, ha_create_table(thd, share->normalized_path.str, share->db.str,
share->table_name.str, &create_info, 1); share->table_name.str, &create_info, 1);
if (open_temporary_table(thd, share->path.str, share->db.str, if (open_table_uncached(thd, share->path.str, share->db.str,
share->table_name.str, 1)) share->table_name.str, TRUE))
{ {
error= FALSE; error= FALSE;
thd->thread_specific_used= TRUE; thd->thread_specific_used= TRUE;
......
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