~drizzle-trunk/drizzle/development

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