-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Nirbhay Choubey
committed
Jun 10, 2016
1 parent
5475111
commit 7305be2
Showing
50 changed files
with
2,313 additions
and
1,258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
# | ||
# MDEV-5535: Cannot reopen temporary table | ||
# | ||
DROP DATABASE IF EXISTS temp_db; | ||
CREATE DATABASE temp_db; | ||
USE temp_db; | ||
# | ||
# Reopen temporary table | ||
# | ||
CREATE TEMPORARY TABLE t1(i int)ENGINE=INNODB; | ||
INSERT INTO t1 VALUES(1), (2); | ||
SELECT * FROM t1 a, t1 b; | ||
i i | ||
1 1 | ||
2 1 | ||
1 2 | ||
2 2 | ||
DROP TABLE t1; | ||
# | ||
# CREATE & Stored routines | ||
# | ||
CREATE TEMPORARY TABLE t3 AS SELECT 1 AS a; | ||
CREATE PROCEDURE p1() | ||
BEGIN | ||
DROP TEMPORARY TABLE t3; | ||
end| | ||
CREATE FUNCTION f3() RETURNS INT | ||
BEGIN | ||
CALL p1(); | ||
RETURN 1; | ||
END| | ||
PREPARE STMT FROM "SELECT f3() AS my_Column, a FROM t3"; | ||
EXECUTE STMT; | ||
ERROR HY000: Can't reopen table: 't3' | ||
DROP TABLE t3; | ||
DROP FUNCTION f3; | ||
DROP PROCEDURE p1; | ||
CREATE TEMPORARY TABLE t4 (i INT); | ||
INSERT INTO t4 VALUES(1), (2); | ||
CREATE FUNCTION f4() RETURNS INT | ||
BEGIN | ||
DROP TEMPORARY TABLE t4; | ||
RETURN 1; | ||
END| | ||
SELECT f4() FROM t4; | ||
ERROR HY000: Can't reopen table: 't4' | ||
SELECT * FROM t4; | ||
i | ||
1 | ||
2 | ||
DROP TABLE t4; | ||
DROP FUNCTION f4; | ||
CREATE TEMPORARY TABLE t5 AS SELECT 1 AS a; | ||
CREATE PROCEDURE p2() | ||
BEGIN | ||
DROP TEMPORARY TABLE t5; | ||
END| | ||
CREATE FUNCTION f5() RETURNS INT | ||
BEGIN | ||
CALL p2(); | ||
RETURN 1; | ||
END| | ||
SELECT f5() AS my_column, a FROM t5; | ||
ERROR HY000: Can't reopen table: 't5' | ||
DROP TABLE t5; | ||
DROP FUNCTION f5; | ||
DROP PROCEDURE p2; | ||
# | ||
# CTAS | ||
# | ||
CREATE TABLE t1(i INT); | ||
INSERT INTO t1 VALUES(1), (2); | ||
CREATE TEMPORARY TABLE t1 | ||
SELECT temp_1.i a, temp_2.i b FROM t1 AS temp_1, t1 AS temp_2; | ||
SELECT * FROM t1; | ||
a b | ||
1 1 | ||
2 1 | ||
1 2 | ||
2 2 | ||
DROP TABLE t1; | ||
SELECT * FROM t1; | ||
i | ||
1 | ||
2 | ||
DROP TABLE t1; | ||
# | ||
# HANDLER | ||
# | ||
CREATE TABLE t1 (a INT, KEY a(a)); | ||
INSERT INTO t1 (a) VALUES (1), (2), (3), (4), (5); | ||
CREATE TABLE t2 (a INT, KEY a (a)) SELECT * FROM t1; | ||
CREATE TEMPORARY TABLE t3 (a INT, KEY a (a)) SELECT * FROM t2; | ||
HANDLER t3 OPEN; | ||
SELECT * FROM t1; | ||
a | ||
1 | ||
2 | ||
3 | ||
4 | ||
5 | ||
LOCK TABLE t1 READ; | ||
HANDLER t3 OPEN; | ||
ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction | ||
UNLOCK TABLES; | ||
HANDLER t3 OPEN; | ||
ERROR 42000: Not unique table/alias: 't3' | ||
HANDLER t3 READ NEXT; | ||
a | ||
1 | ||
HANDLER t3 OPEN AS t3_1; | ||
HANDLER t3_1 READ NEXT; | ||
a | ||
1 | ||
HANDLER t3_1 READ NEXT; | ||
a | ||
2 | ||
HANDLER t3 CLOSE; | ||
HANDLER t3_1 CLOSE; | ||
DROP TEMPORARY TABLE t3; | ||
DROP TABLE t1, t2; | ||
# | ||
# INSERT-SELECT | ||
# | ||
CREATE TEMPORARY TABLE t4 (a INT) ENGINE=MYISAM; | ||
INSERT INTO t4 VALUES(1), (2); | ||
INSERT INTO t4 SELECT * FROM t4; | ||
SELECT COUNT(*) FROM t4; | ||
COUNT(*) | ||
4 | ||
DROP TABLE t4; | ||
# Cleanup | ||
DROP DATABASE temp_db; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.