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