diff options
author | Nirbhay Choubey <nirbhay@mariadb.com> | 2016-06-10 14:54:24 -0400 |
---|---|---|
committer | Nirbhay Choubey <nirbhay@mariadb.com> | 2016-06-10 18:00:23 -0400 |
commit | 547511153fb1f59688752aa5524ae411b5960c92 (patch) | |
tree | e5021ac4805ed7fb0cf5d33a345f5b1535a8f7e7 | |
parent | 78d4276788e2ebad73c2a39e46675ef30dc322a8 (diff) | |
download | mariadb-git-547511153fb1f59688752aa5524ae411b5960c92.tar.gz |
MDEV-5535: Cannot reopen temporary table
Add generic temporary table related tests.
-rw-r--r-- | mysql-test/r/temp_table.result | 181 | ||||
-rw-r--r-- | mysql-test/t/temp_table.test | 202 |
2 files changed, 382 insertions, 1 deletions
diff --git a/mysql-test/r/temp_table.result b/mysql-test/r/temp_table.result index c674113e909..63a9743ef7b 100644 --- a/mysql-test/r/temp_table.result +++ b/mysql-test/r/temp_table.result @@ -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; diff --git a/mysql-test/t/temp_table.test b/mysql-test/t/temp_table.test index 987fbf7e848..2ae995446d6 100644 --- a/mysql-test/t/temp_table.test +++ b/mysql-test/t/temp_table.test @@ -1,5 +1,6 @@ # mysqltest should be fixed --- source include/not_embedded.inc +--source include/not_embedded.inc +--source include/have_innodb.inc # # Test of temporary tables @@ -338,3 +339,202 @@ drop table t2; drop temporary table t3; show status like 'com_create%table'; show status like 'com_drop%table'; + +--echo # +--echo # Some more generic temporary table tests +--echo # added during MDEV-5535. +--echo # + +--disable_warnings +DROP DATABASE IF EXISTS temp_db; +--enable_warnings + +CREATE DATABASE temp_db; +USE temp_db; + +--echo # +--echo # SHOW TABLES do not list temporary tables. +--echo # + +CREATE TEMPORARY TABLE temp_t1(i INT) ENGINE=INNODB; +INSERT INTO temp_t1 VALUES(1); +SELECT * FROM temp_t1; +SHOW TABLES; +DROP TABLE temp_t1; + +--echo # +--echo # Create and drop a temporary table. +--echo # + +CREATE TEMPORARY TABLE temp_t1(i INT) ENGINE=INNODB; +INSERT INTO temp_t1 VALUES(1); +SELECT * FROM temp_t1; +DROP TABLE temp_t1; +--error ER_NO_SUCH_TABLE +SELECT * FROM temp_t1; + +--echo # +--echo # Create a temporary table and base table with same name and DROP TABLE. +--echo # + +CREATE TABLE t1(c1 VARCHAR(20)) ENGINE=INNODB; +INSERT INTO t1 VALUES("BASE TABLE"); +# Temporary table shadows the base table with the same name. +CREATE TEMPORARY TABLE t1(c1 VARCHAR(20)) ENGINE=INNODB; +INSERT INTO t1 VALUES("TEMPORARY TABLE"); +SELECT * FROM t1; +# Only temporary table should get dropped. +DROP TABLE t1; +SELECT * FROM t1; +DROP TABLE t1; +--error ER_NO_SUCH_TABLE +SELECT * FROM t1; + +--echo # +--echo # Create a temporary table and base table with same name and DROP TEMPORARY +--echo # TABLE. +--echo # + +CREATE TABLE t1(c1 VARCHAR(20)) ENGINE=INNODB; +INSERT INTO t1 VALUES("BASE TABLE"); +# Temporary table shadows the base table with the same name. +CREATE TEMPORARY TABLE t1(c1 VARCHAR(20)) ENGINE=INNODB; +INSERT INTO t1 VALUES("TEMPORARY TABLE"); +SELECT * FROM t1; +# Only temporary table should get dropped. +DROP TEMPORARY TABLE t1; +SELECT * FROM t1; +--error ER_BAD_TABLE_ERROR +DROP TEMPORARY TABLE t1; +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # Create a temporary table and drop its parent database. +--echo # + +USE temp_db; +CREATE TEMPORARY TABLE temp_t1(i INT) ENGINE=INNODB; +INSERT INTO temp_t1 VALUES (1); +# Drop database +DROP DATABASE temp_db; +CREATE DATABASE temp_db; +USE temp_db; +# Temporary tables are not physically tied to schemas +DROP TEMPORARY TABLE temp_t1; + +--echo # +--echo # Similar to above, but this time with a base table with same name. +--echo # + +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 +DROP DATABASE temp_db; +CREATE DATABASE temp_db; +USE temp_db; +# Temporary tables are not physically tied to schemas +DROP TEMPORARY TABLE t1; +--error ER_BAD_TABLE_ERROR +DROP TABLE t1; + +--echo # +--echo # Create a temporary table within a function. +--echo # + +USE temp_db; +delimiter |; +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| +delimiter ;| + +SELECT f1(); +SELECT * FROM temp_t1; + +DROP TABLE temp_t1; +CREATE TEMPORARY TABLE `temp_t1`(i INT) ENGINE=INNODB; +SELECT f1(); +SELECT * FROM temp_t1; +DROP FUNCTION f1; + +--echo # +--echo # Create and drop a temporary table within a function. +--echo # + +delimiter |; +--error ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG +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| + +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| +delimiter ;| +SELECT f2(); +DROP FUNCTION f2; + +--echo # +--echo # Create a temporary table within a function and select it from another +--echo # function. +--echo # + +delimiter |; +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)| +delimiter ;| + +SELECT f2(); +DROP TEMPORARY TABLE temp_t1; +DROP FUNCTION f2; + +--echo # +--echo # Create temporary table like base table. +--echo # + +CREATE TABLE t1(i INT) ENGINE=INNODB; +INSERT INTO t1 VALUES(1); +CREATE TEMPORARY TABLE temp_t1 LIKE t1; +SELECT * FROM temp_t1; +--error ER_NONUNIQ_TABLE +CREATE TEMPORARY TABLE t1 LIKE t1; +DROP TABLE temp_t1, t1; + +--echo # +--echo # Create temporary table as base table. +--echo # + +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; +DROP TABLE temp_t1, t1; + +--echo # Cleanup +DROP DATABASE temp_db; + |