mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-5535: Cannot reopen temporary table
Add generic temporary table related tests.
This commit is contained in:
@ -311,3 +311,184 @@ show status like 'com_drop%table';
|
||||
Variable_name Value
|
||||
Com_drop_table 2
|
||||
Com_drop_temporary_table 1
|
||||
#
|
||||
# Some more generic temporary table tests
|
||||
# added during MDEV-5535.
|
||||
#
|
||||
DROP DATABASE IF EXISTS temp_db;
|
||||
CREATE DATABASE temp_db;
|
||||
USE temp_db;
|
||||
#
|
||||
# SHOW TABLES do not list temporary tables.
|
||||
#
|
||||
CREATE TEMPORARY TABLE temp_t1(i INT) ENGINE=INNODB;
|
||||
INSERT INTO temp_t1 VALUES(1);
|
||||
SELECT * FROM temp_t1;
|
||||
i
|
||||
1
|
||||
SHOW TABLES;
|
||||
Tables_in_temp_db
|
||||
DROP TABLE temp_t1;
|
||||
#
|
||||
# Create and drop a temporary table.
|
||||
#
|
||||
CREATE TEMPORARY TABLE temp_t1(i INT) ENGINE=INNODB;
|
||||
INSERT INTO temp_t1 VALUES(1);
|
||||
SELECT * FROM temp_t1;
|
||||
i
|
||||
1
|
||||
DROP TABLE temp_t1;
|
||||
SELECT * FROM temp_t1;
|
||||
ERROR 42S02: Table 'temp_db.temp_t1' doesn't exist
|
||||
#
|
||||
# Create a temporary table and base table with same name and DROP TABLE.
|
||||
#
|
||||
CREATE TABLE t1(c1 VARCHAR(20)) ENGINE=INNODB;
|
||||
INSERT INTO t1 VALUES("BASE TABLE");
|
||||
CREATE TEMPORARY TABLE t1(c1 VARCHAR(20)) ENGINE=INNODB;
|
||||
INSERT INTO t1 VALUES("TEMPORARY TABLE");
|
||||
SELECT * FROM t1;
|
||||
c1
|
||||
TEMPORARY TABLE
|
||||
DROP TABLE t1;
|
||||
SELECT * FROM t1;
|
||||
c1
|
||||
BASE TABLE
|
||||
DROP TABLE t1;
|
||||
SELECT * FROM t1;
|
||||
ERROR 42S02: Table 'temp_db.t1' doesn't exist
|
||||
#
|
||||
# Create a temporary table and base table with same name and DROP TEMPORARY
|
||||
# TABLE.
|
||||
#
|
||||
CREATE TABLE t1(c1 VARCHAR(20)) ENGINE=INNODB;
|
||||
INSERT INTO t1 VALUES("BASE TABLE");
|
||||
CREATE TEMPORARY TABLE t1(c1 VARCHAR(20)) ENGINE=INNODB;
|
||||
INSERT INTO t1 VALUES("TEMPORARY TABLE");
|
||||
SELECT * FROM t1;
|
||||
c1
|
||||
TEMPORARY TABLE
|
||||
DROP TEMPORARY TABLE t1;
|
||||
SELECT * FROM t1;
|
||||
c1
|
||||
BASE TABLE
|
||||
DROP TEMPORARY TABLE t1;
|
||||
ERROR 42S02: Unknown table 'temp_db.t1'
|
||||
SELECT * FROM t1;
|
||||
c1
|
||||
BASE TABLE
|
||||
DROP TABLE t1;
|
||||
#
|
||||
# Create a temporary table and drop its parent database.
|
||||
#
|
||||
USE temp_db;
|
||||
CREATE TEMPORARY TABLE temp_t1(i INT) ENGINE=INNODB;
|
||||
INSERT INTO temp_t1 VALUES (1);
|
||||
DROP DATABASE temp_db;
|
||||
CREATE DATABASE temp_db;
|
||||
USE temp_db;
|
||||
DROP TEMPORARY TABLE temp_t1;
|
||||
#
|
||||
# Similar to above, but this time with a base table with same name.
|
||||
#
|
||||
USE temp_db;
|
||||
CREATE TABLE t1(i INT)ENGINE=INNODB;
|
||||
CREATE TEMPORARY TABLE t1(i INT) ENGINE=INNODB;
|
||||
INSERT INTO t1 VALUES (1);
|
||||
DROP DATABASE temp_db;
|
||||
CREATE DATABASE temp_db;
|
||||
USE temp_db;
|
||||
DROP TEMPORARY TABLE t1;
|
||||
DROP TABLE t1;
|
||||
ERROR 42S02: Unknown table 'temp_db.t1'
|
||||
#
|
||||
# Create a temporary table within a function.
|
||||
#
|
||||
USE temp_db;
|
||||
CREATE FUNCTION f1() RETURNS INT
|
||||
BEGIN
|
||||
DROP TEMPORARY TABLE IF EXISTS temp_t1;
|
||||
CREATE TEMPORARY TABLE temp_t1(i INT) ENGINE=INNODB;
|
||||
INSERT INTO `temp_t1` VALUES(1);
|
||||
RETURN (SELECT COUNT(*) FROM temp_t1);
|
||||
END|
|
||||
SELECT f1();
|
||||
f1()
|
||||
1
|
||||
SELECT * FROM temp_t1;
|
||||
i
|
||||
1
|
||||
DROP TABLE temp_t1;
|
||||
CREATE TEMPORARY TABLE `temp_t1`(i INT) ENGINE=INNODB;
|
||||
SELECT f1();
|
||||
f1()
|
||||
1
|
||||
SELECT * FROM temp_t1;
|
||||
i
|
||||
1
|
||||
DROP FUNCTION f1;
|
||||
#
|
||||
# Create and drop a temporary table within a function.
|
||||
#
|
||||
CREATE FUNCTION f2() RETURNS INT
|
||||
BEGIN
|
||||
DROP TEMPORARY TABLE IF EXISTS temp_t1;
|
||||
CREATE TEMPORARY TABLE temp_t1(i INT) ENGINE=INNODB;
|
||||
INSERT INTO temp_t1 VALUES(1);
|
||||
DROP TABLE temp_t1;
|
||||
RETURN 0;
|
||||
END|
|
||||
ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger.
|
||||
CREATE FUNCTION f2() RETURNS INT
|
||||
BEGIN
|
||||
DROP TEMPORARY TABLE IF EXISTS temp_t1;
|
||||
CREATE TEMPORARY TABLE temp_t1(i INT) ENGINE=INNODB;
|
||||
INSERT INTO temp_t1 VALUES(1);
|
||||
DROP TEMPORARY TABLE temp_t1;
|
||||
RETURN 0;
|
||||
END|
|
||||
SELECT f2();
|
||||
f2()
|
||||
0
|
||||
DROP FUNCTION f2;
|
||||
#
|
||||
# Create a temporary table within a function and select it from another
|
||||
# function.
|
||||
#
|
||||
CREATE FUNCTION f2() RETURNS INT
|
||||
BEGIN
|
||||
DROP TEMPORARY TABLE IF EXISTS temp_t1;
|
||||
CREATE TEMPORARY TABLE temp_t1 (i INT) ENGINE=INNODB;
|
||||
INSERT INTO temp_t1 VALUES (1);
|
||||
RETURN f2_1();
|
||||
END|
|
||||
CREATE FUNCTION f2_1() RETURNS INT
|
||||
RETURN (SELECT COUNT(*) FROM temp_t1)|
|
||||
SELECT f2();
|
||||
f2()
|
||||
1
|
||||
DROP TEMPORARY TABLE temp_t1;
|
||||
DROP FUNCTION f2;
|
||||
#
|
||||
# Create temporary table like base table.
|
||||
#
|
||||
CREATE TABLE t1(i INT) ENGINE=INNODB;
|
||||
INSERT INTO t1 VALUES(1);
|
||||
CREATE TEMPORARY TABLE temp_t1 LIKE t1;
|
||||
SELECT * FROM temp_t1;
|
||||
i
|
||||
CREATE TEMPORARY TABLE t1 LIKE t1;
|
||||
ERROR 42000: Not unique table/alias: 't1'
|
||||
DROP TABLE temp_t1, t1;
|
||||
#
|
||||
# Create temporary table as base table.
|
||||
#
|
||||
CREATE TABLE t1(i INT) ENGINE=INNODB;
|
||||
INSERT INTO t1 VALUES(1);
|
||||
CREATE TEMPORARY TABLE temp_t1 AS SELECT * FROM t1;
|
||||
SELECT * FROM temp_t1;
|
||||
i
|
||||
1
|
||||
DROP TABLE temp_t1, t1;
|
||||
# Cleanup
|
||||
DROP DATABASE temp_db;
|
||||
|
Reference in New Issue
Block a user