From 7305be2f7e724e5e62961606794beab199d79045 Mon Sep 17 00:00:00 2001 From: Nirbhay Choubey Date: Fri, 10 Jun 2016 16:19:59 -0400 Subject: 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. --- sql/sql_insert.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'sql/sql_insert.cc') diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 9f63216af88..13ff5a74b0b 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -4078,7 +4078,12 @@ static TABLE *create_table_from_items(THD *thd, } else { - if (open_temporary_table(thd, create_table)) + /* + The pointer to the newly created temporary table has been stored in + table->create_info. + */ + create_table->table= create_info->table; + if (!create_table->table) { /* This shouldn't happen as creation of temporary table should make @@ -4087,7 +4092,6 @@ static TABLE *create_table_from_items(THD *thd, */ DBUG_ASSERT(0); } - DBUG_ASSERT(create_table->table == create_info->table); } } else @@ -4461,6 +4465,7 @@ void select_create::abort_result_set() if (table) { bool tmp_table= table->s->tmp_table; + table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY); table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE); table->auto_increment_field_not_null= FALSE; -- cgit v1.2.1