2
# Test of temporary tables
6
drop table if exists t1,t2;
7
# we don't support views
8
#drop view if exists v1;
11
CREATE TABLE t1 (c int not null, d char (10) not null);
12
insert into t1 values(1,""),(2,"a"),(3,"b");
13
CREATE TEMPORARY TABLE t1 (a int not null, b char (10) not null);
14
insert into t1 values(4,"e"),(5,"f"),(6,"g");
15
alter table t1 rename t2;
18
CREATE TABLE t2 (x int not null, y int not null);
19
alter table t2 rename t1;
21
create TEMPORARY TABLE t2 engine=MEMORY select * from t1;
22
create TEMPORARY TABLE IF NOT EXISTS t2 (a int) engine=MEMORY;
24
# This should give errors
25
--error ER_TABLE_EXISTS_ERROR
26
CREATE TEMPORARY TABLE t1 (a int not null, b char (10) not null);
27
--error ER_TABLE_EXISTS_ERROR
28
ALTER TABLE t1 RENAME t2;
31
alter table t2 add primary key (a,b);
35
create temporary table t1 select *,2 as "e" from t1;
41
# Test CONCAT_WS with temporary tables
44
CREATE TABLE t1 (pkCrash INTEGER PRIMARY KEY,strCrash VARCHAR(255));
45
INSERT INTO t1 ( pkCrash, strCrash ) VALUES ( 1, '1');
46
SELECT CONCAT_WS(pkCrash, strCrash) FROM t1;
48
create temporary table t1 select 1 as 'x';
50
CREATE TABLE t1 (x INT);
51
INSERT INTO t1 VALUES (1), (2), (3);
52
CREATE TEMPORARY TABLE tmp SELECT *, NULL FROM t1;
58
create temporary table t1 (id int not null unique);
59
create temporary table t2 (id int not null primary key, val int not null);
61
# put in some initial values
62
insert into t1 values (1),(2),(4);
63
insert into t2 values (1,1),(2,1),(3,1),(4,2);
65
# do a query using ELT, a join and an ORDER BY.
66
select one.id, two.val, elt(two.val,'one','two') from t1 one, t2 two where two.id=one.id order by one.id;
70
# Test of failed ALTER TABLE on temporary table
72
create temporary table t1 (a int not null);
73
insert into t1 values (1),(1);
74
alter table t1 add primary key (a);
78
# In MySQL 4.0.4 doing a GROUP BY on a NULL column created a disk based
79
# temporary table when a memory based one would be good enough.
81
CREATE TEMPORARY TABLE t1 (
82
d datetime default NULL
86
INSERT INTO t1 VALUES ('2002-10-24 14:50:32'),('2002-10-24 14:50:33'),('2002-10-24 14:50:34'),('2002-10-24 14:50:34'),('2002-10-24 14:50:34'),('2002-10-24 14:50:35'),('2002-10-24 14:50:35'),('2002-10-24 14:50:35'),('2002-10-24 14:50:35'),('2002-10-24 14:50:36'),('2002-10-24 14:50:36'),('2002-10-24 14:50:36'),('2002-10-24 14:50:36'),('2002-10-24 14:50:37'),('2002-10-24 14:50:37'),('2002-10-24 14:50:37'),('2002-10-24 14:50:37'),('2002-10-24 14:50:38'),('2002-10-24 14:50:38'),('2002-10-24 14:50:38'),('2002-10-24 14:50:39'),('2002-10-24 14:50:39'),('2002-10-24 14:50:39'),('2002-10-24 14:50:39'),('2002-10-24 14:50:40'),('2002-10-24 14:50:40'),('2002-10-24 14:50:40');
89
select * from t1 group by d;
91
show status like "created_tmp%tables";
94
# Fix for BUG#8921: Check that temporary table is ingored by view commands.
95
# Commenting this out since we don't support views
96
#create temporary table v1 as select 'This is temp. table' A;
97
#create view v1 as select 'This is view' A;
99
#show create table v1;
100
#show create view v1;
103
#create view v1 as select 'This is view again' A;
109
# Bug #8497: tmpdir with extra slashes would cause failures
111
create table t1 (a int, b int, index(a), index(b));
112
create table t2 (c int auto_increment, d varchar(255), primary key (c));
113
insert into t1 values (3,1),(3,2);
114
insert into t2 values (NULL, 'foo'), (NULL, 'bar');
115
select d, c from t1 left join t2 on b = c where a = 3 order by d;
120
# Check that it's not possible to drop a base table with
121
# DROP TEMPORARY statement.
123
CREATE TABLE t1 (i INT);
124
CREATE TEMPORARY TABLE t2 (i INT);
126
--error ER_BAD_TABLE_ERROR
127
DROP TEMPORARY TABLE t2, t1;
129
# Table t2 should have been dropped.
130
--error ER_TABLE_UNKNOWN
132
# But table t1 should still be there.
138
--echo End of 4.1 tests.
141
# Bug #24791: Union with AVG-groups generates wrong results
143
CREATE TABLE t1 ( c FLOAT( 20, 14 ) );
144
INSERT INTO t1 VALUES( 12139 );
146
CREATE TABLE t2 ( c FLOAT(30,18) );
147
INSERT INTO t2 VALUES( 123456 );
149
SELECT AVG( c ) FROM t1 UNION SELECT 1;
150
SELECT 1 UNION SELECT AVG( c ) FROM t1;
151
SELECT 1 UNION SELECT * FROM t2 UNION SELECT 1;
152
SELECT c/1 FROM t1 UNION SELECT 1;
157
# Test truncate with temporary tables
160
create temporary table t1 (a int);
161
insert into t1 values (4711);
164
insert into t1 values (42);
169
# Bug #35392: Delete all statement does not execute properly after
170
# few delete statements
172
CREATE TEMPORARY TABLE t1(a INT, b VARCHAR(20));
173
INSERT INTO t1 VALUES(1, 'val1'), (2, 'val2'), (3, 'val3');
174
DELETE FROM t1 WHERE a=1;
175
SELECT count(*) FROM t1;
180
--echo End of 5.1 tests