~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
#
2
# Test of unions
3
#
4
5
--disable_warnings
6
drop table if exists t1,t2,t3,t4,t5,t6;
7
--enable_warnings
8
9
CREATE TABLE t1 (a int not null, b char (10) not null);
10
insert into t1 values(1,'a'),(2,'b'),(3,'c'),(3,'c');
11
CREATE TABLE t2 (a int not null, b char (10) not null);
12
insert into t2 values (3,'c'),(4,'d'),(5,'f'),(6,'e');
13
14
select a,b from t1 union distinct select a,b from t2;
15
select a,b from t1 union all select a,b from t2;
16
select a,b from t1 union all select a,b from t2 order by b;
17
select a,b from t1 union all select a,b from t2 union select 7,'g';
18
select 0,'#' union select a,b from t1 union all select a,b from t2 union select 7,'gg';
19
select a,b from t1 union select a,b from t1;
20
select 't1',b,count(*) from t1 group by b UNION select 't2',b,count(*) from t2 group by b;
21
22
# Test alternate syntax for unions 
23
(select a,b from t1 limit 2)  union all (select a,b from t2 order by a) limit 4;
24
(select a,b from t1 limit 2)  union all (select a,b from t2 order by a limit 1);
25
(select a,b from t1 limit 2)  union all (select a,b from t2 order by a limit 1) order by b desc;
26
--error 1250
27
(select a,b from t1 limit 2)  union all (select a,b from t2 order by a limit 1) order by t1.b;
28
explain extended (select a,b from t1 limit 2)  union all (select a,b from t2 order by a limit 1) order by b desc;
29
(select sql_calc_found_rows  a,b from t1 limit 2)  union all (select a,b from t2 order by a) limit 2;
30
select found_rows();
31
select sql_calc_found_rows  a,b from t1  union all select a,b from t2 limit 2;
32
select found_rows();
33
34
#
35
# Test some error conditions with UNION
36
#
37
38
explain select a,b from t1 union all select a,b from t2;
39
40
--error  1054
41
explain select xx from t1 union select 1;
42
--error 1222
43
explain select a,b from t1 union select 1;
44
--error 1222
45
explain select 1 union select a,b from t1 union select 1;
46
--error 1222
47
explain select a,b from t1 union select 1 limit 0;
48
49
--error 1221
50
select a,b from t1 into outfile 'skr' union select a,b from t2;
51
52
--error 1221
53
select a,b from t1 order by a union select a,b from t2;
54
55
--error 1221
56
insert into t3 select a from t1 order by a union select a from t2;
57
58
--error 1222
59
create table t3 select a,b from t1 union select a from t2;
60
61
--error 1222
62
select a,b from t1 union select a from t2;
63
64
--error 1222
65
select * from t1 union select a from t2;
66
67
--error 1222
68
select a from t1 union select * from t2;
69
70
--error 1234
71
select * from t1 union select SQL_BUFFER_RESULT * from t2;
72
73
# Test CREATE, INSERT and REPLACE
74
create table t3 select a,b from t1 union all select a,b from t2;
75
insert into t3 select a,b from t1 union all select a,b from t2;
76
# PS can't handle REPLACE ... SELECT
77
replace into t3 select a,b as c from t1 union all select a,b from t2;
78
79
drop table t1,t2,t3;
80
81
#
82
# Test some unions without tables
83
#
84
--error 1096
85
select * union select 1;
86
select 1 as a,(select a union select a);
87
--error 1054
88
(select 1) union (select 2) order by 0;
89
SELECT @a:=1 UNION SELECT @a:=@a+1;
90
--error 1054
91
(SELECT 1) UNION (SELECT 2) ORDER BY (SELECT a);
92
(SELECT 1,3) UNION (SELECT 2,1) ORDER BY (SELECT 2);
93
94
#
95
# Test bug reported by joc@presence-pc.com
96
#
97
98
CREATE TABLE t1 (
99
  `pseudo` char(35) NOT NULL default '',
100
  `pseudo1` char(35) NOT NULL default '',
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
101
  `same` int NOT NULL default '1',
1 by brian
clean slate
102
  PRIMARY KEY  (`pseudo1`),
103
  KEY `pseudo` (`pseudo`)
104
) ENGINE=MyISAM;
105
INSERT INTO t1 (pseudo,pseudo1,same) VALUES ('joce', 'testtt', 1),('joce', 'tsestset', 1),('dekad', 'joce', 1);
106
SELECT pseudo FROM t1 WHERE pseudo1='joce' UNION SELECT pseudo FROM t1 WHERE pseudo='joce';
107
SELECT pseudo1 FROM t1 WHERE pseudo1='joce' UNION SELECT pseudo1 FROM t1 WHERE pseudo='joce';
108
SELECT * FROM t1 WHERE pseudo1='joce' UNION SELECT * FROM t1 WHERE pseudo='joce' order by pseudo desc,pseudo1 desc;
109
SELECT pseudo1 FROM t1 WHERE pseudo='joce' UNION SELECT pseudo FROM t1 WHERE pseudo1='joce';
110
SELECT pseudo1 FROM t1 WHERE pseudo='joce' UNION ALL SELECT pseudo FROM t1 WHERE pseudo1='joce';
111
SELECT pseudo1 FROM t1 WHERE pseudo='joce' UNION SELECT 1;
112
drop table t1;
113
114
create table t1 (a int);
115
create table t2 (a int);
116
insert into t1 values (1),(2),(3),(4),(5);
117
insert into t2 values (11),(12),(13),(14),(15);
118
(select * from t1 limit 2) union (select * from t2 limit 3) limit 4;
119
(select * from t1 limit 2) union (select * from t2 limit 3);
120
(select * from t1 limit 2) union (select * from t2 limit 20,3);
121
set SQL_SELECT_LIMIT=2;
122
(select * from t1 limit 1) union (select * from t2 limit 3);
123
set SQL_SELECT_LIMIT=DEFAULT;
124
drop table t1,t2;
125
126
#
127
# Test error with left join
128
#
129
130
CREATE TABLE t1 (
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
131
  cid int NOT NULL default '0',
132
  cv varchar(190) NOT NULL default '',
1 by brian
clean slate
133
  PRIMARY KEY  (cid),
134
  UNIQUE KEY cv (cv)
135
) ;
136
INSERT INTO t1 VALUES (8,'dummy');
137
CREATE TABLE t2 (
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
138
  cid int NOT NULL auto_increment,
1 by brian
clean slate
139
  cap varchar(255) NOT NULL default '',
140
  PRIMARY KEY  (cid),
141
  KEY cap (cap)
142
) ;
143
CREATE TABLE t3 (
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
144
  gid int NOT NULL auto_increment,
1 by brian
clean slate
145
  gn varchar(255) NOT NULL default '',
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
146
  must int default NULL,
1 by brian
clean slate
147
  PRIMARY KEY  (gid),
148
  KEY gn (gn)
149
) ;
150
INSERT INTO t3 VALUES (1,'V1',NULL);
151
CREATE TABLE t4 (
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
152
  uid bigint NOT NULL default '0',
153
  gid bigint default NULL,
154
  rid bigint default NULL,
155
  cid bigint default NULL,
1 by brian
clean slate
156
  UNIQUE KEY m (uid,gid,rid,cid),
157
  KEY uid (uid),
158
  KEY rid (rid),
159
  KEY cid (cid),
160
  KEY container (gid,rid,cid)
161
) ;
162
INSERT INTO t4 VALUES (1,1,NULL,NULL);
163
CREATE TABLE t5 (
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
164
  rid bigint NOT NULL auto_increment,
1 by brian
clean slate
165
  rl varchar(255) NOT NULL default '',
166
  PRIMARY KEY  (rid),
167
  KEY rl (rl)
168
) ;
169
CREATE TABLE t6 (
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
170
  uid bigint NOT NULL auto_increment,
171
  un varchar(190) NOT NULL default '',
172
  uc int NOT NULL default '0',
1 by brian
clean slate
173
  PRIMARY KEY  (uid),
174
  UNIQUE KEY nc (un,uc),
175
  KEY un (un)
176
) ;
177
INSERT INTO t6 VALUES (1,'test',8);
178
179
SELECT t4.uid, t5.rl, t3.gn as g1, t4.cid, t4.gid as gg FROM t3, t6, t1, t4 left join t5 on t5.rid = t4.rid left join t2 on t2.cid = t4.cid WHERE t3.gid=t4.gid AND t6.uid = t4.uid AND t6.uc  = t1.cid AND t1.cv = "dummy" AND t6.un = "test";
180
SELECT t4.uid, t5.rl, t3.gn as g1, t4.cid, t4.gid as gg FROM t3, t6, t1, t4 left join t5 on t5.rid = t4.rid left join t2 on t2.cid = t4.cid WHERE t3.gid=t4.gid AND t6.uid = t4.uid AND t3.must IS NOT NULL AND t6.uc  = t1.cid AND t1.cv = "dummy" AND t6.un = "test";
181
(SELECT t4.uid, t5.rl, t3.gn as g1, t4.cid, t4.gid as gg FROM t3, t6, t1, t4 left join t5 on t5.rid = t4.rid left join t2 on t2.cid = t4.cid WHERE t3.gid=t4.gid AND t6.uid = t4.uid AND t3.must IS NOT NULL AND t6.uc  = t1.cid AND t1.cv = "dummy" AND t6.un = "test") UNION (SELECT t4.uid, t5.rl, t3.gn as g1, t4.cid, t4.gid as gg FROM t3, t6, t1, t4 left join t5 on t5.rid = t4.rid left join t2 on t2.cid = t4.cid WHERE t3.gid=t4.gid AND t6.uid = t4.uid AND t6.uc  = t1.cid AND t1.cv = "dummy" AND t6.un = "test");
182
drop table t1,t2,t3,t4,t5,t6;
183
184
#
185
# Test insert ... SELECT with UNION
186
#
187
188
CREATE TABLE t1 (a int not null, b char (10) not null);
189
insert into t1 values(1,'a'),(2,'b'),(3,'c'),(3,'c');
190
CREATE TABLE t2 (a int not null, b char (10) not null);
191
insert into t2 values (3,'c'),(4,'d'),(5,'f'),(6,'e');
192
create table t3 select a,b from t1 union select a,b from t2;
193
create table t4 (select a,b from t1) union (select a,b from t2) limit 2;
194
insert into  t4 select a,b from t1 union select a,b from t2;
195
insert into  t3 (select a,b from t1) union (select a,b from t2) limit 2;
196
select * from t3;
197
select * from t4;
198
drop table t1,t2,t3,t4;
199
200
#
201
# Test of SQL_CALC_FOUND_ROW handling
202
#
203
create table t1 (a int);
204
insert into t1 values (1),(2),(3);
205
create table t2 (a int);
206
insert into t2 values (3),(4),(5);
207
208
# Test global limits
209
(SELECT SQL_CALC_FOUND_ROWS * FROM t1) UNION all (SELECT * FROM t2) LIMIT 1;
210
select found_rows();
211
(SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1) UNION all (SELECT * FROM t2) LIMIT 2;
212
select found_rows();
213
214
# Test cases where found_rows() should return number of returned rows
215
(SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1) UNION all (SELECT * FROM t2);
216
select found_rows();
217
(SELECT SQL_CALC_FOUND_ROWS * FROM t1) UNION all (SELECT * FROM t2 LIMIT 1);
218
select found_rows();
219
# This used to work in 4.0 but not anymore in 4.1
220
--error 1064
221
(SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1) UNION SELECT * FROM t2 LIMIT 1;
222
#select found_rows();
223
224
# In these case found_rows() should work
225
SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1 UNION all SELECT * FROM t2 LIMIT 2;
226
select found_rows();
227
SELECT SQL_CALC_FOUND_ROWS * FROM t1 UNION all SELECT * FROM t2 LIMIT 2;
228
select found_rows();
229
230
# The following examples will not be exact
231
SELECT SQL_CALC_FOUND_ROWS * FROM t1 UNION SELECT * FROM t2 LIMIT 2;
232
select found_rows();
233
SELECT SQL_CALC_FOUND_ROWS * FROM t1 UNION SELECT * FROM t2 LIMIT 100;
234
select found_rows();
235
SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 100 UNION SELECT * FROM t2;
236
select found_rows();
237
SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1 UNION SELECT * FROM t2;
238
select found_rows();
239
SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1 UNION SELECT * FROM t2 LIMIT 2;
240
select found_rows();
241
SELECT SQL_CALC_FOUND_ROWS * FROM t1 UNION SELECT * FROM t2 LIMIT 2,2;
242
select found_rows();
243
SELECT SQL_CALC_FOUND_ROWS * FROM t1 limit 2,2 UNION SELECT * FROM t2;
244
select found_rows();
245
246
# Test some limits with ORDER BY
247
SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a desc LIMIT 1;
248
(SELECT * FROM t1 ORDER by a) UNION ALL (SELECT * FROM t2 ORDER BY a) ORDER BY A desc LIMIT 4;
249
250
# Wrong usage
251
--error 1234
252
(SELECT * FROM t1) UNION all (SELECT SQL_CALC_FOUND_ROWS * FROM t2) LIMIT 1;
253
254
create temporary table t1 select a from t1 union select a from t2;
255
drop temporary table t1;
256
--error 1093
257
create table t1 select a from t1 union select a from t2;
258
--error 1054
259
select a from t1 union select a from t2 order by t2.a;
260
drop table t1,t2;
261
262
#
263
# Problem with alias '*' (BUG #1249)
264
#
265
266
select length(version()) > 1 as `*` UNION select 2;
267
268
#
269
# Bug #4980: problem with explain
270
#
271
272
create table t1 (a int);
273
insert into t1 values (0), (3), (1), (2);
274
explain (select * from t1) union (select * from t1) order by a;
275
drop table t1;
276
#
277
# Test for another bug with UNION and LEFT JOIN
278
#
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
279
CREATE TABLE t1 (  id int default '0') ENGINE=MyISAM;
1 by brian
clean slate
280
INSERT INTO t1 (id) VALUES("1");
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
281
CREATE TABLE t2 ( id int default '0',  id_master int default '0',  text1 varchar(5) default NULL,  text2 varchar(5) default NULL) ENGINE=MyISAM;
1 by brian
clean slate
282
INSERT INTO t2 (id, id_master, text1, text2) VALUES("1", "1",
283
"foo1", "bar1");
284
INSERT INTO t2 (id, id_master, text1, text2) VALUES("2", "1",
285
"foo2", "bar2");
286
INSERT INTO t2 (id, id_master, text1, text2) VALUES("3", "1", NULL,
287
"bar3");
288
INSERT INTO t2 (id, id_master, text1, text2) VALUES("4", "1",
289
"foo4", "bar4");
290
SELECT 1 AS id_master, 1 AS id, NULL AS text1, 'ABCDE' AS text2 UNION SELECT id_master, t2.id, text1, text2 FROM t1 LEFT JOIN t2 ON t1.id = t2.id_master;
291
SELECT 1 AS id_master, 1 AS id, 'ABCDE' AS text1, 'ABCDE' AS text2 UNION SELECT id_master, t2.id, text1, text2 FROM t1 LEFT JOIN t2 ON t1.id = t2.id_master;
292
drop table if exists t1,t2;
293
294
#
295
# Test of bug when using the same table multiple times
296
#
297
create table t1 (a int not null primary key auto_increment, b int, key(b));
298
create table t2 (a int not null primary key auto_increment, b int);
299
insert into t1 (b) values (1),(2),(2),(3);
300
insert into t2 (b) values (10),(11),(12),(13);
301
302
explain extended (select * from t1 where a=1) union (select * from t2 where a=1);
303
(select * from t1 where a=5) union (select * from t2 where a=1);
304
(select * from t1 where a=5 and a=6) union (select * from t2 where a=1);
305
(select t1.a,t1.b from t1,t2 where t1.a=5) union (select * from t2 where a=1);
306
(select * from t1 where a=1) union (select t1.a,t2.a from t1,t2 where t1.a=t2.a);
307
explain (select * from t1 where a=1 and b=10) union (select straight_join t1.a,t2.a from t1,t2 where t1.a=t2.a);
308
explain (select * from t1 where a=1) union (select * from t1 where b=1);
309
drop table t1,t2;
310
create table t1 (   id int not null auto_increment, primary key (id)   ,user_name text );
311
create table t2 (    id int not null auto_increment, primary key (id)   ,group_name text );
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
312
create table t3 (    id int not null auto_increment, primary key (id)   ,user_id int   ,index user_idx (user_id)   ,foreign key (user_id) references t1(id)   ,group_id int   ,index group_idx (group_id)   ,foreign key (group_id) references t2(id) );
1 by brian
clean slate
313
insert into t1 (user_name) values ('Tester');
314
insert into t2 (group_name) values ('Group A');
315
insert into t2 (group_name) values ('Group B');
316
insert into t3 (user_id, group_id) values (1,1);
317
select 1 'is_in_group', a.user_name, c.group_name, b.id from t1 a, t3 b, t2 c where a.id = b.user_id and b.group_id = c.id UNION  select 0 'is_in_group', a.user_name, c.group_name, null from t1 a, t2 c;
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
318
drop table t3, t1, t2;
1 by brian
clean slate
319
320
#
321
# fix_fields problem
322
#
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
323
create table t1 (mat_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, matintnum CHAR(6) NOT NULL, test INT NULL);
324
create table t2 (mat_id INT NOT NULL, pla_id INT NOT NULL);
1 by brian
clean slate
325
insert into t1 values (NULL, 'a', 1), (NULL, 'b', 2), (NULL, 'c', 3), (NULL, 'd', 4), (NULL, 'e', 5), (NULL, 'f', 6), (NULL, 'g', 7), (NULL, 'h', 8), (NULL, 'i', 9);
326
insert into t2 values (1, 100), (1, 101), (1, 102), (2, 100), (2, 103), (2, 104), (3, 101), (3, 102), (3, 105);
327
SELECT mp.pla_id, MIN(m1.matintnum) AS matintnum FROM t2 mp INNER JOIN t1 m1 ON mp.mat_id=m1.mat_id GROUP BY mp.pla_id union SELECT 0, 0;
328
drop table t1, t2;
329
330
#
331
# types conversions
332
#
333
create table t1 SELECT "a" as a UNION select "aa" as a;
334
select * from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
335
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
336
show create table t1;
337
drop table t1;
338
create table t1 SELECT 12 as a UNION select "aa" as a;
339
select * from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
340
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
341
show create table t1;
342
drop table t1;
343
create table t1 SELECT 12 as a UNION select 12.2 as a;
344
select * from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
345
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
346
show create table t1;
347
drop table t1;
348
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
349
create table t2 (it1 int, it2 int not null, i int not null, ib int, f float, d double, da date, dt datetime, sc char(10), sv varchar(10), b blob, tx text);
873.1.2 by Jay Pipes
Fixed Field_datetime to never accept any bad datetimes as a string. This broke
350
insert into t2 values (NULL, 1, 3, 4, 1.5, 2.5, '1972-10-22', '1972-10-22 11:50:00', 'testc', 'testv', 'tetetetetest', 'teeeeeeeeeeeest');
1 by brian
clean slate
351
352
create table t1 SELECT it2 from t2 UNION select it1 from t2;
353
select * from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
354
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
355
show create table t1;
356
drop table t1;
357
create table t1 SELECT it2 from t2 UNION select i from t2;
358
select * from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
359
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
360
show create table t1;
361
drop table t1;
362
create table t1 SELECT i from t2 UNION select f from t2;
363
select * from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
364
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
365
show create table t1;
366
drop table t1;
367
create table t1 SELECT f from t2 UNION select d from t2;
368
select * from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
369
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
370
show create table t1;
371
drop table t1;
372
create table t1 SELECT ib from t2 UNION select f from t2;
373
select * from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
374
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
375
show create table t1;
376
drop table t1;
377
create table t1 SELECT ib from t2 UNION select d from t2;
378
select * from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
379
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
380
show create table t1;
381
drop table t1;
382
create table t1 SELECT f from t2 UNION select da from t2;
383
select * from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
384
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
385
show create table t1;
386
drop table t1;
387
create table t1 SELECT da from t2 UNION select dt from t2;
388
select * from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
389
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
390
show create table t1;
391
drop table t1;
392
create table t1 SELECT dt from t2 UNION select trim(sc) from t2;
393
select trim(dt) from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
394
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
395
show create table t1;
396
drop table t1;
397
create table t1 SELECT dt from t2 UNION select sv from t2;
398
select * from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
399
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
400
show create table t1;
401
drop table t1;
402
create table t1 SELECT sc from t2 UNION select sv from t2;
403
select * from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
404
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
405
show create table t1;
406
drop table t1;
407
create table t1 SELECT dt from t2 UNION select b from t2;
408
select * from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
409
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
410
show create table t1;
411
drop table t1;
412
create table t1 SELECT sv from t2 UNION select b from t2;
413
select * from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
414
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
415
show create table t1;
416
drop table t1;
417
create table t1 SELECT i from t2 UNION select d from t2 UNION select b from t2;
418
select * from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
419
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
420
show create table t1;
421
drop table t1;
422
create table t1 SELECT sv from t2 UNION select tx from t2;
423
select * from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
424
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
425
show create table t1;
426
drop table t1;
427
create table t1 SELECT b from t2 UNION select tx from t2;
428
select * from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
429
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
430
show create table t1;
431
drop table t1,t2;
432
create table t1 select 1 union select -1;
433
select * from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
434
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
435
show create table t1;
436
drop table t1;
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
437
-- error 1054
438
create table t1 select _latin1"test" union select _latin1"testt" ;
779.3.10 by Monty Taylor
Turned on -Wshadow.
439
-- error 1054
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
440
create table t1 select _utf8"test" union select _utf8"testt" ;
779.3.10 by Monty Taylor
Turned on -Wshadow.
441
create table t1 select "test" union select "testt" ;
942.3.1 by Vladimir Kolesnikov
test generalizations
442
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
443
show create table t1;
444
drop table t1;
445
446
#
447
# conversion memory->disk table
448
#
449
create table t1 (s char(200));
450
insert into t1 values (repeat("1",200));
451
create table t2 select * from t1;
452
insert into t2 select * from t1;
453
insert into t1 select * from t2;
454
insert into t2 select * from t1;
455
insert into t1 select * from t2;
456
insert into t2 select * from t1;
457
set local tmp_table_size=1024;
458
select count(*) from (select * from t1 union all select * from t2 order by 1) b;
459
select count(*) from t1;
460
select count(*) from t2;
461
drop table t1,t2;
462
set local tmp_table_size=default;
463
464
#
465
# slow logging
466
#
467
create table t1 (a int, index (a), b int);
468
insert t1 values (1,1),(2,2),(3,3),(4,4),(5,5);
469
insert t1 select a+1, a+b from t1;
470
insert t1 select a+1, a+b from t1;
471
insert t1 select a+1, a+b from t1;
472
insert t1 select a+1, a+b from t1;
473
insert t1 select a+1, a+b from t1;
474
FLUSH STATUS;
475
show status like 'Slow_queries';
476
select count(*) from t1 where a=7;
477
show status like 'Slow_queries';
478
select count(*) from t1 where b=13;
479
show status like 'Slow_queries';
480
select count(*) from t1 where b=13 union select count(*) from t1 where a=7;
481
show status like 'Slow_queries';
482
select count(*) from t1 where a=7 union select count(*) from t1 where b=13;
483
show status like 'Slow_queries';
484
# additional test for examined rows
485
flush status;
486
select a from t1 where b not in (1,2,3) union select a from t1 where b not in (4,5,6); 
487
show status like 'Slow_queries';
488
drop table t1;
489
490
#
491
# Column 'name' cannot be null (error with union and left join) (bug #2508)
492
#
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
493
create table t1 (   RID int not null default '0',   IID int not null default '0',    nada varchar(50)  not null,NAME varchar(50) not null,PHONE varchar(50) not null) engine=MyISAM;
1 by brian
clean slate
494
insert into t1 ( RID,IID,nada,NAME,PHONE) values (1, 1, 'main', 'a', '111'), (2, 1, 'main', 'b', '222'), (3, 1, 'main', 'c', '333'), (4, 1, 'main', 'd', '444'), (5, 1, 'main', 'e', '555'), (6, 2, 'main', 'c', '333'), (7, 2, 'main', 'd', '454'), (8, 2, 'main', 'e', '555'), (9, 2, 'main', 'f', '666'), (10, 2, 'main', 'g', '777');
495
select A.NAME, A.PHONE, B.NAME, B.PHONE from t1 A left join t1 B on A.NAME = B.NAME and B.IID = 2 where A.IID = 1 and (A.PHONE <> B.PHONE or B.NAME is null) union select A.NAME, A.PHONE, B.NAME, B.PHONE from t1 B left join t1 A on B.NAME = A.NAME and A.IID = 1 where B.IID = 2 and (A.PHONE <> B.PHONE or A.NAME is null);
496
drop  table t1;
497
498
#
499
# Bug #2809 (UNION fails on MyIsam tables when index on second column from
500
# same table)
501
#
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
502
create table t1 (col1 int, col2 int);
1 by brian
clean slate
503
insert into t1 values (1,2),(3,4),(5,6),(7,8),(9,10);
504
select col1 n from t1 union select col2 n from t1 order by n;
505
alter table t1 add index myindex (col2);
506
select col1 n from t1 union select col2 n from t1 order by n;
507
drop  table t1;
508
509
#
510
# Incorrect handling of UNION ALL (Bug #1428)
511
#
512
create table t1 (i int);
513
insert into t1 values (1);
514
select * from t1 UNION select * from t1;
515
select * from t1 UNION ALL select * from t1;
516
select * from t1 UNION select * from t1 UNION ALL select * from t1;
517
drop table t1;
518
select 1 as a union all select 1 union all select 2 union select 1 union all select 2;
519
set sql_select_limit=1;
520
select 1 union select 2;
521
(select 1) union (select 2);
522
(select 1) union (select 2) union (select 3) limit 2;
523
set sql_select_limit=default;
524
525
#
526
# ORDER with LIMIT
527
#
528
create table t1 (a int);
529
insert into t1 values (100), (1);
530
create table t2 (a int);
531
insert into t2 values (100);
532
select a from t1 union select a from t2 order by a;
533
SET SQL_SELECT_LIMIT=1;
534
select a from t1 union select a from t2 order by a;
535
drop table t1, t2;
536
set sql_select_limit=default;
537
538
#
539
# nonexisting column in global ORDER BY
540
#
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
541
CREATE TABLE t1 (i int default NULL,c char(1) default NULL,KEY i (i));
542
CREATE TABLE t2 (i int default NULL,c char(1) default NULL,KEY i (i));
1 by brian
clean slate
543
--error 1054
544
explain (select * from t1) union (select * from t2) order by not_existing_column;
545
drop table t1, t2;
546
547
#
548
# length detecting
549
#
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
550
CREATE TABLE t1 (uid int);
1 by brian
clean slate
551
INSERT INTO t1 SELECT 150;
552
SELECT 'a' UNION SELECT uid FROM t1;
553
drop table t1;
554
555
#
556
# parser stack overflow
557
#
873.1.2 by Jay Pipes
Fixed Field_datetime to never accept any bad datetimes as a string. This broke
558
CREATE TABLE t1 ( ID1 int NOT NULL DEFAULT '0' , ID2 datetime, DATA1 varchar(10) , DATA2 double(5,4) , DATA3 datetime , PRIMARY KEY (ID1,ID2));
1 by brian
clean slate
559
907.1.7 by Jay Pipes
Merged in remove-timezone work
560
CREATE TABLE t2 ( ID int NOT NULL DEFAULT '0' , DATA1 timestamp NULL, PRIMARY KEY (ID));
1 by brian
clean slate
561
(SELECT * FROM t1 AS PARTITIONED, t2 AS
562
PARTITIONED_B WHERE PARTITIONED_B.ID=PARTITIONED.ID1) UNION
563
(SELECT * FROM t1 AS PARTITIONED, t2 AS
564
PARTITIONED_B WHERE PARTITIONED_B.ID=PARTITIONED.ID1) UNION
565
(SELECT * FROM t1 AS PARTITIONED, t2 AS
566
PARTITIONED_B WHERE PARTITIONED_B.ID=PARTITIONED.ID1) UNION
567
(SELECT * FROM t1 AS PARTITIONED, t2 AS
568
PARTITIONED_B WHERE PARTITIONED_B.ID=PARTITIONED.ID1) UNION
569
(SELECT * FROM t1 AS PARTITIONED, t2 AS
570
PARTITIONED_B WHERE PARTITIONED_B.ID=PARTITIONED.ID1) UNION
571
(SELECT * FROM t1 AS PARTITIONED, t2 AS
572
PARTITIONED_B WHERE PARTITIONED_B.ID=PARTITIONED.ID1) UNION
573
(SELECT * FROM t1 AS PARTITIONED, t2 AS
574
PARTITIONED_B WHERE PARTITIONED_B.ID=PARTITIONED.ID1) UNION
575
(SELECT * FROM t1 AS PARTITIONED, t2 AS
576
PARTITIONED_B WHERE PARTITIONED_B.ID=PARTITIONED.ID1) UNION
577
(SELECT * FROM t1 AS PARTITIONED, t2 AS
578
PARTITIONED_B WHERE PARTITIONED_B.ID=PARTITIONED.ID1) UNION
579
(SELECT * FROM t1 AS PARTITIONED, t2 AS
580
PARTITIONED_B WHERE PARTITIONED_B.ID=PARTITIONED.ID1) UNION
581
(SELECT * FROM t1 AS PARTITIONED, t2 AS
582
PARTITIONED_B WHERE PARTITIONED_B.ID=PARTITIONED.ID1) UNION
583
(SELECT * FROM t1 AS PARTITIONED, t2 AS
584
PARTITIONED_B WHERE PARTITIONED_B.ID=PARTITIONED.ID1);
585
drop table t1,t2;
586
587
#
588
# merging ENUM and SET fields in one UNION
589
#
590
create table t1 (a ENUM('Yes', 'No') NOT NULL);
591
create table t2 (a ENUM('aaa', 'bbb') NOT NULL);
592
insert into t1 values ('No');
593
insert into t2 values ('bbb');
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
594
create table t3 (a ENUM('Yes', 'No') NOT NULL);
595
create table t4 (a ENUM('aaa', 'bbb') NOT NULL);
1 by brian
clean slate
596
insert into t3 values (1);
934.4.1 by Jay Pipes
Fixes ENUM field type to throw an error on bad data input. 0 is now not
597
--error 1691 # Bad enum
1 by brian
clean slate
598
insert into t4 values (3);
599
select "1" as a union select a from t1;
600
select a as a from t1 union select "1";
601
select a as a from t2 union select a from t1;
602
select "1" as a union select a from t3;
603
select a as a from t3 union select "1";
604
select a as a from t4 union select a from t3;
605
select a as a from t1 union select a from t4;
606
drop table t1,t2,t3,t4;
607
608
#
609
# Bug #6139 UNION doesn't understand collate in the column of second select
610
#
611
create table t1 as
779.3.10 by Monty Taylor
Turned on -Wshadow.
612
(select 'test') union
613
(select 'TEST') union
614
(select 'TeST');
942.3.1 by Vladimir Kolesnikov
test generalizations
615
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
779.3.10 by Monty Taylor
Turned on -Wshadow.
616
show create table t1;
617
select count(*) from t1;
618
drop table t1;
619
620
create table t1 as
621
(select 'test' collate utf8_bin) union
622
(select 'TEST') union
623
(select 'TeST');
942.3.1 by Vladimir Kolesnikov
test generalizations
624
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
779.3.10 by Monty Taylor
Turned on -Wshadow.
625
show create table t1;
626
select count(*) from t1;
627
drop table t1;
628
629
create table t1 as
630
(select 'test') union
631
(select 'TEST' collate utf8_bin) union
632
(select 'TeST');
942.3.1 by Vladimir Kolesnikov
test generalizations
633
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
779.3.10 by Monty Taylor
Turned on -Wshadow.
634
show create table t1;
635
select count(*) from t1;
636
drop table t1;
637
638
create table t1 as
639
(select 'test') union
640
(select 'TEST') union
641
(select 'TeST' collate utf8_bin);
942.3.1 by Vladimir Kolesnikov
test generalizations
642
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
643
show create table t1;
644
select count(*) from t1;
645
drop table t1;
646
647
# Drizzle doesn't support specifying character set, it is all UTF8
648
--error 1064
649
create table t2 (
650
a char character set utf8 collate utf8_swedish_ci,
651
b char character set utf8 collate utf8_spanish_ci);
652
653
create table t2 (
654
a char collate utf8_swedish_ci,
655
b char collate utf8_spanish_ci);
1 by brian
clean slate
656
--error 1271
657
create table t1 as
658
(select a from t2) union
659
(select b from t2);
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
660
661
--error 1166
1 by brian
clean slate
662
create table t1 as
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
663
(select a collate utf8_swedish_ci from t2) union
1 by brian
clean slate
664
(select b from t2);
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
665
#show create table t1;
666
#drop table t1;
667
1 by brian
clean slate
668
create table t1 as
669
(select a from t2) union
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
670
(select b collate utf8_swedish_ci from t2);
942.3.1 by Vladimir Kolesnikov
test generalizations
671
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
672
show create table t1;
673
drop table t1;
674
create table t1 as
675
(select a from t2) union
676
(select b from t2) union
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
677
(select 'c' collate utf8_spanish_ci from t2);
942.3.1 by Vladimir Kolesnikov
test generalizations
678
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
679
show create table t1;
680
drop table t1;
681
drop table t2;
682
683
#
684
# Bug 6931: Date Type column problem when using UNION-Table.
685
#
686
create table t1(a1 int, f1 char(10));
687
create table t2
688
select f2,a1 from (select a1, CAST('2004-12-31' AS DATE) f2 from t1) a
689
union
690
select f2,a1 from (select a1, CAST('2004-12-31' AS DATE) f2 from t1) a
691
order by f2, a1;
692
show columns from t2;
693
drop table t1, t2;
694
695
create table t1 (f1 int);
696
create table t2 (f1 int, f2 int ,f3 date);
697
create table t3 (f1 int, f2 char(10));
698
create table t4
699
(
700
  select t2.f3 as sdate
701
  from t1
702
  left outer join t2 on (t1.f1 = t2.f1)
703
  inner join t3 on (t2.f2 = t3.f1)
704
  order by t1.f1, t3.f1, t2.f3
705
)
706
union
707
(
708
  select cast('2004-12-31' as date) as sdate
709
  from t1
710
  left outer join t2 on (t1.f1 = t2.f1)
711
  inner join t3 on (t2.f2 = t3.f1)
712
  group by t1.f1
713
  order by t1.f1, t3.f1, t2.f3
714
)
715
order by sdate;
716
show columns from t4;
717
drop table t1, t2, t3, t4;
718
719
#
720
# Bug #2435 UNION with parentheses not supported
721
#
722
create table t1 (a int not null, b char (10) not null); 
723
insert into t1 values(1,'a'),(2,'b'),(3,'c'),(3,'c'); 
724
select * from ((select * from t1 limit 1)) a;
725
select * from ((select * from t1 limit 1) union (select * from t1 limit 1)) a;
726
select * from ((select * from t1 limit 1) union (select * from t1 limit 1) union (select * from t1 limit 1)) a;
727
select * from ((((select * from t1))) union (select * from t1) union (select * from t1)) a;
728
select * from ((select * from t1) union (((select * from t1))) union (select * from t1)) a;
729
drop table t1;
730
731
#
732
# Bugs#6519 UNION with collation binary and latin1_swedish_ci fails
733
#
734
set @val:=6;
735
select concat('value is: ', @val) union select 'some text';
736
737
#
738
# Bug#15949 union + illegal mix of collations (IMPLICIT + COERCIBLE)
739
#
779.3.10 by Monty Taylor
Turned on -Wshadow.
740
select concat('a', 'b' collate utf8_bin);
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
741
create table t1 (foo varchar(100)) collate utf8_bin;
1 by brian
clean slate
742
insert into t1 (foo) values ("foo");
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
743
--error 1146
1 by brian
clean slate
744
select foo from t1 union select 'bar' as foo from dual;
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
745
select foo from t1 union select 'bar' as foo;
1 by brian
clean slate
746
drop table t1;
747
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
748
749
# Commenting out this test until Bug 308841 is fixed
1 by brian
clean slate
750
#
751
# Enum merging test
752
#
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
753
#CREATE TABLE t1 (
754
#  a ENUM('ä','ö','ü') character set utf8 not null default 'ü',
755
#  b ENUM("one", "two") character set utf8,
756
#  c ENUM("one", "two")
757
#);
942.3.1 by Vladimir Kolesnikov
test generalizations
758
#--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
759
#show create table t1;
760
#insert into t1 values ('ä', 'one', 'one'), ('ö', 'two', 'one'), ('ü', NULL, NULL);
761
#create table t2 select NULL union select a from t1;
762
#show columns from t2;
763
#drop table t2;
764
#create table t2 select a from t1 union select NULL;
765
#show columns from t2;
766
#drop table t2;
767
#create table t2 select a from t1 union select a from t1;
768
#show columns from t2;
769
#drop table t2;
770
#create table t2 select a from t1 union select c from t1;
771
#drop table t2;
772
#create table t2 select a from t1 union select b from t1;
773
#show columns from t2;
942.3.1 by Vladimir Kolesnikov
test generalizations
774
#drop table t2, t1;`
1 by brian
clean slate
775
776
# 
777
# Bug #14216: UNION + DECIMAL wrong values in result
778
#
779
create table t1 (f1 decimal(60,25), f2 decimal(60,25));
780
insert into t1 values (0.0,0.0);
781
select f1 from t1 union all select f2 from t1;
782
select 'XXXXXXXXXXXXXXXXXXXX' as description, f1 from t1
783
union all
784
select 'YYYYYYYYYYYYYYYYYYYY' as description, f2 from t1;
785
drop table t1;
786
create table t1 (f1 decimal(60,24), f2 decimal(60,24));
787
insert into t1 values (0.0,0.0);
788
select f1 from t1 union all select f2 from t1;
789
select 'XXXXXXXXXXXXXXXXXXXX' as description, f1 from t1
790
union all
791
select 'YYYYYYYYYYYYYYYYYYYY' as description, f2 from t1;
792
drop table t1;
793
794
#
795
# Test that union with VARCHAR produces dynamic row tables
796
#
797
798
create table t1 (a varchar(5));
799
create table t2 select * from t1 union select 'abcdefghijkl';
942.3.1 by Vladimir Kolesnikov
test generalizations
800
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
801
show create table t2;
802
select row_format from information_schema.TABLES where table_schema="test" and table_name="t2";
803
alter table t2 ROW_FORMAT=fixed;
942.3.1 by Vladimir Kolesnikov
test generalizations
804
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
805
show create table t2;
806
drop table t1,t2;
807
808
#
809
# correct conversion long string to TEXT (BUG#10025)
810
#
811
812
CREATE TABLE t1 (a mediumtext);
813
CREATE TABLE t2 (b varchar(20));
814
INSERT INTO t1 VALUES ('a'),('b');
815
SELECT left(a,100000000) FROM t1 UNION  SELECT b FROM t2;
816
create table t3 SELECT left(a,100000000) FROM t1 UNION  SELECT b FROM t2;
942.3.1 by Vladimir Kolesnikov
test generalizations
817
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
818
show create table t3;
819
drop tables t1,t2,t3;
820
821
#
822
# Extended fix to Bug#10025 - the test above should result to mediumtext
823
# and the one below to longtext. Earlier above test resulted to longtext
824
# type also.
825
#
826
827
CREATE TABLE t1 (a longtext);
828
CREATE TABLE t2 (b varchar(20));
829
INSERT INTO t1 VALUES ('a'),('b');
830
SELECT left(a,100000000) FROM t1 UNION  SELECT b FROM t2;
831
create table t3 SELECT left(a,100000000) FROM t1 UNION  SELECT b FROM t2;
942.3.1 by Vladimir Kolesnikov
test generalizations
832
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
833
show create table t3;
834
drop tables t1,t2,t3;
835
836
#
837
# Testing here that mediumtext converts into longtext if the result
838
# exceeds mediumtext maximum length
839
#
840
841
SELECT @tmp_max:= @@max_allowed_packet;
842
SET max_allowed_packet=25000000;
843
CREATE TABLE t1 (a mediumtext);
844
CREATE TABLE t2 (b varchar(20));
845
INSERT INTO t1 VALUES ('a');
846
CREATE TABLE t3 SELECT REPEAT(a,20000000) AS a FROM t1 UNION SELECT b FROM t2;
942.3.1 by Vladimir Kolesnikov
test generalizations
847
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
848
SHOW CREATE TABLE t3;
849
DROP TABLES t1,t3;
850
CREATE TABLE t1 (a tinytext);
851
INSERT INTO t1 VALUES ('a');
852
CREATE TABLE t3 SELECT REPEAT(a,2) AS a FROM t1 UNION SELECT b FROM t2;
942.3.1 by Vladimir Kolesnikov
test generalizations
853
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
854
SHOW CREATE TABLE t3;
855
DROP TABLES t1,t3;
856
CREATE TABLE t1 (a mediumtext);
857
INSERT INTO t1 VALUES ('a');
858
CREATE TABLE t3 SELECT REPEAT(a,2) AS a FROM t1 UNION SELECT b FROM t2;
942.3.1 by Vladimir Kolesnikov
test generalizations
859
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
860
SHOW CREATE TABLE t3;
861
DROP TABLES t1,t3;
862
CREATE TABLE t1 (a tinyblob);
863
INSERT INTO t1 VALUES ('a');
864
CREATE TABLE t3 SELECT REPEAT(a,2) AS a FROM t1 UNION SELECT b FROM t2;
942.3.1 by Vladimir Kolesnikov
test generalizations
865
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
866
SHOW CREATE TABLE t3;
867
DROP TABLES t1,t2,t3;
868
SET max_allowed_packet:= @tmp_max;
869
870
#
871
# Bug #10032 Bug in parsing UNION with ORDER BY when one node does not use FROM
872
#
873
874
create table t1 ( id int not null auto_increment, primary key (id), col1 int);
875
insert into t1 (col1) values (2),(3),(4),(5),(6);
876
select 99 union all select id from t1 order by 1;
877
select id from t1 union all select 99 order by 1;
878
drop table t1;
879
880
# End of 4.1 tests
881
882
#
883
# Bug#12185: Data type aggregation may produce wrong result
884
#
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
885
create table t1(f1 char(1), f2 char(5), f3 blob, f4 blob, f5 timestamp, f6 varchar(1) collate utf8_general_ci, f7 text);
1 by brian
clean slate
886
create table t2 as select *, f6 as f8 from t1 union select *, f7 from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
887
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
888
show create table t2;
889
drop table t1, t2;
890
891
#
892
# Bug#18175: Union select over 129 tables with a sum function fails.
893
#
894
(select avg(1)) union (select avg(1)) union (select avg(1)) union
895
(select avg(1)) union (select avg(1)) union (select avg(1)) union
896
(select avg(1)) union (select avg(1)) union (select avg(1)) union
897
(select avg(1)) union (select avg(1)) union (select avg(1)) union
898
(select avg(1)) union (select avg(1)) union (select avg(1)) union
899
(select avg(1)) union (select avg(1)) union (select avg(1)) union
900
(select avg(1)) union (select avg(1)) union (select avg(1)) union
901
(select avg(1)) union (select avg(1)) union (select avg(1)) union
902
(select avg(1)) union (select avg(1)) union (select avg(1)) union
903
(select avg(1)) union (select avg(1)) union (select avg(1)) union
904
(select avg(1)) union (select avg(1)) union (select avg(1)) union
905
(select avg(1)) union (select avg(1)) union (select avg(1)) union
906
(select avg(1)) union (select avg(1)) union (select avg(1)) union
907
(select avg(1)) union (select avg(1)) union (select avg(1)) union
908
(select avg(1)) union (select avg(1)) union (select avg(1)) union
909
(select avg(1)) union (select avg(1)) union (select avg(1)) union
910
(select avg(1)) union (select avg(1)) union (select avg(1)) union
911
(select avg(1)) union (select avg(1)) union (select avg(1)) union
912
(select avg(1)) union (select avg(1)) union (select avg(1)) union
913
(select avg(1)) union (select avg(1)) union (select avg(1)) union
914
(select avg(1)) union (select avg(1)) union (select avg(1)) union
915
(select avg(1)) union (select avg(1)) union (select avg(1)) union
916
(select avg(1)) union (select avg(1)) union (select avg(1)) union
917
(select avg(1)) union (select avg(1)) union (select avg(1)) union
918
(select avg(1)) union (select avg(1)) union (select avg(1)) union
919
(select avg(1)) union (select avg(1)) union (select avg(1)) union
920
(select avg(1)) union (select avg(1)) union (select avg(1)) union
921
(select avg(1)) union (select avg(1)) union (select avg(1)) union
922
(select avg(1)) union (select avg(1)) union (select avg(1)) union
923
(select avg(1)) union (select avg(1)) union (select avg(1)) union
924
(select avg(1)) union (select avg(1)) union (select avg(1)) union
925
(select avg(1)) union (select avg(1)) union (select avg(1)) union
926
(select avg(1)) union (select avg(1)) union (select avg(1)) union
927
(select avg(1)) union (select avg(1)) union (select avg(1)) union
928
(select avg(1)) union (select avg(1)) union (select avg(1)) union
929
(select avg(1)) union (select avg(1)) union (select avg(1)) union
930
(select avg(1)) union (select avg(1)) union (select avg(1)) union
931
(select avg(1)) union (select avg(1)) union (select avg(1)) union
932
(select avg(1)) union (select avg(1)) union (select avg(1)) union
933
(select avg(1)) union (select avg(1)) union (select avg(1)) union
934
(select avg(1)) union (select avg(1)) union (select avg(1)) union
935
(select avg(1)) union (select avg(1)) union (select avg(1)) union
936
(select avg(1)) union (select avg(1)) union (select avg(1));
937
938
#
939
# Bug #16881: password() and union select
940
# (The issue was poor handling of character set aggregation.)
941
#
779.3.10 by Monty Taylor
Turned on -Wshadow.
942
select '12' union select '12345';
1 by brian
clean slate
943
944
#
945
# Bug #26661: UNION with ORDER BY undefined column in FROM list
946
#
947
948
CREATE TABLE t1 (a int);
949
INSERT INTO t1 VALUES (3),(1),(2),(4),(1);
950
951
SELECT a FROM (SELECT a FROM t1 UNION SELECT a FROM t1 ORDER BY a) AS test;
952
--error 1054 
953
SELECT a FROM (SELECT a FROM t1 UNION SELECT a FROM t1 ORDER BY c) AS test;
954
955
DROP TABLE t1;
956
957
#
958
# Bug#23345: Wrongly allowed INTO in a non-last select of a UNION.
959
#
960
--error 1221
961
(select 1 into @var) union (select 1);
962
(select 1) union (select 1 into @var);
963
select @var;
964
--error 1172
965
(select 2) union (select 1 into @var);
966
967
#
968
# Bug#27848: order-by of union clashes with rollup of select part
969
#
970
971
CREATE TABLE t1 (a int);
972
INSERT INTO t1 VALUES (10), (20);
973
CREATE TABLE t2 (b int);
974
INSERT INTO t2 VALUES (10), (50), (50);
975
976
SELECT a,1 FROM t1 
977
UNION
978
SELECT b, COUNT(*) FROM t2 GROUP BY b WITH ROLLUP
979
ORDER BY a;
980
981
SELECT a,1 FROM t1 
982
UNION
983
SELECT b, COUNT(*) FROM t2 GROUP BY b WITH ROLLUP
984
ORDER BY a DESC;
985
986
SELECT a,1 FROM t1 
987
UNION
988
SELECT b, COUNT(*) FROM t2 GROUP BY b WITH ROLLUP
989
ORDER BY a ASC LIMIT 3;
990
991
SELECT a,1 FROM t1 
992
UNION ALL 
993
SELECT b, COUNT(*) FROM t2 GROUP BY b WITH ROLLUP
994
ORDER BY a DESC;
995
996
--error ER_WRONG_USAGE
997
SELECT a,1 FROM t1
998
UNION 
999
(SELECT b, COUNT(*) FROM t2 GROUP BY b WITH ROLLUP ORDER BY a);
1000
1001
--error ER_WRONG_USAGE
1002
SELECT a,1 FROM t1
1003
UNION ALL
1004
SELECT b, COUNT(*) FROM t2 GROUP BY b WITH ROLLUP ORDER BY a
1005
UNION
1006
SELECT 1,1;
1007
1008
DROP TABLE t1,t2;
1009
1010
# Bug#32848: Data type conversion bug in union subselects in MySQL 5.0.38
1011
#
1012
CREATE TABLE t1 (a INT);
1013
INSERT INTO t1 VALUES (1), (2), (3);
1014
1015
CREATE TABLE t2 SELECT * FROM (SELECT NULL) a UNION SELECT a FROM t1;
1016
DESC t2;
1017
1018
CREATE TABLE t3 SELECT a FROM t1 UNION SELECT * FROM (SELECT NULL) a;
1019
DESC t3;
1020
1021
CREATE TABLE t4 SELECT NULL;
1022
DESC t4;
1023
1024
CREATE TABLE t5 SELECT NULL UNION SELECT NULL;
1025
DESC t5;
1026
1027
CREATE TABLE t6 
1028
SELECT * FROM (SELECT * FROM (SELECT NULL)a) b UNION SELECT a FROM t1;
1029
DESC t6;
1030
1031
DROP TABLE t1, t2, t3, t4, t5, t6;
1032
--echo End of 5.0 tests