~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;
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
26
--error ER_TABLENAME_NOT_ALLOWED_HERE
1 by brian
clean slate
27
(select a,b from t1 limit 2)  union all (select a,b from t2 order by a limit 1) order by t1.b;
1063.9.44 by Stewart Smith
union.test for MyISAM as temp only.
28
--replace_column 9 #
1 by brian
clean slate
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
1063.9.44 by Stewart Smith
union.test for MyISAM as temp only.
39
--replace_column 9 #
1 by brian
clean slate
40
explain select a,b from t1 union all select a,b from t2;
41
2107.1.1 by Brian Aker
Add in all of the error messages, also remove all cases of --error number
42
--error ER_BAD_FIELD_ERROR
1 by brian
clean slate
43
explain select xx from t1 union select 1;
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
44
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
1 by brian
clean slate
45
explain select a,b from t1 union select 1;
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
46
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
1 by brian
clean slate
47
explain select 1 union select a,b from t1 union select 1;
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
48
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
1 by brian
clean slate
49
explain select a,b from t1 union select 1 limit 0;
50
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
51
--error ER_WRONG_USAGE
1 by brian
clean slate
52
select a,b from t1 into outfile 'skr' union select a,b from t2;
53
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
54
--error ER_WRONG_USAGE
1 by brian
clean slate
55
select a,b from t1 order by a union select a,b from t2;
56
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
57
--error ER_WRONG_USAGE
1 by brian
clean slate
58
insert into t3 select a from t1 order by a union select a from t2;
59
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
60
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
1 by brian
clean slate
61
create table t3 select a,b from t1 union select a from t2;
62
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
63
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
1 by brian
clean slate
64
select a,b from t1 union select a from t2;
65
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
66
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
1 by brian
clean slate
67
select * from t1 union select a from t2;
68
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
69
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
1 by brian
clean slate
70
select a from t1 union select * from t2;
71
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
72
--error ER_CANT_USE_OPTION_HERE
1 by brian
clean slate
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
#
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
86
--error ER_NO_TABLES_USED
1 by brian
clean slate
87
select * union select 1;
88
select 1 as a,(select a union select a);
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
89
--error ER_BAD_FIELD_ERROR
1 by brian
clean slate
90
(select 1) union (select 2) order by 0;
91
SELECT @a:=1 UNION SELECT @a:=@a+1;
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
92
--error ER_BAD_FIELD_ERROR
1 by brian
clean slate
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 '',
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
103
  `same` int NOT NULL default '1',
1 by brian
clean slate
104
  PRIMARY KEY  (`pseudo1`),
105
  KEY `pseudo` (`pseudo`)
1063.9.44 by Stewart Smith
union.test for MyISAM as temp only.
106
);
1 by brian
clean slate
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 (
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
133
  cid int NOT NULL default '0',
134
  cv varchar(190) NOT NULL default '',
1 by brian
clean slate
135
  PRIMARY KEY  (cid),
136
  UNIQUE KEY cv (cv)
137
) ;
138
INSERT INTO t1 VALUES (8,'dummy');
139
CREATE TABLE t2 (
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
140
  cid int NOT NULL auto_increment,
1 by brian
clean slate
141
  cap varchar(255) NOT NULL default '',
142
  PRIMARY KEY  (cid),
143
  KEY cap (cap)
144
) ;
145
CREATE TABLE t3 (
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
146
  gid int NOT NULL auto_increment,
1 by brian
clean slate
147
  gn varchar(255) NOT NULL default '',
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
148
  must int default NULL,
1 by brian
clean slate
149
  PRIMARY KEY  (gid),
150
  KEY gn (gn)
151
) ;
152
INSERT INTO t3 VALUES (1,'V1',NULL);
153
CREATE TABLE t4 (
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
154
  uid bigint NOT NULL default '0',
155
  gid bigint default NULL,
156
  rid bigint default NULL,
157
  cid bigint default NULL,
1 by brian
clean slate
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 (
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
166
  rid bigint NOT NULL auto_increment,
1 by brian
clean slate
167
  rl varchar(255) NOT NULL default '',
168
  PRIMARY KEY  (rid),
169
  KEY rl (rl)
170
) ;
171
CREATE TABLE t6 (
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
172
  uid bigint NOT NULL auto_increment,
173
  un varchar(190) NOT NULL default '',
174
  uc int NOT NULL default '0',
1 by brian
clean slate
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
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
222
--error ER_PARSE_ERROR
1 by brian
clean slate
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
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
253
--error ER_CANT_USE_OPTION_HERE
1 by brian
clean slate
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;
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
258
--error ER_UPDATE_TABLE_USED
1 by brian
clean slate
259
create table t1 select a from t1 union select a from t2;
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
260
--error ER_BAD_FIELD_ERROR
1 by brian
clean slate
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
#
1063.9.44 by Stewart Smith
union.test for MyISAM as temp only.
281
CREATE TEMPORARY TABLE t1 (  id int default '0') ENGINE=MyISAM;
1 by brian
clean slate
282
INSERT INTO t1 (id) VALUES("1");
1063.9.44 by Stewart Smith
union.test for MyISAM as temp only.
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;
1 by brian
clean slate
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 );
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
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) );
1 by brian
clean slate
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);
2141.4.2 by Andrew Hutchings
Implicit joins of the form "SELECT * FROM t1, t2" without WHERE or ON now error.
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 CROSS JOIN t2 c;
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
320
drop table t3, t1, t2;
1 by brian
clean slate
321
322
#
323
# fix_fields problem
324
#
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
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);
1 by brian
clean slate
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;
942.3.1 by Vladimir Kolesnikov
test generalizations
337
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
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;
942.3.1 by Vladimir Kolesnikov
test generalizations
342
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
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;
942.3.1 by Vladimir Kolesnikov
test generalizations
347
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
348
show create table t1;
349
drop table t1;
350
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
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);
873.1.2 by Jay Pipes
Fixed Field_datetime to never accept any bad datetimes as a string. This broke
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');
1 by brian
clean slate
353
354
create table t1 SELECT it2 from t2 UNION select it1 from t2;
355
select * from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
356
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
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;
942.3.1 by Vladimir Kolesnikov
test generalizations
361
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
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;
942.3.1 by Vladimir Kolesnikov
test generalizations
366
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
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;
942.3.1 by Vladimir Kolesnikov
test generalizations
371
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
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;
942.3.1 by Vladimir Kolesnikov
test generalizations
376
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
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;
942.3.1 by Vladimir Kolesnikov
test generalizations
381
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
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;
942.3.1 by Vladimir Kolesnikov
test generalizations
386
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
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;
942.3.1 by Vladimir Kolesnikov
test generalizations
391
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
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;
942.3.1 by Vladimir Kolesnikov
test generalizations
396
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
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;
942.3.1 by Vladimir Kolesnikov
test generalizations
401
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
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;
942.3.1 by Vladimir Kolesnikov
test generalizations
406
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
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;
942.3.1 by Vladimir Kolesnikov
test generalizations
411
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
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;
942.3.1 by Vladimir Kolesnikov
test generalizations
416
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
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;
942.3.1 by Vladimir Kolesnikov
test generalizations
421
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
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;
942.3.1 by Vladimir Kolesnikov
test generalizations
426
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
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;
942.3.1 by Vladimir Kolesnikov
test generalizations
431
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
432
show create table t1;
433
drop table t1,t2;
434
create table t1 select 1 union select -1;
435
select * from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
436
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
437
show create table t1;
438
drop table t1;
2131.5.1 by kalebral at gmail
remove error numbers in tests and use enum values only
439
--error ER_BAD_FIELD_ERROR
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
440
create table t1 select _latin1"test" union select _latin1"testt" ;
2131.5.1 by kalebral at gmail
remove error numbers in tests and use enum values only
441
--error ER_BAD_FIELD_ERROR
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
442
create table t1 select _utf8"test" union select _utf8"testt" ;
779.3.10 by Monty Taylor
Turned on -Wshadow.
443
create table t1 select "test" union select "testt" ;
942.3.1 by Vladimir Kolesnikov
test generalizations
444
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
445
show create table t1;
446
drop table t1;
447
448
#
449
# conversion memory->disk table
450
#
451
create table t1 (s char(200));
452
insert into t1 values (repeat("1",200));
453
create table t2 select * from t1;
454
insert into t2 select * from t1;
455
insert into t1 select * from t2;
456
insert into t2 select * from t1;
457
insert into t1 select * from t2;
458
insert into t2 select * from t1;
459
set local tmp_table_size=1024;
1487.1.1 by Brian Aker
There is room for improvement around this. We should be using rows as well
460
select SQL_BIG_RESULT count(*) from (select SQL_BIG_RESULT * from t1 union all select * from t2 order by 1) b;
1 by brian
clean slate
461
select count(*) from t1;
462
select count(*) from t2;
463
drop table t1,t2;
464
set local tmp_table_size=default;
465
466
#
467
# slow logging
468
#
469
create table t1 (a int, index (a), b int);
470
insert t1 values (1,1),(2,2),(3,3),(4,4),(5,5);
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
insert t1 select a+1, a+b from t1;
475
insert t1 select a+1, a+b from t1;
476
FLUSH STATUS;
1273.16.1 by Brian Aker
More removal of show code.
477
--replace_column 2 #
1 by brian
clean slate
478
show status like 'Slow_queries';
479
select count(*) from t1 where a=7;
1273.16.1 by Brian Aker
More removal of show code.
480
--replace_column 2 #
1 by brian
clean slate
481
show status like 'Slow_queries';
482
select count(*) from t1 where b=13;
1273.16.1 by Brian Aker
More removal of show code.
483
--replace_column 2 #
1 by brian
clean slate
484
show status like 'Slow_queries';
485
select count(*) from t1 where b=13 union select count(*) from t1 where a=7;
1273.16.1 by Brian Aker
More removal of show code.
486
--replace_column 2 #
1 by brian
clean slate
487
show status like 'Slow_queries';
488
select count(*) from t1 where a=7 union select count(*) from t1 where b=13;
1273.16.1 by Brian Aker
More removal of show code.
489
--replace_column 2 #
1 by brian
clean slate
490
show status like 'Slow_queries';
491
# additional test for examined rows
492
flush status;
493
select a from t1 where b not in (1,2,3) union select a from t1 where b not in (4,5,6); 
1273.16.1 by Brian Aker
More removal of show code.
494
--replace_column 2 #
1 by brian
clean slate
495
show status like 'Slow_queries';
496
drop table t1;
497
498
#
499
# Column 'name' cannot be null (error with union and left join) (bug #2508)
500
#
1063.9.44 by Stewart Smith
union.test for MyISAM as temp only.
501
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);
1 by brian
clean slate
502
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');
503
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);
504
drop  table t1;
505
506
#
507
# Bug #2809 (UNION fails on MyIsam tables when index on second column from
508
# same table)
509
#
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
510
create table t1 (col1 int, col2 int);
1 by brian
clean slate
511
insert into t1 values (1,2),(3,4),(5,6),(7,8),(9,10);
512
select col1 n from t1 union select col2 n from t1 order by n;
513
alter table t1 add index myindex (col2);
514
select col1 n from t1 union select col2 n from t1 order by n;
515
drop  table t1;
516
517
#
518
# Incorrect handling of UNION ALL (Bug #1428)
519
#
520
create table t1 (i int);
521
insert into t1 values (1);
522
select * from t1 UNION select * from t1;
523
select * from t1 UNION ALL select * from t1;
524
select * from t1 UNION select * from t1 UNION ALL select * from t1;
525
drop table t1;
526
select 1 as a union all select 1 union all select 2 union select 1 union all select 2;
527
set sql_select_limit=1;
528
select 1 union select 2;
529
(select 1) union (select 2);
530
(select 1) union (select 2) union (select 3) limit 2;
531
set sql_select_limit=default;
532
533
#
534
# ORDER with LIMIT
535
#
536
create table t1 (a int);
537
insert into t1 values (100), (1);
538
create table t2 (a int);
539
insert into t2 values (100);
540
select a from t1 union select a from t2 order by a;
541
SET SQL_SELECT_LIMIT=1;
542
select a from t1 union select a from t2 order by a;
543
drop table t1, t2;
544
set sql_select_limit=default;
545
546
#
547
# nonexisting column in global ORDER BY
548
#
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
549
CREATE TABLE t1 (i int default NULL,c char(1) default NULL,KEY i (i));
550
CREATE TABLE t2 (i int default NULL,c char(1) default NULL,KEY i (i));
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
551
--error ER_BAD_FIELD_ERROR
1 by brian
clean slate
552
explain (select * from t1) union (select * from t2) order by not_existing_column;
553
drop table t1, t2;
554
555
#
556
# length detecting
557
#
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
558
CREATE TABLE t1 (uid int);
1 by brian
clean slate
559
INSERT INTO t1 SELECT 150;
560
SELECT 'a' UNION SELECT uid FROM t1;
561
drop table t1;
562
563
#
564
# parser stack overflow
565
#
873.1.2 by Jay Pipes
Fixed Field_datetime to never accept any bad datetimes as a string. This broke
566
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
567
907.1.7 by Jay Pipes
Merged in remove-timezone work
568
CREATE TABLE t2 ( ID int NOT NULL DEFAULT '0' , DATA1 timestamp NULL, PRIMARY KEY (ID));
1 by brian
clean slate
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) UNION
591
(SELECT * FROM t1 AS PARTITIONED, t2 AS
592
PARTITIONED_B WHERE PARTITIONED_B.ID=PARTITIONED.ID1);
593
drop table t1,t2;
594
595
#
596
# merging ENUM and SET fields in one UNION
597
#
598
create table t1 (a ENUM('Yes', 'No') NOT NULL);
599
create table t2 (a ENUM('aaa', 'bbb') NOT NULL);
600
insert into t1 values ('No');
601
insert into t2 values ('bbb');
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
602
create table t3 (a ENUM('Yes', 'No') NOT NULL);
603
create table t4 (a ENUM('aaa', 'bbb') NOT NULL);
1 by brian
clean slate
604
insert into t3 values (1);
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
605
--error ER_INVALID_ENUM_VALUE # Bad enum
1 by brian
clean slate
606
insert into t4 values (3);
607
select "1" as a union select a from t1;
608
select a as a from t1 union select "1";
609
select a as a from t2 union select a from t1;
610
select "1" as a union select a from t3;
611
select a as a from t3 union select "1";
612
select a as a from t4 union select a from t3;
613
select a as a from t1 union select a from t4;
614
drop table t1,t2,t3,t4;
615
616
#
617
# Bug #6139 UNION doesn't understand collate in the column of second select
618
#
619
create table t1 as
779.3.10 by Monty Taylor
Turned on -Wshadow.
620
(select 'test') union
621
(select 'TEST') union
622
(select 'TeST');
942.3.1 by Vladimir Kolesnikov
test generalizations
623
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
779.3.10 by Monty Taylor
Turned on -Wshadow.
624
show create table t1;
625
select count(*) from t1;
626
drop table t1;
627
628
create table t1 as
629
(select 'test' collate utf8_bin) union
630
(select 'TEST') union
631
(select 'TeST');
942.3.1 by Vladimir Kolesnikov
test generalizations
632
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
779.3.10 by Monty Taylor
Turned on -Wshadow.
633
show create table t1;
634
select count(*) from t1;
635
drop table t1;
636
637
create table t1 as
638
(select 'test') union
639
(select 'TEST' collate utf8_bin) union
640
(select 'TeST');
942.3.1 by Vladimir Kolesnikov
test generalizations
641
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
779.3.10 by Monty Taylor
Turned on -Wshadow.
642
show create table t1;
643
select count(*) from t1;
644
drop table t1;
645
646
create table t1 as
647
(select 'test') union
648
(select 'TEST') union
649
(select 'TeST' collate utf8_bin);
942.3.1 by Vladimir Kolesnikov
test generalizations
650
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
651
show create table t1;
652
select count(*) from t1;
653
drop table t1;
654
655
# Drizzle doesn't support specifying character set, it is all UTF8
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
656
--error ER_PARSE_ERROR
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
657
create table t2 (
658
a char character set utf8 collate utf8_swedish_ci,
659
b char character set utf8 collate utf8_spanish_ci);
660
661
create table t2 (
662
a char collate utf8_swedish_ci,
663
b char collate utf8_spanish_ci);
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
664
--error ER_CANT_AGGREGATE_NCOLLATIONS
1 by brian
clean slate
665
create table t1 as
666
(select a from t2) union
667
(select b from t2);
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
668
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
669
--error ER_WRONG_COLUMN_NAME
1 by brian
clean slate
670
create table t1 as
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
671
(select a collate utf8_swedish_ci from t2) union
1 by brian
clean slate
672
(select b from t2);
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
673
#show create table t1;
674
#drop table t1;
675
1 by brian
clean slate
676
create table t1 as
677
(select a from t2) union
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
678
(select b collate utf8_swedish_ci from t2);
942.3.1 by Vladimir Kolesnikov
test generalizations
679
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
680
show create table t1;
681
drop table t1;
682
create table t1 as
683
(select a from t2) union
684
(select b from t2) union
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
685
(select 'c' collate utf8_spanish_ci from t2);
942.3.1 by Vladimir Kolesnikov
test generalizations
686
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
687
show create table t1;
688
drop table t1;
689
drop table t2;
690
691
#
692
# Bug 6931: Date Type column problem when using UNION-Table.
693
#
694
create table t1(a1 int, f1 char(10));
695
create table t2
696
select f2,a1 from (select a1, CAST('2004-12-31' AS DATE) f2 from t1) a
697
union
698
select f2,a1 from (select a1, CAST('2004-12-31' AS DATE) f2 from t1) a
699
order by f2, a1;
700
show columns from t2;
701
drop table t1, t2;
702
703
create table t1 (f1 int);
704
create table t2 (f1 int, f2 int ,f3 date);
705
create table t3 (f1 int, f2 char(10));
706
create table t4
707
(
708
  select t2.f3 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
  order by t1.f1, t3.f1, t2.f3
713
)
714
union
715
(
716
  select cast('2004-12-31' as date) as sdate
717
  from t1
718
  left outer join t2 on (t1.f1 = t2.f1)
719
  inner join t3 on (t2.f2 = t3.f1)
720
  group by t1.f1
721
  order by t1.f1, t3.f1, t2.f3
722
)
723
order by sdate;
724
show columns from t4;
725
drop table t1, t2, t3, t4;
726
727
#
728
# Bug #2435 UNION with parentheses not supported
729
#
730
create table t1 (a int not null, b char (10) not null); 
731
insert into t1 values(1,'a'),(2,'b'),(3,'c'),(3,'c'); 
732
select * from ((select * from t1 limit 1)) a;
733
select * from ((select * from t1 limit 1) union (select * from t1 limit 1)) a;
734
select * from ((select * from t1 limit 1) union (select * from t1 limit 1) union (select * from t1 limit 1)) a;
735
select * from ((((select * from t1))) union (select * from t1) union (select * from t1)) a;
736
select * from ((select * from t1) union (((select * from t1))) union (select * from t1)) a;
737
drop table t1;
738
739
#
740
# Bugs#6519 UNION with collation binary and latin1_swedish_ci fails
741
#
742
set @val:=6;
743
select concat('value is: ', @val) union select 'some text';
744
745
#
746
# Bug#15949 union + illegal mix of collations (IMPLICIT + COERCIBLE)
747
#
779.3.10 by Monty Taylor
Turned on -Wshadow.
748
select concat('a', 'b' collate utf8_bin);
1245.3.4 by Stewart Smith
make the equals of KEY=VALUE required for CREATE TABLE options
749
create table t1 (foo varchar(100)) collate=utf8_bin;
1 by brian
clean slate
750
insert into t1 (foo) values ("foo");
2140.1.2 by Brian Aker
Merge in decomplication of our error system when reading through the table
751
--error ER_TABLE_UNKNOWN
1 by brian
clean slate
752
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
753
select foo from t1 union select 'bar' as foo;
1 by brian
clean slate
754
drop table t1;
755
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
756
757
# Commenting out this test until Bug 308841 is fixed
1 by brian
clean slate
758
#
759
# Enum merging test
760
#
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
761
#CREATE TABLE t1 (
762
#  a ENUM('ä','ö','ü') character set utf8 not null default 'ü',
763
#  b ENUM("one", "two") character set utf8,
764
#  c ENUM("one", "two")
765
#);
942.3.1 by Vladimir Kolesnikov
test generalizations
766
#--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
767
#show create table t1;
768
#insert into t1 values ('ä', 'one', 'one'), ('ö', 'two', 'one'), ('ü', NULL, NULL);
769
#create table t2 select NULL union select a from t1;
770
#show columns from t2;
771
#drop table t2;
772
#create table t2 select a from t1 union select NULL;
773
#show columns from t2;
774
#drop table t2;
775
#create table t2 select a from t1 union select a from t1;
776
#show columns from t2;
777
#drop table t2;
778
#create table t2 select a from t1 union select c from t1;
779
#drop table t2;
780
#create table t2 select a from t1 union select b from t1;
781
#show columns from t2;
942.3.1 by Vladimir Kolesnikov
test generalizations
782
#drop table t2, t1;`
1 by brian
clean slate
783
784
# 
785
# Bug #14216: UNION + DECIMAL wrong values in result
786
#
787
create table t1 (f1 decimal(60,25), f2 decimal(60,25));
788
insert into t1 values (0.0,0.0);
789
select f1 from t1 union all select f2 from t1;
790
select 'XXXXXXXXXXXXXXXXXXXX' as description, f1 from t1
791
union all
792
select 'YYYYYYYYYYYYYYYYYYYY' as description, f2 from t1;
793
drop table t1;
794
create table t1 (f1 decimal(60,24), f2 decimal(60,24));
795
insert into t1 values (0.0,0.0);
796
select f1 from t1 union all select f2 from t1;
797
select 'XXXXXXXXXXXXXXXXXXXX' as description, f1 from t1
798
union all
799
select 'YYYYYYYYYYYYYYYYYYYY' as description, f2 from t1;
800
drop table t1;
801
802
#
803
# Test that union with VARCHAR produces dynamic row tables
804
#
805
806
create table t1 (a varchar(5));
807
create table t2 select * from t1 union select 'abcdefghijkl';
942.3.1 by Vladimir Kolesnikov
test generalizations
808
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
809
show create table t2;
1273.13.32 by Brian Aker
Big ole patch. This covers moving information_schema to old_* table names
810
select row_format from data_dictionary.TABLES where table_schema="test" and table_name="t2";
942.3.1 by Vladimir Kolesnikov
test generalizations
811
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
812
show create table t2;
813
drop table t1,t2;
814
815
#
816
# correct conversion long string to TEXT (BUG#10025)
817
#
818
819
CREATE TABLE t1 (a mediumtext);
820
CREATE TABLE t2 (b varchar(20));
821
INSERT INTO t1 VALUES ('a'),('b');
822
SELECT left(a,100000000) FROM t1 UNION  SELECT b FROM t2;
823
create table t3 SELECT left(a,100000000) FROM t1 UNION  SELECT b FROM t2;
942.3.1 by Vladimir Kolesnikov
test generalizations
824
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
825
show create table t3;
826
drop tables t1,t2,t3;
827
828
#
829
# Extended fix to Bug#10025 - the test above should result to mediumtext
830
# and the one below to longtext. Earlier above test resulted to longtext
831
# type also.
832
#
833
834
CREATE TABLE t1 (a longtext);
835
CREATE TABLE t2 (b varchar(20));
836
INSERT INTO t1 VALUES ('a'),('b');
837
SELECT left(a,100000000) FROM t1 UNION  SELECT b FROM t2;
838
create table t3 SELECT left(a,100000000) FROM t1 UNION  SELECT b FROM t2;
942.3.1 by Vladimir Kolesnikov
test generalizations
839
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
840
show create table t3;
841
drop tables t1,t2,t3;
842
843
#
844
# Testing here that mediumtext converts into longtext if the result
845
# exceeds mediumtext maximum length
846
#
847
848
SELECT @tmp_max:= @@max_allowed_packet;
849
SET max_allowed_packet=25000000;
850
CREATE TABLE t1 (a mediumtext);
851
CREATE TABLE t2 (b varchar(20));
852
INSERT INTO t1 VALUES ('a');
853
CREATE TABLE t3 SELECT REPEAT(a,20000000) AS a FROM t1 UNION SELECT b FROM t2;
942.3.1 by Vladimir Kolesnikov
test generalizations
854
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
855
SHOW CREATE TABLE t3;
856
DROP TABLES t1,t3;
857
CREATE TABLE t1 (a tinytext);
858
INSERT INTO t1 VALUES ('a');
859
CREATE TABLE t3 SELECT REPEAT(a,2) AS a FROM t1 UNION SELECT b FROM t2;
942.3.1 by Vladimir Kolesnikov
test generalizations
860
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
861
SHOW CREATE TABLE t3;
862
DROP TABLES t1,t3;
863
CREATE TABLE t1 (a mediumtext);
864
INSERT INTO t1 VALUES ('a');
865
CREATE TABLE t3 SELECT REPEAT(a,2) AS a FROM t1 UNION SELECT b FROM t2;
942.3.1 by Vladimir Kolesnikov
test generalizations
866
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
867
SHOW CREATE TABLE t3;
868
DROP TABLES t1,t3;
869
CREATE TABLE t1 (a tinyblob);
870
INSERT INTO t1 VALUES ('a');
871
CREATE TABLE t3 SELECT REPEAT(a,2) AS a FROM t1 UNION SELECT b FROM t2;
942.3.1 by Vladimir Kolesnikov
test generalizations
872
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
873
SHOW CREATE TABLE t3;
874
DROP TABLES t1,t2,t3;
875
SET max_allowed_packet:= @tmp_max;
876
877
#
878
# Bug #10032 Bug in parsing UNION with ORDER BY when one node does not use FROM
879
#
880
881
create table t1 ( id int not null auto_increment, primary key (id), col1 int);
882
insert into t1 (col1) values (2),(3),(4),(5),(6);
883
select 99 union all select id from t1 order by 1;
884
select id from t1 union all select 99 order by 1;
885
drop table t1;
886
887
# End of 4.1 tests
888
889
#
890
# Bug#12185: Data type aggregation may produce wrong result
891
#
642.1.49 by Lee
enable type_enum, union, variables-big and type_enum tests
892
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
893
create table t2 as select *, f6 as f8 from t1 union select *, f7 from t1;
942.3.1 by Vladimir Kolesnikov
test generalizations
894
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
1 by brian
clean slate
895
show create table t2;
896
drop table t1, t2;
897
898
#
899
# Bug#18175: Union select over 129 tables with a sum function fails.
900
#
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)) union
942
(select avg(1)) union (select avg(1)) union (select avg(1)) union
943
(select avg(1)) union (select avg(1)) union (select avg(1));
944
945
#
946
# Bug #16881: password() and union select
947
# (The issue was poor handling of character set aggregation.)
948
#
779.3.10 by Monty Taylor
Turned on -Wshadow.
949
select '12' union select '12345';
1 by brian
clean slate
950
951
#
952
# Bug #26661: UNION with ORDER BY undefined column in FROM list
953
#
954
955
CREATE TABLE t1 (a int);
956
INSERT INTO t1 VALUES (3),(1),(2),(4),(1);
957
958
SELECT a FROM (SELECT a FROM t1 UNION SELECT a FROM t1 ORDER BY a) AS test;
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
959
--error ER_BAD_FIELD_ERROR 
1 by brian
clean slate
960
SELECT a FROM (SELECT a FROM t1 UNION SELECT a FROM t1 ORDER BY c) AS test;
961
962
DROP TABLE t1;
963
964
#
965
# Bug#23345: Wrongly allowed INTO in a non-last select of a UNION.
966
#
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
967
--error ER_WRONG_USAGE
1 by brian
clean slate
968
(select 1 into @var) union (select 1);
969
(select 1) union (select 1 into @var);
970
select @var;
1731.3.1 by Lee Bieber
change tests to use enum values instead of error numbers
971
--error ER_TOO_MANY_ROWS
1 by brian
clean slate
972
(select 2) union (select 1 into @var);
973
974
#
975
# Bug#27848: order-by of union clashes with rollup of select part
976
#
977
978
CREATE TABLE t1 (a int);
979
INSERT INTO t1 VALUES (10), (20);
980
CREATE TABLE t2 (b int);
981
INSERT INTO t2 VALUES (10), (50), (50);
982
983
SELECT a,1 FROM t1 
984
UNION
985
SELECT b, COUNT(*) FROM t2 GROUP BY b WITH ROLLUP
986
ORDER BY a;
987
988
SELECT a,1 FROM t1 
989
UNION
990
SELECT b, COUNT(*) FROM t2 GROUP BY b WITH ROLLUP
991
ORDER BY a DESC;
992
993
SELECT a,1 FROM t1 
994
UNION
995
SELECT b, COUNT(*) FROM t2 GROUP BY b WITH ROLLUP
996
ORDER BY a ASC LIMIT 3;
997
998
SELECT a,1 FROM t1 
999
UNION ALL 
1000
SELECT b, COUNT(*) FROM t2 GROUP BY b WITH ROLLUP
1001
ORDER BY a DESC;
1002
1003
--error ER_WRONG_USAGE
1004
SELECT a,1 FROM t1
1005
UNION 
1006
(SELECT b, COUNT(*) FROM t2 GROUP BY b WITH ROLLUP ORDER BY a);
1007
1008
--error ER_WRONG_USAGE
1009
SELECT a,1 FROM t1
1010
UNION ALL
1011
SELECT b, COUNT(*) FROM t2 GROUP BY b WITH ROLLUP ORDER BY a
1012
UNION
1013
SELECT 1,1;
1014
1015
DROP TABLE t1,t2;
1016
1017
# Bug#32848: Data type conversion bug in union subselects in MySQL 5.0.38
1018
#
1019
CREATE TABLE t1 (a INT);
1020
INSERT INTO t1 VALUES (1), (2), (3);
1021
1022
CREATE TABLE t2 SELECT * FROM (SELECT NULL) a UNION SELECT a FROM t1;
1023
DESC t2;
1024
1025
CREATE TABLE t3 SELECT a FROM t1 UNION SELECT * FROM (SELECT NULL) a;
1026
DESC t3;
1027
1028
CREATE TABLE t4 SELECT NULL;
1029
DESC t4;
1030
1031
CREATE TABLE t5 SELECT NULL UNION SELECT NULL;
1032
DESC t5;
1033
1034
CREATE TABLE t6 
1035
SELECT * FROM (SELECT * FROM (SELECT NULL)a) b UNION SELECT a FROM t1;
1036
DESC t6;
1037
1038
DROP TABLE t1, t2, t3, t4, t5, t6;
1039
--echo End of 5.0 tests