summaryrefslogtreecommitdiff
path: root/sql/sql_handler.cc
diff options
context:
space:
mode:
authorNirbhay Choubey <nirbhay@mariadb.com>2016-06-10 16:19:59 -0400
committerNirbhay Choubey <nirbhay@mariadb.com>2016-06-10 18:39:43 -0400
commit7305be2f7e724e5e62961606794beab199d79045 (patch)
tree403bd132ee82a16946e3208f5d535de6e5945b80 /sql/sql_handler.cc
parent547511153fb1f59688752aa5524ae411b5960c92 (diff)
downloadmariadb-git-7305be2f7e724e5e62961606794beab199d79045.tar.gz
MDEV-5535: Cannot reopen temporary table
mysqld maintains a list of TABLE objects for all temporary tables created within a session in THD. Here each table is represented by a TABLE object. A query referencing a particular temporary table for more than once, however, failed with ER_CANT_REOPEN_TABLE error because a TABLE_SHARE was allocate together with the TABLE, so temporary tables always had only one TABLE per TABLE_SHARE. This patch lift this restriction by separating TABLE and TABLE_SHARE objects and storing TABLE_SHAREs for temporary tables in a list in THD, and TABLEs in a list within their respective TABLE_SHAREs.
Diffstat (limited to 'sql/sql_handler.cc')
-rw-r--r--sql/sql_handler.cc14
1 files changed, 6 insertions, 8 deletions
diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc
index e8ade81062b..95417c73c74 100644
--- a/sql/sql_handler.cc
+++ b/sql/sql_handler.cc
@@ -1,5 +1,5 @@
/* Copyright (c) 2001, 2015, Oracle and/or its affiliates.
- Copyright (c) 2011, 2015, MariaDB
+ Copyright (c) 2011, 2016, MariaDB Corporation
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -178,9 +178,8 @@ static void mysql_ha_close_table(SQL_HANDLER *handler)
{
/* Must be a temporary table */
table->file->ha_index_or_rnd_end();
- table->query_id= thd->query_id;
table->open_by_handler= 0;
- mark_tmp_table_for_reuse(table);
+ thd->mark_tmp_table_as_free_for_reuse(table);
}
my_free(handler->lock);
handler->init();
@@ -294,7 +293,7 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, SQL_HANDLER *reopen)
open_ltable() or open_table() because we would like to be able
to open a temporary table.
*/
- error= (open_temporary_tables(thd, tables) ||
+ error= (thd->open_temporary_tables(tables) ||
open_tables(thd, &tables, &counter, 0));
if (error)
@@ -389,8 +388,7 @@ bool mysql_ha_open(THD *thd, TABLE_LIST *tables, SQL_HANDLER *reopen)
/*
Assert that the above check prevents opening of views and merge tables.
For temporary tables, TABLE::next can be set even if only one table
- was opened for HANDLER as it is used to link them together
- (see thd->temporary_tables).
+ was opened for HANDLER as it is used to link them together.
*/
DBUG_ASSERT(sql_handler->table->next == NULL ||
sql_handler->table->s->tmp_table);
@@ -1195,10 +1193,10 @@ void mysql_ha_set_explicit_lock_duration(THD *thd)
Remove temporary tables from the HANDLER's hash table. The reason
for having a separate function, rather than calling
mysql_ha_rm_tables() is that it is not always feasible (e.g. in
- close_temporary_tables) to obtain a TABLE_LIST containing the
+ THD::close_temporary_tables) to obtain a TABLE_LIST containing the
temporary tables.
- @See close_temporary_tables
+ @See THD::close_temporary_tables()
@param thd Thread identifier.
*/
void mysql_ha_rm_temporary_tables(THD *thd)