Commit cc0925f5 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 587f776c
......@@ -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
SYNPOSIS
open_temporary_table()
thd Thread object
path Path (without .frm)
db database
table_name Table name
link_in_list 1 if table should be linked into thd->temporary_tables
NOTES:
Used by alter_table to open a temporary table and when creating
a temporary table with CREATE TEMPORARY ...
RETURN
0 Error
# TABLE object
/**
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,
the opened TABLE instance will be addded to THD::temporary_tables list.
@param thd Thread context.
@param path Path (without .frm)
@param db Database name.
@param table_name Table name.
@param add_to_temporary_tables_list Specifies if the opened TABLE
instance should be linked into
THD::temporary_tables list.
@note This function is used:
- by alter_table() to open a temporary table;
- when creating a temporary table with CREATE TEMPORARY TABLE.
@return TABLE instance for opened table.
@retval NULL on error.
*/
TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
const char *table_name, bool link_in_list)
TABLE *open_table_uncached(THD *thd, const char *path, const char *db,
const char *table_name,
bool add_to_temporary_tables_list)
{
TABLE *tmp_table;
TABLE_SHARE *share;
char cache_key[MAX_DBKEY_LENGTH], *saved_cache_key, *tmp_path;
uint key_length;
TABLE_LIST table_list;
DBUG_ENTER("open_temporary_table");
DBUG_ENTER("open_table_uncached");
DBUG_PRINT("enter",
("table: '%s'.'%s' path: '%s' server_id: %u "
"pseudo_thread_id: %lu",
......@@ -5767,7 +5769,7 @@ TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
share->tmp_table= (tmp_table->file->has_transactions() ?
TRANSACTIONAL_TMP_TABLE : NON_TRANSACTIONAL_TMP_TABLE);
if (link_in_list)
if (add_to_temporary_tables_list)
{
/* growing temp list at the head */
tmp_table->next= thd->temporary_tables;
......
......@@ -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,
List<String> *index_list);
TABLE *open_temporary_table(THD *thd, const char *path, const char *db,
const char *table_name, bool link_in_list);
TABLE *open_table_uncached(THD *thd, const char *path, const char *db,
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_write_locked_table(TABLE *list, const char *db,
const char *table_name);
......
......@@ -22,7 +22,7 @@
#include "sql_rename.h" // do_rename
#include "sql_parse.h" // test_if_data_home_dir
#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
// start_waiting_global_read_lock,
// mysql_unlock_tables
......@@ -4224,9 +4224,14 @@ bool mysql_create_table_no_lock(THD *thd,
if (create_info->options & HA_LEX_CREATE_TMP_TABLE)
{
TABLE *table= NULL;
/* Open table and put in temporary table list */
if (!(table= open_temporary_table(thd, path, db, table_name, 1)))
/*
Open a table (skipping table cache) and add it into
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);
goto err;
......@@ -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 */
build_table_filename(path, sizeof(path) - 1, new_db, tmp_name, "",
FN_IS_TMP);
/* Open our intermediate table */
new_table= open_temporary_table(thd, path, new_db, tmp_name, 1);
/* Open our intermediate table. */
new_table= open_table_uncached(thd, path, new_db, tmp_name, TRUE);
}
if (!new_table)
goto err_new_table_cleanup;
......@@ -6642,7 +6647,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
char path[FN_REFLEN];
TABLE *t_table;
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)
{
intern_close_table(t_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,
share->table_name.str, &create_info, 1);
if (open_temporary_table(thd, share->path.str, share->db.str,
share->table_name.str, 1))
if (open_table_uncached(thd, share->path.str, share->db.str,
share->table_name.str, TRUE))
{
error= FALSE;
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