Skip to content

Commit b2ae32a

Browse files
author
Nirbhay Choubey
committed
MDEV-5535: Cannot reopen temporary table
Since a query can now refer to the same temporary table multiple times, find_dup_table()/find_table_in_list() have been updated to also consider this new possibility.
1 parent e2087c6 commit b2ae32a

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

mysql-test/r/reopen_temp_table.result

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,18 @@ SELECT COUNT(*) FROM t4;
151151
COUNT(*)
152152
4
153153
DROP TABLE t4;
154+
CREATE TABLE t5 (a INT) ENGINE=INNODB;
155+
CREATE TEMPORARY TABLE t6 (a INT) ENGINE=INNODB;
156+
INSERT INTO t5 VALUES(1), (2);
157+
INSERT INTO t6 SELECT * FROM t5;
158+
INSERT INTO t6 SELECT * FROM t6;
159+
INSERT INTO t5 SELECT * FROM t6;
160+
SELECT COUNT(*)=6 FROM t5;
161+
COUNT(*)=6
162+
1
163+
SELECT COUNT(*)=4 FROM t6;
164+
COUNT(*)=4
165+
1
166+
DROP TABLE t5, t6;
154167
# Cleanup
155168
DROP DATABASE temp_db;

mysql-test/t/reopen_temp_table.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,15 @@ INSERT INTO t4 SELECT * FROM t4;
149149
SELECT COUNT(*) FROM t4;
150150
DROP TABLE t4;
151151

152+
CREATE TABLE t5 (a INT) ENGINE=INNODB;
153+
CREATE TEMPORARY TABLE t6 (a INT) ENGINE=INNODB;
154+
INSERT INTO t5 VALUES(1), (2);
155+
INSERT INTO t6 SELECT * FROM t5;
156+
INSERT INTO t6 SELECT * FROM t6;
157+
INSERT INTO t5 SELECT * FROM t6;
158+
SELECT COUNT(*)=6 FROM t5;
159+
SELECT COUNT(*)=4 FROM t6;
160+
DROP TABLE t5, t6;
161+
152162
--echo # Cleanup
153163
DROP DATABASE temp_db;

sql/sql_base.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -910,8 +910,7 @@ TABLE_LIST *find_table_in_list(TABLE_LIST *table,
910910
{
911911
for (; table; table= table->*link )
912912
{
913-
if ((table->table == 0 || table->table->s->tmp_table == NO_TMP_TABLE) &&
914-
strcmp(table->db, db_name) == 0 &&
913+
if (strcmp(table->db, db_name) == 0 &&
915914
strcmp(table->table_name, table_name) == 0)
916915
break;
917916
}
@@ -976,9 +975,6 @@ TABLE_LIST* find_dup_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list,
976975
/* All MyISAMMRG children are plain MyISAM tables. */
977976
DBUG_ASSERT(table->table->file->ht->db_type != DB_TYPE_MRG_MYISAM);
978977

979-
/* temporary table is always unique */
980-
if (table->table && table->table->s->tmp_table != NO_TMP_TABLE)
981-
DBUG_RETURN(0);
982978
table= table->find_underlying_table(table->table);
983979
/*
984980
as far as we have table->table we have to find real TABLE_LIST of

0 commit comments

Comments
 (0)