summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorAlexander Nozdrin <alik@sun.com>2010-08-31 14:03:36 +0400
committerAlexander Nozdrin <alik@sun.com>2010-08-31 14:03:36 +0400
commitcc0925f5d95c9b77336b3f9cd307d7bc2236247e (patch)
tree51c4727108df919fd2a982c76f2d8294ed1199fa /sql
parent587f776cfe8cf70771cf0923199a25de710df6c4 (diff)
downloadmariadb-git-cc0925f5d95c9b77336b3f9cd307d7bc2236247e.tar.gz
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.
Diffstat (limited to 'sql')
-rw-r--r--sql/sql_base.cc46
-rw-r--r--sql/sql_base.h5
-rw-r--r--sql/sql_table.cc19
-rw-r--r--sql/sql_truncate.cc4
4 files changed, 41 insertions, 33 deletions
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index feb63355353..8cd0ce4432a 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -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;
diff --git a/sql/sql_base.h b/sql/sql_base.h
index 56776bde1cc..a21850355b4 100644
--- a/sql/sql_base.h
+++ b/sql/sql_base.h
@@ -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);
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 06db813481d..9d8f59189d0 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -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);
diff --git a/sql/sql_truncate.cc b/sql/sql_truncate.cc
index a61abdafe3e..c0bc726a188 100644
--- a/sql/sql_truncate.cc
+++ b/sql/sql_truncate.cc
@@ -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;