Commit b2ae32aa authored by Nirbhay Choubey's avatar Nirbhay Choubey

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.
parent e2087c6e
......@@ -151,5 +151,18 @@ SELECT COUNT(*) FROM t4;
COUNT(*)
4
DROP TABLE t4;
CREATE TABLE t5 (a INT) ENGINE=INNODB;
CREATE TEMPORARY TABLE t6 (a INT) ENGINE=INNODB;
INSERT INTO t5 VALUES(1), (2);
INSERT INTO t6 SELECT * FROM t5;
INSERT INTO t6 SELECT * FROM t6;
INSERT INTO t5 SELECT * FROM t6;
SELECT COUNT(*)=6 FROM t5;
COUNT(*)=6
1
SELECT COUNT(*)=4 FROM t6;
COUNT(*)=4
1
DROP TABLE t5, t6;
# Cleanup
DROP DATABASE temp_db;
......@@ -149,5 +149,15 @@ INSERT INTO t4 SELECT * FROM t4;
SELECT COUNT(*) FROM t4;
DROP TABLE t4;
CREATE TABLE t5 (a INT) ENGINE=INNODB;
CREATE TEMPORARY TABLE t6 (a INT) ENGINE=INNODB;
INSERT INTO t5 VALUES(1), (2);
INSERT INTO t6 SELECT * FROM t5;
INSERT INTO t6 SELECT * FROM t6;
INSERT INTO t5 SELECT * FROM t6;
SELECT COUNT(*)=6 FROM t5;
SELECT COUNT(*)=4 FROM t6;
DROP TABLE t5, t6;
--echo # Cleanup
DROP DATABASE temp_db;
......@@ -910,8 +910,7 @@ TABLE_LIST *find_table_in_list(TABLE_LIST *table,
{
for (; table; table= table->*link )
{
if ((table->table == 0 || table->table->s->tmp_table == NO_TMP_TABLE) &&
strcmp(table->db, db_name) == 0 &&
if (strcmp(table->db, db_name) == 0 &&
strcmp(table->table_name, table_name) == 0)
break;
}
......@@ -976,9 +975,6 @@ TABLE_LIST* find_dup_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list,
/* All MyISAMMRG children are plain MyISAM tables. */
DBUG_ASSERT(table->table->file->ht->db_type != DB_TYPE_MRG_MYISAM);
/* temporary table is always unique */
if (table->table && table->table->s->tmp_table != NO_TMP_TABLE)
DBUG_RETURN(0);
table= table->find_underlying_table(table->table);
/*
as far as we have table->table we have to find real TABLE_LIST of
......
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