1
by brian
clean slate |
1 |
# mysqltest should be fixed |
2 |
-- source include/not_embedded.inc
|
|
3 |
#
|
|
4 |
# Test of temporary tables |
|
5 |
#
|
|
6 |
||
7 |
--disable_warnings
|
|
8 |
drop table if exists t1,t2; |
|
9 |
drop view if exists v1; |
|
10 |
--enable_warnings
|
|
11 |
||
12 |
CREATE TABLE t1 (c int not null, d char (10) not null); |
|
13 |
insert into t1 values(1,""),(2,"a"),(3,"b"); |
|
14 |
CREATE TEMPORARY TABLE t1 (a int not null, b char (10) not null); |
|
15 |
insert into t1 values(4,"e"),(5,"f"),(6,"g"); |
|
16 |
alter table t1 rename t2; |
|
17 |
select * from t1; |
|
18 |
select * from t2; |
|
19 |
CREATE TABLE t2 (x int not null, y int not null); |
|
20 |
alter table t2 rename t1; |
|
21 |
select * from t1; |
|
22 |
create TEMPORARY TABLE t2 engine=heap select * from t1; |
|
23 |
create TEMPORARY TABLE IF NOT EXISTS t2 (a int) engine=heap; |
|
24 |
||
25 |
# This should give errors |
|
26 |
--error 1050
|
|
27 |
CREATE TEMPORARY TABLE t1 (a int not null, b char (10) not null); |
|
28 |
--error 1050
|
|
29 |
ALTER TABLE t1 RENAME t2; |
|
30 |
||
31 |
select * from t2; |
|
32 |
alter table t2 add primary key (a,b); |
|
33 |
drop table t1,t2; |
|
34 |
select * from t1; |
|
35 |
drop table t2; |
|
36 |
create temporary table t1 select *,2 as "e" from t1; |
|
37 |
select * from t1; |
|
38 |
drop table t1; |
|
39 |
drop table t1; |
|
40 |
||
41 |
#
|
|
42 |
# Test CONCAT_WS with temporary tables |
|
43 |
#
|
|
44 |
||
45 |
CREATE TABLE t1 (pkCrash INTEGER PRIMARY KEY,strCrash VARCHAR(255)); |
|
46 |
INSERT INTO t1 ( pkCrash, strCrash ) VALUES ( 1, '1'); |
|
47 |
SELECT CONCAT_WS(pkCrash, strCrash) FROM t1; |
|
48 |
drop table t1; |
|
49 |
create temporary table t1 select 1 as 'x'; |
|
50 |
drop table t1; |
|
51 |
CREATE TABLE t1 (x INT); |
|
52 |
INSERT INTO t1 VALUES (1), (2), (3); |
|
53 |
CREATE TEMPORARY TABLE tmp SELECT *, NULL FROM t1; |
|
54 |
drop table t1; |
|
55 |
||
56 |
#
|
|
57 |
# Problem with ELT |
|
58 |
#
|
|
59 |
create temporary table t1 (id int(10) not null unique); |
|
60 |
create temporary table t2 (id int(10) not null primary key, |
|
61 |
val int(10) not null); |
|
62 |
||
63 |
# put in some initial values |
|
64 |
insert into t1 values (1),(2),(4); |
|
65 |
insert into t2 values (1,1),(2,1),(3,1),(4,2); |
|
66 |
||
67 |
# do a query using ELT, a join and an ORDER BY. |
|
68 |
select one.id, two.val, elt(two.val,'one','two') from t1 one, t2 two where two.id=one.id order by one.id; |
|
69 |
drop table t1,t2; |
|
70 |
||
71 |
#
|
|
72 |
# Test of failed ALTER TABLE on temporary table |
|
73 |
#
|
|
74 |
create temporary table t1 (a int not null); |
|
75 |
insert into t1 values (1),(1); |
|
76 |
-- error ER_DUP_ENTRY
|
|
77 |
alter table t1 add primary key (a); |
|
78 |
drop table t1; |
|
79 |
||
80 |
#
|
|
81 |
# In MySQL 4.0.4 doing a GROUP BY on a NULL column created a disk based |
|
82 |
# temporary table when a memory based one would be good enough. |
|
83 |
||
84 |
CREATE TABLE t1 ( |
|
85 |
d datetime default NULL |
|
86 |
) ENGINE=MyISAM; |
|
87 |
||
88 |
||
89 |
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'); |
|
90 |
||
91 |
flush status; |
|
92 |
select * from t1 group by d; |
|
93 |
show status like "created_tmp%tables"; |
|
94 |
drop table t1; |
|
95 |
||
96 |
# Fix for BUG#8921: Check that temporary table is ingored by view commands. |
|
97 |
create temporary table v1 as select 'This is temp. table' A; |
|
98 |
create view v1 as select 'This is view' A; |
|
99 |
select * from v1; |
|
100 |
show create table v1; |
|
101 |
show create view v1; |
|
102 |
drop view v1; |
|
103 |
select * from v1; |
|
104 |
create view v1 as select 'This is view again' A; |
|
105 |
select * from v1; |
|
106 |
drop table v1; |
|
107 |
select * from v1; |
|
108 |
drop view v1; |
|
109 |
||
110 |
# Bug #8497: tmpdir with extra slashes would cause failures |
|
111 |
#
|
|
112 |
create table t1 (a int, b int, index(a), index(b)); |
|
113 |
create table t2 (c int auto_increment, d varchar(255), primary key (c)); |
|
114 |
insert into t1 values (3,1),(3,2); |
|
115 |
insert into t2 values (NULL, 'foo'), (NULL, 'bar'); |
|
116 |
select d, c from t1 left join t2 on b = c where a = 3 order by d; |
|
117 |
drop table t1, t2; |
|
118 |
||
119 |
||
120 |
#
|
|
121 |
# BUG#21096: locking issue ; temporary table conflicts. |
|
122 |
#
|
|
123 |
# The problem was that on DROP TEMPORARY table name lock was acquired, |
|
124 |
# which should not be done. |
|
125 |
#
|
|
126 |
--disable_warnings
|
|
127 |
DROP TABLE IF EXISTS t1; |
|
128 |
--enable_warnings
|
|
129 |
||
130 |
CREATE TABLE t1 (i INT); |
|
131 |
||
132 |
LOCK TABLE t1 WRITE; |
|
133 |
||
134 |
connect (conn1, localhost, root,,); |
|
135 |
||
136 |
CREATE TEMPORARY TABLE t1 (i INT); |
|
137 |
||
138 |
--echo The following command should not block
|
|
139 |
DROP TEMPORARY TABLE t1; |
|
140 |
||
141 |
disconnect conn1; |
|
142 |
connection default; |
|
143 |
||
144 |
DROP TABLE t1; |
|
145 |
||
146 |
#
|
|
147 |
# Check that it's not possible to drop a base table with |
|
148 |
# DROP TEMPORARY statement.
|
|
149 |
#
|
|
150 |
CREATE TABLE t1 (i INT);
|
|
151 |
CREATE TEMPORARY TABLE t2 (i INT);
|
|
152 |
||
153 |
--error 1051
|
|
154 |
DROP TEMPORARY TABLE t2, t1;
|
|
155 |
||
156 |
# Table t2 should have been dropped.
|
|
157 |
--error 1146
|
|
158 |
SELECT * FROM t2;
|
|
159 |
# But table t1 should still be there.
|
|
160 |
SELECT * FROM t1;
|
|
161 |
||
162 |
DROP TABLE t1;
|
|
163 |
||
164 |
||
165 |
--echo End of 4.1 tests.
|
|
166 |
||
167 |
#
|
|
168 |
# Bug #24791: Union with AVG-groups generates wrong results
|
|
169 |
#
|
|
170 |
CREATE TABLE t1 ( c FLOAT( 20, 14 ) );
|
|
171 |
INSERT INTO t1 VALUES( 12139 );
|
|
172 |
||
173 |
CREATE TABLE t2 ( c FLOAT(30,18) );
|
|
174 |
INSERT INTO t2 VALUES( 123456 );
|
|
175 |
||
176 |
SELECT AVG( c ) FROM t1 UNION SELECT 1;
|
|
177 |
SELECT 1 UNION SELECT AVG( c ) FROM t1;
|
|
178 |
SELECT 1 UNION SELECT * FROM t2 UNION SELECT 1;
|
|
179 |
SELECT c/1 FROM t1 UNION SELECT 1;
|
|
180 |
||
181 |
DROP TABLE t1, t2;
|
|
182 |
||
183 |
#
|
|
184 |
# Test truncate with temporary tables
|
|
185 |
#
|
|
186 |
||
187 |
create temporary table t1 (a int);
|
|
188 |
insert into t1 values (4711);
|
|
189 |
select * from t1;
|
|
190 |
truncate t1;
|
|
191 |
insert into t1 values (42);
|
|
192 |
select * from t1;
|
|
193 |
drop table t1;
|
|
194 |
||
195 |
#
|
|
196 |
# Bug #35392: Delete all statement does not execute properly after
|
|
197 |
# few delete statements
|
|
198 |
#
|
|
199 |
CREATE TEMPORARY TABLE t1(a INT, b VARCHAR(20));
|
|
200 |
INSERT INTO t1 VALUES(1, 'val1'), (2, 'val2'), (3, 'val3'); |
|
201 |
DELETE FROM t1 WHERE a=1; |
|
202 |
SELECT count(*) FROM t1; |
|
203 |
DELETE FROM t1; |
|
204 |
SELECT * FROM t1; |
|
205 |
DROP TABLE t1; |
|
206 |
||
207 |
--echo End of 5.1 tests
|