~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/union.test

Cleanup around SAFEMALLOC

Show diffs side-by-side

added added

removed removed

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