summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbhay Choubey <nirbhay@mariadb.com>2016-06-09 17:24:45 -0400
committerNirbhay Choubey <nirbhay@mariadb.com>2016-06-09 17:24:45 -0400
commitcac2504adb0d1c2894a2e9d15d0dc469068d58eb (patch)
tree4e5176d413f199162956729d3026edc47fc0a2f0
parent8bb332df682f9feaf3d48c2ea93e47052f6479f5 (diff)
downloadmariadb-git-bb-10.2-mdev-5535.tar.gz
MDEV-5535: Cannot reopen temporary tablebb-10.2-mdev-5535
Addendum: 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.
-rw-r--r--mysql-test/r/reopen_temp_table.result13
-rw-r--r--mysql-test/t/reopen_temp_table.test10
-rw-r--r--sql/sql_base.cc6
3 files changed, 24 insertions, 5 deletions
diff --git a/mysql-test/r/reopen_temp_table.result b/mysql-test/r/reopen_temp_table.result
index 6d85703a999..08affaaaac5 100644
--- a/mysql-test/r/reopen_temp_table.result
+++ b/mysql-test/r/reopen_temp_table.result
@@ -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;
diff --git a/mysql-test/t/reopen_temp_table.test b/mysql-test/t/reopen_temp_table.test
index 1daca0322f7..98de983777d 100644
--- a/mysql-test/t/reopen_temp_table.test
+++ b/mysql-test/t/reopen_temp_table.test
@@ -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;
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 663d8e83fab..432a3788f3a 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -972,8 +972,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;
}
@@ -1038,9 +1037,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