~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12;
2
select (select 2);
3
(select 2)
4
2
5
explain extended select (select 2);
6
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
7
1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
8
Warnings:
9
Note	1249	Select 2 was reduced during optimization
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
10
Note	1003	select 2 AS `(select 2)`
1 by brian
clean slate
11
SELECT (SELECT 1) UNION SELECT (SELECT 2);
12
(SELECT 1)
13
1
14
2
15
explain extended SELECT (SELECT 1) UNION SELECT (SELECT 2);
16
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
17
1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
18
3	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
19
NULL	UNION RESULT	<union1,3>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
20
Warnings:
21
Note	1249	Select 2 was reduced during optimization
22
Note	1249	Select 4 was reduced during optimization
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
23
Note	1003	select 1 AS `(SELECT 1)` union select 2 AS `(SELECT 2)`
1 by brian
clean slate
24
SELECT (SELECT (SELECT 0 UNION SELECT 0));
25
(SELECT (SELECT 0 UNION SELECT 0))
26
0
27
explain extended SELECT (SELECT (SELECT 0 UNION SELECT 0));
28
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
29
1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
30
3	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
31
4	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
32
NULL	UNION RESULT	<union3,4>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
33
Warnings:
34
Note	1249	Select 2 was reduced during optimization
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
35
Note	1003	select (select 0 AS `0` union select 0 AS `0`) AS `(SELECT (SELECT 0 UNION SELECT 0))`
1 by brian
clean slate
36
SELECT (SELECT 1 FROM (SELECT 1) as b HAVING a=1) as a;
37
ERROR 42S22: Reference 'a' not supported (forward reference in item list)
38
SELECT (SELECT 1 FROM (SELECT 1) as b HAVING b=1) as a,(SELECT 1 FROM (SELECT 1) as c HAVING a=1) as b;
39
ERROR 42S22: Reference 'b' not supported (forward reference in item list)
40
SELECT (SELECT 1),MAX(1) FROM (SELECT 1) as a;
41
(SELECT 1)	MAX(1)
42
1	1
43
SELECT (SELECT a) as a;
44
ERROR 42S22: Reference 'a' not supported (forward reference in item list)
45
EXPLAIN EXTENDED SELECT 1 FROM (SELECT 1 as a) as b  HAVING (SELECT a)=1;
46
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
47
1	PRIMARY	<derived2>	system	NULL	NULL	NULL	NULL	1	100.00	
48
3	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
49
2	DERIVED	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
50
Warnings:
51
Note	1276	Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1
52
Note	1276	Field or reference 'b.a' of SELECT #3 was resolved in SELECT #1
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
53
Note	1003	select 1 AS `1` from (select 1 AS `a`) `b` having ((select '1' AS `a`) = 1)
1 by brian
clean slate
54
SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
55
1
56
1
57
SELECT (SELECT 1), a;
58
ERROR 42S22: Unknown column 'a' in 'field list'
59
SELECT 1 as a FROM (SELECT 1) as b HAVING (SELECT a)=1;
60
a
61
1
62
SELECT 1 FROM (SELECT (SELECT a) b) c;
63
ERROR 42S22: Unknown column 'a' in 'field list'
64
SELECT * FROM (SELECT 1 as id) b WHERE id IN (SELECT * FROM (SELECT 1 as id) c ORDER BY id);
65
id
66
1
67
SELECT * FROM (SELECT 1) a  WHERE 1 IN (SELECT 1,1);
68
ERROR 21000: Operand should contain 1 column(s)
69
SELECT 1 IN (SELECT 1);
70
1 IN (SELECT 1)
71
1
72
SELECT 1 FROM (SELECT 1 as a) b WHERE 1 IN (SELECT (SELECT a));
73
1
74
1
75
SELECT (SELECT 1) as a FROM (SELECT 1) b WHERE (SELECT a) IS NULL;
76
ERROR 42S22: Unknown column 'a' in 'field list'
77
SELECT (SELECT 1) as a FROM (SELECT 1) b WHERE (SELECT a) IS NOT NULL;
78
ERROR 42S22: Unknown column 'a' in 'field list'
79
SELECT (SELECT 1,2,3) = ROW(1,2,3);
80
(SELECT 1,2,3) = ROW(1,2,3)
81
1
82
SELECT (SELECT 1,2,3) = ROW(1,2,1);
83
(SELECT 1,2,3) = ROW(1,2,1)
84
0
85
SELECT (SELECT 1,2,3) < ROW(1,2,1);
86
(SELECT 1,2,3) < ROW(1,2,1)
87
0
88
SELECT (SELECT 1,2,3) > ROW(1,2,1);
89
(SELECT 1,2,3) > ROW(1,2,1)
90
1
91
SELECT (SELECT 1,2,3) = ROW(1,2,NULL);
92
(SELECT 1,2,3) = ROW(1,2,NULL)
93
NULL
94
SELECT ROW(1,2,3) = (SELECT 1,2,3);
95
ROW(1,2,3) = (SELECT 1,2,3)
96
1
97
SELECT ROW(1,2,3) = (SELECT 1,2,1);
98
ROW(1,2,3) = (SELECT 1,2,1)
99
0
100
SELECT ROW(1,2,3) < (SELECT 1,2,1);
101
ROW(1,2,3) < (SELECT 1,2,1)
102
0
103
SELECT ROW(1,2,3) > (SELECT 1,2,1);
104
ROW(1,2,3) > (SELECT 1,2,1)
105
1
106
SELECT ROW(1,2,3) = (SELECT 1,2,NULL);
107
ROW(1,2,3) = (SELECT 1,2,NULL)
108
NULL
109
SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'a');
110
(SELECT 1.5,2,'a') = ROW(1.5,2,'a')
111
1
112
SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'b');
113
(SELECT 1.5,2,'a') = ROW(1.5,2,'b')
114
0
115
SELECT (SELECT 1.5,2,'a') = ROW('1.5b',2,'b');
116
(SELECT 1.5,2,'a') = ROW('1.5b',2,'b')
117
0
118
Warnings:
119
Warning	1292	Truncated incorrect DOUBLE value: '1.5b'
120
SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a');
121
(SELECT 'b',2,'a') = ROW(1.5,2,'a')
122
0
123
SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a');
124
(SELECT 1.5,2,'a') = ROW(1.5,'2','a')
125
1
126
SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a');
127
(SELECT 1.5,'c','a') = ROW(1.5,2,'a')
128
0
129
SELECT (SELECT * FROM (SELECT 'test' a,'test' b) a);
130
ERROR 21000: Operand should contain 1 column(s)
131
SELECT 1 as a,(SELECT a+a) b,(SELECT b);
132
a	b	(SELECT b)
133
1	2	2
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
134
create table t1 (a int) ENGINE=MyISAM;
135
create table t2 (a int, b int) ENGINE=MyISAM;
136
create table t3 (a int) ENGINE=MyISAM;
137
create table t4 (a int not null, b int not null) ENGINE=MyISAM;
1 by brian
clean slate
138
insert into t1 values (2);
139
insert into t2 values (1,7),(2,7);
140
insert into t4 values (4,8),(3,8),(5,9);
141
select (select a from t1 where t1.a = a1) as a2, (select b from t2 where t2.b=a2) as a1;
142
ERROR 42S22: Reference 'a1' not supported (forward reference in item list)
143
select (select a from t1 where t1.a=t2.a), a from t2;
144
(select a from t1 where t1.a=t2.a)	a
145
NULL	1
146
2	2
147
select (select a from t1 where t1.a=t2.b), a from t2;
148
(select a from t1 where t1.a=t2.b)	a
149
NULL	1
150
NULL	2
151
select (select a from t1), a, (select 1 union select 2 limit 1) from t2;
152
(select a from t1)	a	(select 1 union select 2 limit 1)
153
2	1	1
154
2	2	1
155
select (select a from t3), a from t2;
156
(select a from t3)	a
157
NULL	1
158
NULL	2
159
select * from t2 where t2.a=(select a from t1);
160
a	b
161
2	7
162
insert into t3 values (6),(7),(3);
163
select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1);
164
a	b
165
1	7
166
2	7
167
(select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)) union (select * from t4 order by a limit 2) limit 3;
168
a	b
169
1	7
170
2	7
171
3	8
172
(select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)) union (select * from t4 where t4.b=(select max(t2.a)*4 from t2) order by a);
173
a	b
174
1	7
175
2	7
176
4	8
177
3	8
178
explain extended (select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)) union (select * from t4 where t4.b=(select max(t2.a)*4 from t2) order by a);
179
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
180
1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
181
2	SUBQUERY	t3	ALL	NULL	NULL	NULL	NULL	3	100.00	Using filesort
182
3	UNION	t4	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
183
4	SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	2	100.00	
184
NULL	UNION RESULT	<union1,3>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
185
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
186
Note	1003	(select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`b` = (select `test`.`t3`.`a` AS `a` from `test`.`t3` order by 1 desc limit 1))) union (select `test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t4` where (`test`.`t4`.`b` = (select (max(`test`.`t2`.`a`) * 4) AS `max(t2.a)*4` from `test`.`t2`)) order by `a`)
1 by brian
clean slate
187
select (select a from t3 where a<t2.a*4 order by 1 desc limit 1), a from t2;
188
(select a from t3 where a<t2.a*4 order by 1 desc limit 1)	a
189
3	1
190
7	2
191
select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from 
192
(select * from t2 where a>1) as tt;
193
(select t3.a from t3 where a<8 order by 1 desc limit 1)	a
194
7	2
195
explain extended select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from 
196
(select * from t2 where a>1) as tt;
197
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
198
1	PRIMARY	<derived3>	system	NULL	NULL	NULL	NULL	1	100.00	
199
3	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
200
2	SUBQUERY	t3	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using filesort
201
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
202
Note	1003	select (select `test`.`t3`.`a` AS `a` from `test`.`t3` where (`test`.`t3`.`a` < 8) order by 1 desc limit 1) AS `(select t3.a from t3 where a<8 order by 1 desc limit 1)`,'2' AS `a` from (select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where (`test`.`t2`.`a` > 1)) `tt`
1 by brian
clean slate
203
select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3) order by 1 desc limit 1);
204
a
205
2
206
select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3 where t3.a > t1.a) order by 1 desc limit 1);
207
a
208
2
209
select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3 where t3.a < t1.a) order by 1 desc limit 1);
210
a
211
select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4;
212
b	(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2)
213
8	7.5000
214
8	4.5000
215
9	7.5000
216
explain extended select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4;
217
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
218
1	PRIMARY	t4	ALL	NULL	NULL	NULL	NULL	3	100.00	
219
2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	2	100.00	
220
3	DEPENDENT SUBQUERY	t3	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
221
Warnings:
222
Note	1276	Field or reference 'test.t4.a' of SELECT #3 was resolved in SELECT #1
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
223
Note	1003	select `test`.`t4`.`b` AS `b`,(select avg((`test`.`t2`.`a` + (select min(`test`.`t3`.`a`) AS `min(t3.a)` from `test`.`t3` where (`test`.`t3`.`a` >= `test`.`t4`.`a`)))) AS `avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a))` from `test`.`t2`) AS `(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2)` from `test`.`t4`
1 by brian
clean slate
224
select * from t3 where exists (select * from t2 where t2.b=t3.a);
225
a
226
7
227
select * from t3 where not exists (select * from t2 where t2.b=t3.a);
228
a
229
6
230
3
231
select * from t3 where a in (select b from t2);
232
a
233
7
234
select * from t3 where a not in (select b from t2);
235
a
236
6
237
3
238
select * from t3 where a = some (select b from t2);
239
a
240
7
241
select * from t3 where a <> any (select b from t2);
242
a
243
6
244
3
245
select * from t3 where a = all (select b from t2);
246
a
247
7
248
select * from t3 where a <> all (select b from t2);
249
a
250
6
251
3
252
insert into t2 values (100, 5);
253
select * from t3 where a < any (select b from t2);
254
a
255
6
256
3
257
select * from t3 where a < all (select b from t2);
258
a
259
3
260
select * from t3 where a >= any (select b from t2);
261
a
262
6
263
7
264
explain extended select * from t3 where a >= any (select b from t2);
265
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
266
1	PRIMARY	t3	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
267
2	SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
268
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
269
Note	1003	select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>((`test`.`t3`.`a` >= (select min(`test`.`t2`.`b`) from `test`.`t2`)))
1 by brian
clean slate
270
select * from t3 where a >= all (select b from t2);
271
a
272
7
273
delete from t2 where a=100;
274
select * from t3 where a in (select a,b from t2);
275
ERROR 21000: Operand should contain 1 column(s)
276
select * from t3 where a in (select * from t2);
277
ERROR 21000: Operand should contain 1 column(s)
278
insert into t4 values (12,7),(1,7),(10,9),(9,6),(7,6),(3,9),(1,10);
279
select b,max(a) as ma from t4 group by b having b < (select max(t2.a) from t2 where t2.b=t4.b);
280
b	ma
281
insert into t2 values (2,10);
282
select b,max(a) as ma from t4 group by b having ma < (select max(t2.a) from t2 where t2.b=t4.b);
283
b	ma
284
10	1
285
delete from t2 where a=2 and b=10;
286
select b,max(a) as ma from t4 group by b having b >= (select max(t2.a) from t2 where t2.b=t4.b);
287
b	ma
288
7	12
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
289
create table t5 (a int) ENGINE=MyISAM;
1 by brian
clean slate
290
select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
291
(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)	a
292
NULL	1
293
2	2
294
insert into t5 values (5);
295
select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
296
(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)	a
297
NULL	1
298
2	2
299
insert into t5 values (2);
300
select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
301
(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)	a
302
NULL	1
303
2	2
304
explain extended select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
305
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
306
1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	2	100.00	
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
307
2	DEPENDENT SUBQUERY	t1	system	NULL	NULL	NULL	NULL	1	100.00	
1 by brian
clean slate
308
3	DEPENDENT UNION	t5	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
309
NULL	UNION RESULT	<union2,3>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
310
Warnings:
311
Note	1276	Field or reference 'test.t2.a' of SELECT #2 was resolved in SELECT #1
312
Note	1276	Field or reference 'test.t2.a' of SELECT #3 was resolved in SELECT #1
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
313
Note	1003	select (select '2' AS `a` from `test`.`t1` where ('2' = `test`.`t2`.`a`) union select `test`.`t5`.`a` AS `a` from `test`.`t5` where (`test`.`t5`.`a` = `test`.`t2`.`a`)) AS `(select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a)`,`test`.`t2`.`a` AS `a` from `test`.`t2`
1 by brian
clean slate
314
select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2;
315
ERROR 21000: Subquery returns more than 1 row
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
316
create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq)) ENGINE=MyISAM;
317
create table t7( uq int primary key, name char(25)) ENGINE=MyISAM;
1 by brian
clean slate
318
insert into t7 values(1,"Oblastnaia bolnitsa"),(2,"Bolnitsa Krasnogo Kresta");
319
insert into t6 values (1,1),(1,2),(2,2),(1,3);
320
select * from t6 where exists (select * from t7 where uq = clinic_uq);
321
patient_uq	clinic_uq
322
1	1
323
1	2
324
2	2
325
explain extended select * from t6 where exists (select * from t7 where uq = clinic_uq);
326
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
327
1	PRIMARY	t6	ALL	NULL	NULL	NULL	NULL	4	100.00	Using where
328
2	DEPENDENT SUBQUERY	t7	eq_ref	PRIMARY	PRIMARY	4	test.t6.clinic_uq	1	100.00	Using index
329
Warnings:
330
Note	1276	Field or reference 'test.t6.clinic_uq' of SELECT #2 was resolved in SELECT #1
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
331
Note	1003	select `test`.`t6`.`patient_uq` AS `patient_uq`,`test`.`t6`.`clinic_uq` AS `clinic_uq` from `test`.`t6` where exists(select 1 AS `Not_used` from `test`.`t7` where (`test`.`t7`.`uq` = `test`.`t6`.`clinic_uq`))
1 by brian
clean slate
332
select * from t1 where a= (select a from t2,t4 where t2.b=t4.b);
333
ERROR 23000: Column 'a' in field list is ambiguous
334
drop table t1,t2,t3;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
335
CREATE TABLE t3 (a varchar(20),b char(1) NOT NULL default '0') ENGINE=MyISAM;
1 by brian
clean slate
336
INSERT INTO t3 VALUES ('W','a'),('A','c'),('J','b');
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
337
CREATE TABLE t2 (a varchar(20),b int NOT NULL default '0') ENGINE=MyISAM;
1 by brian
clean slate
338
INSERT INTO t2 VALUES ('W','1'),('A','3'),('J','2');
873.1.1 by Jay Pipes
Fixes the Field_date class to not allow any invalid input at
339
CREATE TABLE t1 (a varchar(20),b date NULL) ENGINE=MyISAM;
1 by brian
clean slate
340
INSERT INTO t1 VALUES ('W','1732-02-22'),('A','1735-10-30'),('J','1743-04-13');
341
SELECT * FROM t1 WHERE b = (SELECT MIN(b) FROM t1);
342
a	b
343
W	1732-02-22
344
SELECT * FROM t2 WHERE b = (SELECT MIN(b) FROM t2);
345
a	b
346
W	1
347
SELECT * FROM t3 WHERE b = (SELECT MIN(b) FROM t3);
348
a	b
349
W	a
350
CREATE TABLE `t8` (
383.1.28 by Brian Aker
Fix for CREATE TABLE/character sets.
351
`pseudo` varchar(35) NOT NULL default '',
352
`email` varchar(60) NOT NULL default '',
1 by brian
clean slate
353
PRIMARY KEY  (`pseudo`),
354
UNIQUE KEY `email` (`email`)
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
355
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
1 by brian
clean slate
356
INSERT INTO t8 (pseudo,email) VALUES ('joce','test');
357
INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1');
358
INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1');
359
EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce');
360
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
383.1.28 by Brian Aker
Fix for CREATE TABLE/character sets.
361
1	PRIMARY	t8	const	PRIMARY	PRIMARY	142	const	1	100.00	Using index
362
4	SUBQUERY	t8	const	PRIMARY	PRIMARY	142		1	100.00	Using index
363
2	SUBQUERY	t8	const	PRIMARY	PRIMARY	142	const	1	100.00	
364
3	SUBQUERY	t8	const	PRIMARY	PRIMARY	142		1	100.00	Using index
1 by brian
clean slate
365
Warnings:
383.1.28 by Brian Aker
Fix for CREATE TABLE/character sets.
366
Note	1003	select 'joce' AS `pseudo`,(select 'test' AS `email` from `test`.`t8` where ('joce' = (select 'joce' AS `pseudo` from `test`.`t8` where ('joce' = 'joce')))) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where ('joce' = (select 'joce' AS `pseudo` from `test`.`t8` where ('joce' = 'joce')))
1 by brian
clean slate
367
SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM
368
t8 WHERE pseudo='joce');
369
ERROR 21000: Operand should contain 1 column(s)
370
SELECT pseudo FROM t8 WHERE pseudo=(SELECT * FROM t8 WHERE
371
pseudo='joce');
372
ERROR 21000: Operand should contain 1 column(s)
373
SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce');
374
pseudo
375
joce
376
SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo LIKE '%joce%');
377
ERROR 21000: Subquery returns more than 1 row
378
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8;
379
CREATE TABLE `t1` (
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
380
`topic` bigint NOT NULL default '0',
873.1.1 by Jay Pipes
Fixes the Field_date class to not allow any invalid input at
381
`date` date NULL,
383.1.28 by Brian Aker
Fix for CREATE TABLE/character sets.
382
`pseudo` varchar(35) NOT NULL default '',
1 by brian
clean slate
383
PRIMARY KEY  (`pseudo`,`date`,`topic`),
384
KEY `topic` (`topic`)
385
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
386
INSERT INTO t1 (topic,date,pseudo) VALUES
387
('43506','2002-10-02','joce'),('40143','2002-08-03','joce');
388
EXPLAIN EXTENDED SELECT DISTINCT date FROM t1 WHERE date='2002-08-03';
389
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
383.1.28 by Brian Aker
Fix for CREATE TABLE/character sets.
390
1	SIMPLE	t1	index	NULL	PRIMARY	153	NULL	2	100.00	Using where; Using index
1 by brian
clean slate
391
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
392
Note	1003	select distinct `test`.`t1`.`date` AS `date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03')
1 by brian
clean slate
393
EXPLAIN EXTENDED SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03');
394
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
395
1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
383.1.28 by Brian Aker
Fix for CREATE TABLE/character sets.
396
2	SUBQUERY	t1	index	NULL	PRIMARY	153	NULL	2	100.00	Using where; Using index
1 by brian
clean slate
397
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
398
Note	1003	select (select distinct `test`.`t1`.`date` AS `date` from `test`.`t1` where (`test`.`t1`.`date` = '2002-08-03')) AS `(SELECT DISTINCT date FROM t1 WHERE date='2002-08-03')`
1 by brian
clean slate
399
SELECT DISTINCT date FROM t1 WHERE date='2002-08-03';
400
date
401
2002-08-03
402
SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03');
403
(SELECT DISTINCT date FROM t1 WHERE date='2002-08-03')
404
2002-08-03
405
SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 1) UNION ALL SELECT 1;
406
1
407
1
408
1
409
1
410
SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION ALL SELECT 1) UNION SELECT 1;
411
ERROR 21000: Subquery returns more than 1 row
412
EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 1);
413
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
67 by Brian Aker
First pass for removing mediumint (3 byte INT type).
414
1	PRIMARY	t1	index	NULL	topic	8	NULL	2	100.00	Using index
1 by brian
clean slate
415
2	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
416
3	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
417
NULL	UNION RESULT	<union2,3>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
418
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
419
Note	1003	select 1 AS `1` from `test`.`t1` where 1
1 by brian
clean slate
420
drop table t1;
421
CREATE TABLE `t1` (
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
422
`numeropost` bigint NOT NULL auto_increment,
423
`maxnumrep` int NOT NULL default '0',
1 by brian
clean slate
424
PRIMARY KEY  (`numeropost`),
425
UNIQUE KEY `maxnumrep` (`maxnumrep`)
426
) ENGINE=MyISAM ROW_FORMAT=FIXED;
427
INSERT INTO t1 (numeropost,maxnumrep) VALUES (40143,1),(43506,2);
428
CREATE TABLE `t2` (
429
`mot` varchar(30) NOT NULL default '',
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
430
`topic` bigint NOT NULL default '0',
873.1.1 by Jay Pipes
Fixes the Field_date class to not allow any invalid input at
431
`date` date NULL,
1 by brian
clean slate
432
`pseudo` varchar(35) NOT NULL default '',
433
PRIMARY KEY  (`mot`,`pseudo`,`date`,`topic`)
434
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
435
INSERT INTO t2 (mot,topic,date,pseudo) VALUES ('joce','40143','2002-10-22','joce'), ('joce','43506','2002-10-22','joce');
436
select numeropost as a FROM t1 GROUP BY (SELECT 1 FROM t1 HAVING a=1);
437
a
438
40143
439
SELECT numeropost,maxnumrep FROM t1 WHERE exists (SELECT 1 FROM t2 WHERE (mot='joce') AND date >= '2002-10-21' AND t1.numeropost = t2.topic) ORDER BY maxnumrep DESC LIMIT 0, 20;
440
numeropost	maxnumrep
441
43506	2
442
40143	1
443
SELECT (SELECT 1) as a FROM (SELECT 1 FROM t1 HAVING a=1) b;
444
ERROR 42S22: Unknown column 'a' in 'having clause'
445
SELECT 1 IN (SELECT 1 FROM t2 HAVING a);
446
ERROR 42S22: Unknown column 'a' in 'having clause'
447
SELECT * from t2 where topic IN (SELECT topic FROM t2 GROUP BY topic);
448
mot	topic	date	pseudo
449
joce	40143	2002-10-22	joce
450
joce	43506	2002-10-22	joce
451
SELECT * from t2 where topic IN (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100);
452
mot	topic	date	pseudo
453
SELECT * from t2 where topic IN (SELECT SUM(topic) FROM t1);
454
mot	topic	date	pseudo
455
SELECT * from t2 where topic = any (SELECT topic FROM t2 GROUP BY topic);
456
mot	topic	date	pseudo
457
joce	40143	2002-10-22	joce
458
joce	43506	2002-10-22	joce
459
SELECT * from t2 where topic = any (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100);
460
mot	topic	date	pseudo
461
SELECT * from t2 where topic = any (SELECT SUM(topic) FROM t1);
462
mot	topic	date	pseudo
463
SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic);
464
mot	topic	date	pseudo
465
SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100);
466
mot	topic	date	pseudo
467
joce	40143	2002-10-22	joce
468
joce	43506	2002-10-22	joce
469
SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) from t2;
470
mot	topic	date	pseudo	topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100)
471
joce	40143	2002-10-22	joce	1
472
joce	43506	2002-10-22	joce	1
473
SELECT * from t2 where topic = all (SELECT SUM(topic) FROM t2);
474
mot	topic	date	pseudo
475
SELECT * from t2 where topic <> any (SELECT SUM(topic) FROM t2);
476
mot	topic	date	pseudo
477
joce	40143	2002-10-22	joce
478
joce	43506	2002-10-22	joce
479
SELECT * from t2 where topic IN (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000);
480
mot	topic	date	pseudo
481
joce	40143	2002-10-22	joce
482
SELECT * from t2 where topic = any (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000);
483
mot	topic	date	pseudo
484
joce	40143	2002-10-22	joce
485
SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000);
486
mot	topic	date	pseudo
487
joce	40143	2002-10-22	joce
488
SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) from t2;
489
mot	topic	date	pseudo	topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000)
490
joce	40143	2002-10-22	joce	1
491
joce	43506	2002-10-22	joce	0
492
drop table t1,t2;
493
CREATE TABLE `t1` (
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
494
`numeropost` bigint NOT NULL auto_increment,
495
`maxnumrep` int NOT NULL default '0',
1 by brian
clean slate
496
PRIMARY KEY  (`numeropost`),
497
UNIQUE KEY `maxnumrep` (`maxnumrep`)
498
) ENGINE=MyISAM ROW_FORMAT=FIXED;
499
INSERT INTO t1 (numeropost,maxnumrep) VALUES (1,0),(2,1);
500
select numeropost as a FROM t1 GROUP BY (SELECT 1 FROM t1 HAVING a=1);
501
ERROR 21000: Subquery returns more than 1 row
502
select numeropost as a FROM t1 ORDER BY (SELECT 1 FROM t1 HAVING a=1);
503
ERROR 21000: Subquery returns more than 1 row
504
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
505
create table t1 (a int) ENGINE=MyISAM;
1 by brian
clean slate
506
insert into t1 values (1),(2),(3);
507
(select * from t1) union (select * from t1) order by (select a from t1 limit 1);
508
a
509
1
510
2
511
3
512
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
513
CREATE TABLE t1 (field char(1) NOT NULL DEFAULT 'b') ENGINE=MyISAM;
1 by brian
clean slate
514
INSERT INTO t1 VALUES ();
515
SELECT field FROM t1 WHERE 1=(SELECT 1 UNION ALL SELECT 1 FROM (SELECT 1) a HAVING field='b');
516
ERROR 21000: Subquery returns more than 1 row
517
drop table t1;
518
CREATE TABLE `t1` (
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
519
`numeropost` bigint NOT NULL default '0',
520
`numreponse` int NOT NULL auto_increment,
1 by brian
clean slate
521
`pseudo` varchar(35) NOT NULL default '',
522
PRIMARY KEY  (`numeropost`,`numreponse`),
523
UNIQUE KEY `numreponse` (`numreponse`),
524
KEY `pseudo` (`pseudo`,`numeropost`)
525
) ENGINE=MyISAM;
526
SELECT (SELECT numeropost FROM t1 HAVING numreponse=a),numreponse FROM (SELECT * FROM t1) as a;
527
ERROR 42S22: Reference 'numreponse' not supported (forward reference in item list)
528
SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=a) FROM (SELECT * FROM t1) as a;
529
ERROR 42S22: Unknown column 'a' in 'having clause'
530
SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=1) FROM (SELECT * FROM t1) as a;
531
numreponse	(SELECT numeropost FROM t1 HAVING numreponse=1)
532
INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test');
533
EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1');
534
ERROR 21000: Subquery returns more than 1 row
535
EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1';
536
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
537
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
538
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
539
Note	1003	select max(`test`.`t1`.`numreponse`) AS `MAX(numreponse)` from `test`.`t1` where multiple equal(1, `test`.`t1`.`numeropost`)
1 by brian
clean slate
540
EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM t1 WHERE numeropost='1');
541
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
67 by Brian Aker
First pass for removing mediumint (3 byte INT type).
542
1	PRIMARY	t1	const	PRIMARY,numreponse	PRIMARY	12	const,const	1	100.00	Using index
1 by brian
clean slate
543
2	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
544
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
545
Note	1003	select '3' AS `numreponse` from `test`.`t1` where 1
1 by brian
clean slate
546
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
547
CREATE TABLE t1 (a int) ENGINE=MyISAM;
1 by brian
clean slate
548
INSERT INTO t1 VALUES (1);
549
SELECT 1 FROM (SELECT a FROM t1) b HAVING (SELECT b.a)=1;
550
1
551
1
552
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
553
create table t1 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
554
create table t2 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
1 by brian
clean slate
555
insert into t1 values (0, 10),(1, 11),(2, 12);
556
insert into t2 values (1, 21),(2, 22),(3, 23);
557
select * from t1;
558
a	b
559
0	10
560
1	11
561
2	12
562
update t1 set b= (select b from t1);
563
ERROR HY000: You can't specify target table 't1' for update in FROM clause
564
update t1 set b= (select b from t2);
565
ERROR 21000: Subquery returns more than 1 row
566
update t1 set b= (select b from t2 where t1.a = t2.a);
567
select * from t1;
568
a	b
569
0	NULL
570
1	21
571
2	22
572
drop table t1, t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
573
create table t1 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
574
create table t2 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
1 by brian
clean slate
575
insert into t1 values (0, 10),(1, 11),(2, 12);
576
insert into t2 values (1, 21),(2, 12),(3, 23);
577
select * from t1;
578
a	b
579
0	10
580
1	11
581
2	12
582
select * from t1 where b = (select b from t2 where t1.a = t2.a);
583
a	b
584
2	12
585
delete from t1 where b = (select b from t1);
586
ERROR HY000: You can't specify target table 't1' for update in FROM clause
587
delete from t1 where b = (select b from t2);
588
ERROR 21000: Subquery returns more than 1 row
589
delete from t1 where b = (select b from t2 where t1.a = t2.a);
590
select * from t1;
591
a	b
592
0	10
593
1	11
594
drop table t1, t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
595
create table t11 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
596
create table t12 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
597
create table t2 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM;
1 by brian
clean slate
598
insert into t11 values (0, 10),(1, 11),(2, 12);
599
insert into t12 values (33, 10),(22, 11),(2, 12);
600
insert into t2 values (1, 21),(2, 12),(3, 23);
601
select * from t11;
602
a	b
603
0	10
604
1	11
605
2	12
606
select * from t12;
607
a	b
201 by Brian Aker
Convert default engine to Innodb
608
2	12
609
22	11
1 by brian
clean slate
610
33	10
611
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t12 where t11.a = t12.a);
612
ERROR HY000: You can't specify target table 't12' for update in FROM clause
613
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2);
614
ERROR 21000: Subquery returns more than 1 row
615
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2 where t11.a = t2.a);
616
select * from t11;
617
a	b
618
0	10
619
1	11
620
select * from t12;
621
a	b
201 by Brian Aker
Convert default engine to Innodb
622
22	11
1 by brian
clean slate
623
33	10
624
drop table t11, t12, t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
625
CREATE TABLE t1 (x int) ENGINE=MyISAM;
626
create table t2 (a int) ENGINE=MyISAM;
627
create table t3 (b int) ENGINE=MyISAM;
1 by brian
clean slate
628
insert into t2 values (1);
629
insert into t3 values (1),(2);
630
INSERT INTO t1 (x) VALUES ((SELECT x FROM t1));
631
ERROR HY000: You can't specify target table 't1' for update in FROM clause
632
INSERT INTO t1 (x) VALUES ((SELECT b FROM t3));
633
ERROR 21000: Subquery returns more than 1 row
634
INSERT INTO t1 (x) VALUES ((SELECT a FROM t2));
635
select * from t1;
636
x
637
1
638
insert into t2 values (1);
1008.1.2 by Brian Aker
Removed old DELAYED keyword from parser (plus cleaned up tests). Also
639
INSERT INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2));
1 by brian
clean slate
640
select * from t1;
641
x
642
1
643
2
644
INSERT INTO t1 (x) select (SELECT SUM(a)+1 FROM t2) FROM t2;
645
select * from t1;
646
x
647
1
648
2
649
3
650
3
651
INSERT INTO t1 (x) select (SELECT SUM(x)+2 FROM t1) FROM t2;
652
select * from t1;
653
x
654
1
655
2
656
3
657
3
658
11
659
11
1008.1.2 by Brian Aker
Removed old DELAYED keyword from parser (plus cleaned up tests). Also
660
INSERT INTO t1 (x) VALUES ((SELECT SUM(x) FROM t2));
1 by brian
clean slate
661
ERROR 42S22: Unknown column 'x' in 'field list'
1008.1.2 by Brian Aker
Removed old DELAYED keyword from parser (plus cleaned up tests). Also
662
INSERT INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2));
1 by brian
clean slate
663
select * from t1;
664
x
665
1
666
2
667
3
668
3
669
11
670
11
671
2
672
drop table t1, t2, t3;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
673
CREATE TABLE t1 (x int not null, y int, primary key (x)) ENGINE=MyISAM;
674
create table t2 (a int) ENGINE=MyISAM;
675
create table t3 (a int) ENGINE=MyISAM;
1 by brian
clean slate
676
insert into t2 values (1);
677
insert into t3 values (1),(2);
678
select * from t1;
679
x	y
680
replace into t1 (x, y) VALUES ((SELECT x FROM t1), (SELECT a+1 FROM t2));
681
ERROR HY000: You can't specify target table 't1' for update in FROM clause
682
replace into t1 (x, y) VALUES ((SELECT a FROM t3), (SELECT a+1 FROM t2));
683
ERROR 21000: Subquery returns more than 1 row
684
replace into t1 (x, y) VALUES ((SELECT a FROM t2), (SELECT a+1 FROM t2));
685
select * from t1;
686
x	y
687
1	2
688
replace into t1 (x, y) VALUES ((SELECT a FROM t2), (SELECT a+2 FROM t2));
689
select * from t1;
690
x	y
691
1	3
1008.1.2 by Brian Aker
Removed old DELAYED keyword from parser (plus cleaned up tests). Also
692
replace into t1 (x, y) VALUES ((SELECT a+3 FROM t2), (SELECT a FROM t2));
1 by brian
clean slate
693
select * from t1;
694
x	y
695
1	3
696
4	1
1008.1.2 by Brian Aker
Removed old DELAYED keyword from parser (plus cleaned up tests). Also
697
replace into t1 (x, y) VALUES ((SELECT a+3 FROM t2), (SELECT a+1 FROM t2));
1 by brian
clean slate
698
select * from t1;
699
x	y
700
1	3
701
4	2
1008.1.2 by Brian Aker
Removed old DELAYED keyword from parser (plus cleaned up tests). Also
702
replace into t1 (x, y) VALUES ((SELECT a+1 FROM t2), (SELECT a FROM t2));
1 by brian
clean slate
703
select * from t1;
704
x	y
705
1	3
201 by Brian Aker
Convert default engine to Innodb
706
2	1
1 by brian
clean slate
707
4	2
708
drop table t1, t2, t3;
709
SELECT * FROM (SELECT 1) b WHERE 1 IN (SELECT *);
710
ERROR HY000: No tables used
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
711
CREATE TABLE t2 (id int default NULL, KEY id (id)) ENGINE=MyISAM;
1 by brian
clean slate
712
INSERT INTO t2 VALUES (1),(2);
713
SELECT * FROM t2 WHERE id IN (SELECT 1);
714
id
715
1
716
EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1);
717
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
718
1	PRIMARY	t2	ref	id	id	5	const	1	100.00	Using index
719
Warnings:
720
Note	1249	Select 2 was reduced during optimization
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
721
Note	1003	select `test`.`t2`.`id` AS `id` from `test`.`t2` where (`test`.`t2`.`id` = 1)
1 by brian
clean slate
722
SELECT * FROM t2 WHERE id IN (SELECT 1 UNION SELECT 3);
723
id
724
1
725
SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1));
726
id
727
2
728
EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1));
729
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
730
1	PRIMARY	t2	ref	id	id	5	const	1	100.00	Using index
731
Warnings:
732
Note	1249	Select 3 was reduced during optimization
733
Note	1249	Select 2 was reduced during optimization
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
734
Note	1003	select `test`.`t2`.`id` AS `id` from `test`.`t2` where (`test`.`t2`.`id` = (1 + 1))
1 by brian
clean slate
735
EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1 UNION SELECT 3);
736
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
737
1	PRIMARY	t2	index	NULL	id	5	NULL	2	100.00	Using where; Using index
738
2	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
739
3	DEPENDENT UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
740
NULL	UNION RESULT	<union2,3>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
741
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
742
Note	1003	select `test`.`t2`.`id` AS `id` from `test`.`t2` where <in_optimizer>(`test`.`t2`.`id`,<exists>(select 1 AS `1` having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(1)) union select 3 AS `3` having (<cache>(`test`.`t2`.`id`) = <ref_null_helper>(3))))
1 by brian
clean slate
743
SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 3);
744
id
745
SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 2);
746
id
747
2
748
INSERT INTO t2 VALUES ((SELECT * FROM t2));
749
ERROR HY000: You can't specify target table 't2' for update in FROM clause
750
INSERT INTO t2 VALUES ((SELECT id FROM t2));
751
ERROR HY000: You can't specify target table 't2' for update in FROM clause
752
SELECT * FROM t2;
753
id
754
1
755
2
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
756
CREATE TABLE t1 (id int default NULL, KEY id (id)) ENGINE=MyISAM;
1 by brian
clean slate
757
INSERT INTO t1 values (1),(1);
758
UPDATE t2 SET id=(SELECT * FROM t1);
759
ERROR 21000: Subquery returns more than 1 row
760
drop table t2, t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
761
create table t1 (a int) ENGINE=MyISAM;
1 by brian
clean slate
762
insert into t1 values (1),(2),(3);
763
select 1 IN (SELECT * from t1);
764
1 IN (SELECT * from t1)
765
1
766
select 10 IN (SELECT * from t1);
767
10 IN (SELECT * from t1)
768
0
769
select NULL IN (SELECT * from t1);
770
NULL IN (SELECT * from t1)
771
NULL
772
update t1 set a=NULL where a=2;
773
select 1 IN (SELECT * from t1);
774
1 IN (SELECT * from t1)
775
1
776
select 3 IN (SELECT * from t1);
777
3 IN (SELECT * from t1)
778
1
779
select 10 IN (SELECT * from t1);
780
10 IN (SELECT * from t1)
781
NULL
782
select 1 > ALL (SELECT * from t1);
783
1 > ALL (SELECT * from t1)
784
0
785
select 10 > ALL (SELECT * from t1);
786
10 > ALL (SELECT * from t1)
787
NULL
788
select 1 > ANY (SELECT * from t1);
789
1 > ANY (SELECT * from t1)
790
NULL
791
select 10 > ANY (SELECT * from t1);
792
10 > ANY (SELECT * from t1)
793
1
794
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
795
create table t1 (a varchar(20)) ENGINE=MyISAM;
1 by brian
clean slate
796
insert into t1 values ('A'),('BC'),('DEF');
797
select 'A' IN (SELECT * from t1);
798
'A' IN (SELECT * from t1)
799
1
800
select 'XYZS' IN (SELECT * from t1);
801
'XYZS' IN (SELECT * from t1)
802
0
803
select NULL IN (SELECT * from t1);
804
NULL IN (SELECT * from t1)
805
NULL
806
update t1 set a=NULL where a='BC';
807
select 'A' IN (SELECT * from t1);
808
'A' IN (SELECT * from t1)
809
1
810
select 'DEF' IN (SELECT * from t1);
811
'DEF' IN (SELECT * from t1)
812
1
813
select 'XYZS' IN (SELECT * from t1);
814
'XYZS' IN (SELECT * from t1)
815
NULL
816
select 'A' > ALL (SELECT * from t1);
817
'A' > ALL (SELECT * from t1)
818
0
819
select 'XYZS' > ALL (SELECT * from t1);
820
'XYZS' > ALL (SELECT * from t1)
821
NULL
822
select 'A' > ANY (SELECT * from t1);
823
'A' > ANY (SELECT * from t1)
824
NULL
825
select 'XYZS' > ANY (SELECT * from t1);
826
'XYZS' > ANY (SELECT * from t1)
827
1
828
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
829
create table t1 (a float) ENGINE=MyISAM;
1 by brian
clean slate
830
insert into t1 values (1.5),(2.5),(3.5);
831
select 1.5 IN (SELECT * from t1);
832
1.5 IN (SELECT * from t1)
833
1
834
select 10.5 IN (SELECT * from t1);
835
10.5 IN (SELECT * from t1)
836
0
837
select NULL IN (SELECT * from t1);
838
NULL IN (SELECT * from t1)
839
NULL
840
update t1 set a=NULL where a=2.5;
841
select 1.5 IN (SELECT * from t1);
842
1.5 IN (SELECT * from t1)
843
1
844
select 3.5 IN (SELECT * from t1);
845
3.5 IN (SELECT * from t1)
846
1
847
select 10.5 IN (SELECT * from t1);
848
10.5 IN (SELECT * from t1)
849
NULL
850
select 1.5 > ALL (SELECT * from t1);
851
1.5 > ALL (SELECT * from t1)
852
0
853
select 10.5 > ALL (SELECT * from t1);
854
10.5 > ALL (SELECT * from t1)
855
NULL
856
select 1.5 > ANY (SELECT * from t1);
857
1.5 > ANY (SELECT * from t1)
858
NULL
859
select 10.5 > ANY (SELECT * from t1);
860
10.5 > ANY (SELECT * from t1)
861
1
862
explain extended select (select a+1) from t1;
863
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
864
1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
865
Warnings:
866
Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
867
Note	1249	Select 2 was reduced during optimization
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
868
Note	1003	select (`test`.`t1`.`a` + 1) AS `(select a+1)` from `test`.`t1`
1 by brian
clean slate
869
select (select a+1) from t1;
870
(select a+1)
871
2.5
872
4.5
496.1.4 by Paul McCullagh
Changes to .result files to run both PBXT and InnoDB
873
NULL
1 by brian
clean slate
874
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
875
CREATE TABLE t1 (a int NOT NULL default '0', PRIMARY KEY  (a)) ENGINE=MyISAM;
876
CREATE TABLE t2 (a int default '0', INDEX (a)) ENGINE=MyISAM;
1 by brian
clean slate
877
INSERT INTO t1 VALUES (1),(2),(3),(4);
878
INSERT INTO t2 VALUES (1),(2),(3);
879
SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
880
a	t1.a in (select t2.a from t2)
881
1	1
882
2	1
883
3	1
884
4	0
885
explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
886
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
887
1	PRIMARY	t1	index	NULL	PRIMARY	4	NULL	4	100.00	Using index
888
2	DEPENDENT SUBQUERY	t2	index_subquery	a	a	5	func	2	100.00	Using index
889
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
890
Note	1003	select `test`.`t1`.`a` AS `a`,<in_optimizer>(`test`.`t1`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in t2 on a checking NULL having <is_not_null_test>(`test`.`t2`.`a`)))) AS `t1.a in (select t2.a from t2)` from `test`.`t1`
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
891
CREATE TABLE t3 (a int default '0') ENGINE=MyISAM;
1 by brian
clean slate
892
INSERT INTO t3 VALUES (1),(2),(3);
893
SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
894
a	t1.a in (select t2.a from t2,t3 where t3.a=t2.a)
895
1	1
896
2	1
897
3	1
898
4	0
899
explain extended SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
900
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
901
1	PRIMARY	t1	index	NULL	PRIMARY	4	NULL	4	100.00	Using index
902
2	DEPENDENT SUBQUERY	t2	ref_or_null	a	a	5	func	2	100.00	Using index
903
2	DEPENDENT SUBQUERY	t3	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
904
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
905
Note	1003	select `test`.`t1`.`a` AS `a`,<in_optimizer>(`test`.`t1`.`a`,<exists>(select 1 AS `Not_used` from `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t2`.`a`) and ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`) or isnull(`test`.`t2`.`a`))) having <is_not_null_test>(`test`.`t2`.`a`))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1`
1 by brian
clean slate
906
drop table t1,t2,t3;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
907
CREATE TABLE t1 (a int) ENGINE=MyISAM;
1 by brian
clean slate
908
EXPLAIN EXTENDED SELECT (SELECT RAND() FROM t1) FROM t1;
909
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
910
1	PRIMARY	t1	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
911
2	SUBQUERY	t1	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
1 by brian
clean slate
912
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
913
Note	1003	select (select rand() AS `RAND()` from `test`.`t1`) AS `(SELECT RAND() FROM t1)` from `test`.`t1`
1 by brian
clean slate
914
EXPLAIN EXTENDED SELECT (SELECT BENCHMARK(1,1) FROM t1) FROM t1;
915
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
916
1	PRIMARY	t1	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
917
2	SUBQUERY	t1	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
1 by brian
clean slate
918
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
919
Note	1003	select (select benchmark(1,1) AS `BENCHMARK(1,1)` from `test`.`t1`) AS `(SELECT BENCHMARK(1,1) FROM t1)` from `test`.`t1`
1 by brian
clean slate
920
drop table t1;
921
CREATE TABLE `t1` (
383.1.28 by Brian Aker
Fix for CREATE TABLE/character sets.
922
`mot` varchar(30) NOT NULL default '',
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
923
`topic` bigint NOT NULL default '0',
896.3.6 by Stewart Smith
Read Fields out of proto instead of FRM.
924
`date` date NULL DEFAULT '2009-01-20',
383.1.28 by Brian Aker
Fix for CREATE TABLE/character sets.
925
`pseudo` varchar(35) NOT NULL default '',
1 by brian
clean slate
926
PRIMARY KEY  (`mot`,`pseudo`,`date`,`topic`),
927
KEY `pseudo` (`pseudo`,`date`,`topic`),
928
KEY `topic` (`topic`)
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
929
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
1 by brian
clean slate
930
CREATE TABLE `t2` (
383.1.28 by Brian Aker
Fix for CREATE TABLE/character sets.
931
`mot` varchar(30) NOT NULL default '',
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
932
`topic` bigint NOT NULL default '0',
896.3.6 by Stewart Smith
Read Fields out of proto instead of FRM.
933
`date` date NULL default '1997-08-29',
383.1.28 by Brian Aker
Fix for CREATE TABLE/character sets.
934
`pseudo` varchar(35) NOT NULL default '',
1 by brian
clean slate
935
PRIMARY KEY  (`mot`,`pseudo`,`date`,`topic`),
936
KEY `pseudo` (`pseudo`,`date`,`topic`),
937
KEY `topic` (`topic`)
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
938
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
1 by brian
clean slate
939
CREATE TABLE `t3` (
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
940
`numeropost` bigint NOT NULL auto_increment,
941
`maxnumrep` int NOT NULL default '0',
1 by brian
clean slate
942
PRIMARY KEY  (`numeropost`),
943
UNIQUE KEY `maxnumrep` (`maxnumrep`)
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
944
) ENGINE=MyISAM;
1 by brian
clean slate
945
INSERT INTO t1 (mot, topic, pseudo) VALUES ('joce','1','joce'),('test','2','test');
946
INSERT INTO t2 (mot, topic, pseudo) VALUES ('joce','1','joce'),('test','2','test');
947
INSERT INTO t3 VALUES (1,1);
948
SELECT DISTINCT topic FROM t2 WHERE NOT EXISTS(SELECT * FROM t3 WHERE
949
numeropost=topic);
950
topic
951
2
952
select * from t1;
953
mot	topic	date	pseudo
896.3.6 by Stewart Smith
Read Fields out of proto instead of FRM.
954
joce	1	2009-01-20	joce
955
test	2	2009-01-20	test
1 by brian
clean slate
956
DELETE FROM t1 WHERE topic IN (SELECT DISTINCT topic FROM t2 WHERE NOT
957
EXISTS(SELECT * FROM t3 WHERE numeropost=topic));
958
select * from t1;
959
mot	topic	date	pseudo
896.3.6 by Stewart Smith
Read Fields out of proto instead of FRM.
960
joce	1	2009-01-20	joce
1 by brian
clean slate
961
drop table t1, t2, t3;
962
SELECT * FROM (SELECT 1 as a,(SELECT a)) a;
963
a	(SELECT a)
964
1	1
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
965
CREATE TABLE t1 ENGINE=MyISAM SELECT * FROM (SELECT 1 as a,(SELECT 1)) a;
1 by brian
clean slate
966
SHOW CREATE TABLE t1;
967
Table	Create Table
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
968
t1	CREATE TABLE `t1` (
873.2.35 by Monty Taylor
Update tests based on how Toru's latest patch changes create table statements.
969
  `a` int NOT NULL DEFAULT '0',
970
  `(SELECT 1)` int NOT NULL DEFAULT '0'
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
971
) ENGINE=MyISAM
1 by brian
clean slate
972
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
973
CREATE TABLE t1 ENGINE=MyISAM SELECT * FROM (SELECT 1 as a,(SELECT a)) a;
1 by brian
clean slate
974
SHOW CREATE TABLE t1;
975
Table	Create Table
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
976
t1	CREATE TABLE `t1` (
873.2.35 by Monty Taylor
Update tests based on how Toru's latest patch changes create table statements.
977
  `a` int NOT NULL DEFAULT '0',
978
  `(SELECT a)` int NOT NULL DEFAULT '0'
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
979
) ENGINE=MyISAM
1 by brian
clean slate
980
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
981
CREATE TABLE t1 ENGINE=MyISAM SELECT * FROM (SELECT 1 as a,(SELECT a+0)) a;
1 by brian
clean slate
982
SHOW CREATE TABLE t1;
983
Table	Create Table
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
984
t1	CREATE TABLE `t1` (
873.2.35 by Monty Taylor
Update tests based on how Toru's latest patch changes create table statements.
985
  `a` int NOT NULL DEFAULT '0',
986
  `(SELECT a+0)` int NOT NULL DEFAULT '0'
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
987
) ENGINE=MyISAM
1 by brian
clean slate
988
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
989
CREATE TABLE t1 ENGINE=MyISAM SELECT (SELECT 1 as a UNION SELECT 1+1 limit 1,1) as a;
1 by brian
clean slate
990
select * from t1;
991
a
992
2
993
SHOW CREATE TABLE t1;
994
Table	Create Table
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
995
t1	CREATE TABLE `t1` (
896.3.6 by Stewart Smith
Read Fields out of proto instead of FRM.
996
  `a` bigint NOT NULL
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
997
) ENGINE=MyISAM
1 by brian
clean slate
998
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
999
create table t1 (a int) ENGINE=MyISAM;
1 by brian
clean slate
1000
insert into t1 values (1), (2), (3);
1001
explain extended select a,(select (select rand() from t1 limit 1)  from t1 limit 1)
1002
from t1;
1003
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1004
1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
1005
2	SUBQUERY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
1006
3	SUBQUERY	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	
1007
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1008
Note	1003	select `test`.`t1`.`a` AS `a`,(select (select rand() AS `rand()` from `test`.`t1` limit 1) AS `(select rand() from t1 limit 1)` from `test`.`t1` limit 1) AS `(select (select rand() from t1 limit 1)  from t1 limit 1)` from `test`.`t1`
1 by brian
clean slate
1009
drop table t1;
1010
select t1.Continent, t2.Name, t2.Population from t1 LEFT JOIN t2 ON t1.Code = t2.Country  where t2.Population IN (select max(t2.Population) AS Population from t2, t1 where t2.Country = t1.Code group by Continent);
1011
ERROR 42S02: Table 'test.t1' doesn't exist
1012
CREATE TABLE t1 (
223 by Brian Aker
Cleanup int() work.
1013
ID int NOT NULL auto_increment,
1 by brian
clean slate
1014
name char(35) NOT NULL default '',
1015
t2 char(3) NOT NULL default '',
1016
District char(20) NOT NULL default '',
223 by Brian Aker
Cleanup int() work.
1017
Population int NOT NULL default '0',
1 by brian
clean slate
1018
PRIMARY KEY  (ID)
1019
) ENGINE=MyISAM;
1020
INSERT INTO t1 VALUES (130,'Sydney','AUS','New South Wales',3276207);
1021
INSERT INTO t1 VALUES (131,'Melbourne','AUS','Victoria',2865329);
1022
INSERT INTO t1 VALUES (132,'Brisbane','AUS','Queensland',1291117);
1023
CREATE TABLE t2 (
1024
Code char(3) NOT NULL default '',
1025
Name char(52) NOT NULL default '',
1026
Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia',
1027
Region char(26) NOT NULL default '',
1028
SurfaceArea float(10,2) NOT NULL default '0.00',
396 by Brian Aker
Cleanup tiny and small int.
1029
IndepYear int default NULL,
223 by Brian Aker
Cleanup int() work.
1030
Population int NOT NULL default '0',
1 by brian
clean slate
1031
LifeExpectancy float(3,1) default NULL,
1032
GNP float(10,2) default NULL,
1033
GNPOld float(10,2) default NULL,
1034
LocalName char(45) NOT NULL default '',
1035
GovernmentForm char(45) NOT NULL default '',
1036
HeadOfState char(60) default NULL,
223 by Brian Aker
Cleanup int() work.
1037
Capital int default NULL,
1 by brian
clean slate
1038
Code2 char(2) NOT NULL default '',
1039
PRIMARY KEY  (Code)
1040
) ENGINE=MyISAM;
1041
INSERT INTO t2 VALUES ('AUS','Australia','Oceania','Australia and New Zealand',7741220.00,1901,18886000,79.8,351182.00,392911.00,'Australia','Constitutional Monarchy, Federation','Elisabeth II',135,'AU');
1042
INSERT INTO t2 VALUES ('AZE','Azerbaijan','Asia','Middle East',86600.00,1991,7734000,62.9,4127.00,4100.00,'Azärbaycan','Federal Republic','Heydär Äliyev',144,'AZ');
1043
select t2.Continent, t1.Name, t1.Population from t2 LEFT JOIN t1 ON t2.Code = t1.t2  where t1.Population IN (select max(t1.Population) AS Population from t1, t2 where t1.t2 = t2.Code group by Continent);
1044
Continent	Name	Population
1045
Oceania	Sydney	3276207
1046
drop table t1, t2;
1047
CREATE TABLE `t1` (
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
1048
`id` bigint NOT NULL auto_increment,
383.1.28 by Brian Aker
Fix for CREATE TABLE/character sets.
1049
`pseudo` varchar(35) NOT NULL default '',
1 by brian
clean slate
1050
PRIMARY KEY  (`id`),
1051
UNIQUE KEY `pseudo` (`pseudo`)
1052
) ENGINE=MyISAM PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
1053
INSERT INTO t1 (pseudo) VALUES ('test');
1054
SELECT 0 IN (SELECT 1 FROM t1 a);
1055
0 IN (SELECT 1 FROM t1 a)
1056
0
1057
EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a);
1058
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1059
1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
1060
2	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
1061
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1062
Note	1003	select <in_optimizer>(0,<exists>(select 1 AS `Not_used` from `test`.`t1` `a` where 0)) AS `0 IN (SELECT 1 FROM t1 a)`
1 by brian
clean slate
1063
INSERT INTO t1 (pseudo) VALUES ('test1');
1064
SELECT 0 IN (SELECT 1 FROM t1 a);
1065
0 IN (SELECT 1 FROM t1 a)
1066
0
1067
EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a);
1068
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1069
1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
1070
2	DEPENDENT SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
1071
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1072
Note	1003	select <in_optimizer>(0,<exists>(select 1 AS `Not_used` from `test`.`t1` `a` where 0)) AS `0 IN (SELECT 1 FROM t1 a)`
1 by brian
clean slate
1073
drop table t1;
1074
CREATE TABLE `t1` (
223 by Brian Aker
Cleanup int() work.
1075
`i` int NOT NULL default '0',
1 by brian
clean slate
1076
PRIMARY KEY  (`i`)
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
1077
) ENGINE=MyISAM;
1 by brian
clean slate
1078
INSERT INTO t1 VALUES (1);
1079
UPDATE t1 SET i=i+(SELECT MAX(i) FROM (SELECT 1) t) WHERE i=(SELECT MAX(i));
1080
UPDATE t1 SET i=i+1 WHERE i=(SELECT MAX(i));
1081
UPDATE t1 SET t.i=i+(SELECT MAX(i) FROM (SELECT 1) t);
1082
ERROR 42S22: Unknown column 't.i' in 'field list'
1083
select * from t1;
1084
i
1085
3
1086
drop table t1;
1087
CREATE TABLE t1 (
223 by Brian Aker
Cleanup int() work.
1088
id int default NULL
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
1089
) ENGINE=MyISAM;
1 by brian
clean slate
1090
INSERT INTO t1 VALUES (1),(1),(2),(2),(1),(3);
1091
CREATE TABLE t2 (
223 by Brian Aker
Cleanup int() work.
1092
id int default NULL,
1 by brian
clean slate
1093
name varchar(15) default NULL
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
1094
) ENGINE=MyISAM;
1 by brian
clean slate
1095
INSERT INTO t2 VALUES (4,'vita'), (1,'vita'), (2,'vita'), (1,'vita');
1096
update t1, t2 set t2.name='lenka' where t2.id in (select id from t1);
1097
select * from t2;
1098
id	name
1099
4	vita
1100
1	lenka
1101
2	lenka
1102
1	lenka
1103
drop table t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1104
create table t1 (a int, unique index indexa (a)) ENGINE=MyISAM;
1 by brian
clean slate
1105
insert into t1 values (-1), (-4), (-2), (NULL);
1106
select -10 IN (select a from t1 FORCE INDEX (indexa));
1107
-10 IN (select a from t1 FORCE INDEX (indexa))
1108
NULL
1109
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1110
create table t1 (id int not null auto_increment primary key, salary int, key(salary)) ENGINE=MyISAM;
1 by brian
clean slate
1111
insert into t1 (salary) values (100),(1000),(10000),(10),(500),(5000),(50000);
1112
explain extended SELECT id FROM t1 where salary = (SELECT MAX(salary) FROM t1);
1113
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1114
1	PRIMARY	t1	ref	salary	salary	5	const	1	100.00	Using where
1 by brian
clean slate
1115
2	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
1116
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1117
Note	1003	select `test`.`t1`.`id` AS `id` from `test`.`t1` where (`test`.`t1`.`salary` = (select max(`test`.`t1`.`salary`) AS `MAX(salary)` from `test`.`t1`))
1 by brian
clean slate
1118
drop table t1;
1119
CREATE TABLE t1 (
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
1120
ID int NOT NULL auto_increment,
1121
SUB_ID int NOT NULL default '0',
1122
REF_ID int default NULL,
1123
REF_SUB int default '0',
1 by brian
clean slate
1124
PRIMARY KEY (ID,SUB_ID),
1125
UNIQUE KEY t1_PK (ID,SUB_ID),
1126
KEY t1_FK (REF_ID,REF_SUB),
1127
KEY t1_REFID (REF_ID)
377.1.3 by Brian Aker
Remove a few character sets/fix some tests.
1128
) ENGINE=MyISAM;
1 by brian
clean slate
1129
INSERT INTO t1 VALUES (1,0,NULL,NULL),(2,0,NULL,NULL);
1130
SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2);
1131
REF_ID
1132
DROP TABLE t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1133
create table t1 (a int, b int) ENGINE=MyISAM;
1134
create table t2 (a int, b int) ENGINE=MyISAM;
1 by brian
clean slate
1135
insert into t1 values (1,0), (2,0), (3,0);
1136
insert into t2 values (1,1), (2,1), (3,1), (2,2);
1137
update ignore t1 set b=(select b from t2 where t1.a=t2.a);
1138
Warnings:
1139
Error	1242	Subquery returns more than 1 row
1140
select * from t1;
1141
a	b
1142
1	1
1143
2	NULL
1144
3	1
1145
drop table t1, t2;
1146
CREATE TABLE `t1` (
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
1147
`id` bigint NOT NULL auto_increment,
1 by brian
clean slate
1148
`pseudo` varchar(35) NOT NULL default '',
1149
`email` varchar(60) NOT NULL default '',
1150
PRIMARY KEY  (`id`),
1151
UNIQUE KEY `email` (`email`),
1152
UNIQUE KEY `pseudo` (`pseudo`)
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
1153
) ENGINE=MyISAM PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
1 by brian
clean slate
1154
INSERT INTO t1 (id,pseudo,email) VALUES (1,'test','test'),(2,'test1','test1');
1155
SELECT pseudo as a, pseudo as b FROM t1 GROUP BY (SELECT a) ORDER BY (SELECT id*1);
1156
a	b
1157
test	test
1158
test1	test1
1159
drop table if exists t1;
1160
(SELECT 1 as a) UNION (SELECT 1) ORDER BY (SELECT a+0);
1161
a
1162
1
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1163
create table t1 (a int not null, b int, primary key (a)) ENGINE=MyISAM;
1164
create table t2 (a int not null, primary key (a)) ENGINE=MyISAM;
1165
create table t3 (a int not null, b int, primary key (a)) ENGINE=MyISAM;
1 by brian
clean slate
1166
insert into t1 values (1,10), (2,20), (3,30),  (4,40);
1167
insert into t2 values (2), (3), (4), (5);
1168
insert into t3 values (10,3), (20,4), (30,5);
1169
select * from t2 where t2.a in (select a from t1);
1170
a
1171
2
1172
3
1173
4
1174
explain extended select * from t2 where t2.a in (select a from t1);
1175
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1176
1	PRIMARY	t2	index	PRIMARY	PRIMARY	4	NULL	4	100.00	Using index
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1177
1	PRIMARY	t1	index	PRIMARY	PRIMARY	4	NULL	4	75.00	Using where; Using index; Using join buffer
1 by brian
clean slate
1178
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1179
Note	1003	select `test`.`t2`.`a` AS `a` from (`test`.`t1`) join `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`)
1 by brian
clean slate
1180
select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
1181
a
1182
2
1183
4
1184
explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
1185
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1186
1	PRIMARY	t2	index	PRIMARY	PRIMARY	4	NULL	4	100.00	Using index
1187
1	PRIMARY	t1	ALL	PRIMARY	NULL	NULL	NULL	4	75.00	Using where; Using join buffer
1188
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1189
Note	1003	select `test`.`t2`.`a` AS `a` from (`test`.`t1`) join `test`.`t2` where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` <> 30))
1 by brian
clean slate
1190
select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
1191
a
1192
2
1193
3
1194
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
1195
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1196
1	PRIMARY	t2	index	PRIMARY	PRIMARY	4	NULL	4	100.00	Using index
1197
1	PRIMARY	t1	ALL	PRIMARY	NULL	NULL	NULL	4	75.00	Using where; Using join buffer
1198
1	PRIMARY	t3	eq_ref	PRIMARY	PRIMARY	4	test.t1.b	1	100.00	Using index
1199
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1200
Note	1003	select `test`.`t2`.`a` AS `a` from (`test`.`t1` join `test`.`t3`) join `test`.`t2` where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t3`.`a` = `test`.`t1`.`b`))
1 by brian
clean slate
1201
drop table t1, t2, t3;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1202
create table t1 (a int, b int, index a (a,b)) ENGINE=MyISAM;
1203
create table t2 (a int, index a (a)) ENGINE=MyISAM;
1204
create table t3 (a int, b int, index a (a)) ENGINE=MyISAM;
1 by brian
clean slate
1205
insert into t1 values (1,10), (2,20), (3,30), (4,40);
1206
insert into t2 values (2), (3), (4), (5);
1207
insert into t3 values (10,3), (20,4), (30,5);
1208
select * from t2 where t2.a in (select a from t1);
1209
a
1210
2
1211
3
1212
4
1213
explain extended select * from t2 where t2.a in (select a from t1);
1214
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1215
1	PRIMARY	t2	index	a	a	5	NULL	4	100.00	Using index
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1216
1	PRIMARY	t1	ref	a	a	5	test.t2.a	101	100.00	Using index; FirstMatch(t2)
1 by brian
clean slate
1217
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1218
Note	1003	select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where (`test`.`t1`.`a` = `test`.`t2`.`a`)
1 by brian
clean slate
1219
select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
1220
a
1221
2
1222
4
1223
explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
1224
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1225
1	PRIMARY	t2	index	a	a	5	NULL	4	100.00	Using index
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1226
1	PRIMARY	t1	ref	a	a	5	test.t2.a	101	100.00	Using where; Using index; FirstMatch(t2)
1 by brian
clean slate
1227
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1228
Note	1003	select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` <> 30))
1 by brian
clean slate
1229
select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
1230
a
1231
2
1232
3
1233
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
1234
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1235
1	PRIMARY	t2	index	a	a	5	NULL	4	100.00	Using index; Start temporary
1236
1	PRIMARY	t1	ref	a	a	5	test.t2.a	101	100.00	Using index; FirstMatch(t2)
1237
1	PRIMARY	t3	index	a	a	5	NULL	3	100.00	Using where; Using index; End temporary; Using join buffer
1 by brian
clean slate
1238
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1239
Note	1003	select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t3`.`a` = `test`.`t1`.`b`))
1 by brian
clean slate
1240
insert into t1 values (3,31);
1241
select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
1242
a
1243
2
1244
3
1245
4
1246
select * from t2 where t2.a in (select a from t1 where t1.b <> 30 and t1.b <> 31);
1247
a
1248
2
1249
4
1250
explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
1251
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1252
1	PRIMARY	t2	index	a	a	5	NULL	4	100.00	Using index
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1253
1	PRIMARY	t1	ref	a	a	5	test.t2.a	101	100.00	Using where; Using index; FirstMatch(t2)
1 by brian
clean slate
1254
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1255
Note	1003	select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) where ((`test`.`t1`.`a` = `test`.`t2`.`a`) and (`test`.`t1`.`b` <> 30))
1 by brian
clean slate
1256
drop table t1, t2, t3;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1257
create table t1 (a int, b int) ENGINE=MyISAM;
1258
create table t2 (a int, b int) ENGINE=MyISAM;
1259
create table t3 (a int, b int) ENGINE=MyISAM;
1 by brian
clean slate
1260
insert into t1 values (0,100),(1,2), (1,3), (2,2), (2,7), (2,-1), (3,10);
1261
insert into t2 values (0,0), (1,1), (2,1), (3,1), (4,1);
1262
insert into t3 values (3,3), (2,2), (1,1);
1263
select a,(select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) from t3;
1264
a	(select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1)
1265
3	1
1266
2	2
1267
1	2
1268
drop table t1,t2,t3;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1269
create table t1 (s1 int) ENGINE=MyISAM;
1270
create table t2 (s1 int) ENGINE=MyISAM;
1 by brian
clean slate
1271
insert into t1 values (1);
1272
insert into t2 values (1);
1273
select * from t1 where exists (select s1 from t2 having max(t2.s1)=t1.s1);
1274
s1
1275
1
1276
drop table t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1277
create table t1 (s1 int) ENGINE=MyISAM;
1278
create table t2 (s1 int) ENGINE=MyISAM;
1 by brian
clean slate
1279
insert into t1 values (1);
1280
insert into t2 values (1);
1281
update t1 set  s1 = s1 + 1 where 1 = (select x.s1 as A from t2 WHERE t2.s1 > t1.s1 order by A);
1282
ERROR 42S22: Unknown column 'x.s1' in 'field list'
1283
DROP TABLE t1, t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1284
create table t1(toid int,rd int) ENGINE=MyISAM;
1285
create table t2(userid int,pmnew int,pmtotal int) ENGINE=MyISAM;
1 by brian
clean slate
1286
insert into t2 values(1,0,0),(2,0,0);
1287
insert into t1 values(1,0),(1,0),(1,0),(1,12),(1,15),(1,123),(1,12312),(1,12312),(1,123),(2,0),(2,0),(2,1),(2,2);
1288
select userid,pmtotal,pmnew, (select count(rd) from t1 where toid=t2.userid) calc_total, (select count(rd) from t1 where rd=0 and toid=t2.userid) calc_new from t2 where userid in (select distinct toid from t1);
1289
userid	pmtotal	pmnew	calc_total	calc_new
1290
1	0	0	9	3
1291
2	0	0	4	2
1292
drop table t1, t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1293
create table t1 (s1 char(5)) ENGINE=MyISAM;
1 by brian
clean slate
1294
select (select 'a','b' from t1 union select 'a','b' from t1) from t1;
1295
ERROR 21000: Operand should contain 1 column(s)
1296
insert into t1 values ('tttt');
1297
select * from t1 where ('a','b')=(select 'a','b' from t1 union select 'a','b' from t1);
1298
s1
1299
tttt
1300
explain extended (select * from t1);
1301
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1302
1	SIMPLE	t1	system	NULL	NULL	NULL	NULL	1	100.00	
1 by brian
clean slate
1303
Warnings:
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1304
Note	1003	(select 'tttt' AS `s1` from `test`.`t1`)
1 by brian
clean slate
1305
(select * from t1);
1306
s1
1307
tttt
1308
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1309
create table t1 (s1 char(5), index s1(s1)) ENGINE=MyISAM;
1310
create table t2 (s1 char(5), index s1(s1)) ENGINE=MyISAM;
1 by brian
clean slate
1311
insert into t1 values ('a1'),('a2'),('a3');
1312
insert into t2 values ('a1'),('a2');
1313
select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
1314
s1	s1 NOT IN (SELECT s1 FROM t2)
1315
a1	0
1316
a2	0
1317
a3	1
1318
select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
1319
s1	s1 = ANY (SELECT s1 FROM t2)
1320
a1	1
1321
a2	1
1322
a3	0
1323
select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
1324
s1	s1 <> ALL (SELECT s1 FROM t2)
1325
a1	0
1326
a2	0
1327
a3	1
1328
select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1;
1329
s1	s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')
1330
a1	0
1331
a2	1
1332
a3	1
1333
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
1334
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
383.1.16 by Brian Aker
Force client communication into UTF8
1335
1	PRIMARY	t1	index	NULL	s1	23	NULL	3	100.00	Using index
1336
2	DEPENDENT SUBQUERY	t2	index_subquery	s1	s1	23	func	2	100.00	Using index; Full scan on NULL key
1 by brian
clean slate
1337
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1338
Note	1003	select `test`.`t1`.`s1` AS `s1`,(not(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
1 by brian
clean slate
1339
explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
1340
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
383.1.16 by Brian Aker
Force client communication into UTF8
1341
1	PRIMARY	t1	index	NULL	s1	23	NULL	3	100.00	Using index
1342
2	DEPENDENT SUBQUERY	t2	index_subquery	s1	s1	23	func	2	100.00	Using index; Full scan on NULL key
1 by brian
clean slate
1343
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1344
Note	1003	select `test`.`t1`.`s1` AS `s1`,<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
1 by brian
clean slate
1345
explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
1346
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
383.1.16 by Brian Aker
Force client communication into UTF8
1347
1	PRIMARY	t1	index	NULL	s1	23	NULL	3	100.00	Using index
1348
2	DEPENDENT SUBQUERY	t2	index_subquery	s1	s1	23	func	2	100.00	Using index; Full scan on NULL key
1 by brian
clean slate
1349
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1350
Note	1003	select `test`.`t1`.`s1` AS `s1`,(not(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
1 by brian
clean slate
1351
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1;
1352
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
383.1.16 by Brian Aker
Force client communication into UTF8
1353
1	PRIMARY	t1	index	NULL	s1	23	NULL	3	100.00	Using index
1354
2	DEPENDENT SUBQUERY	t2	index_subquery	s1	s1	23	func	2	100.00	Using index; Using where; Full scan on NULL key
1 by brian
clean slate
1355
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1356
Note	1003	select `test`.`t1`.`s1` AS `s1`,(not(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL where (`test`.`t2`.`s1` < 'a2') having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))))) AS `s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')` from `test`.`t1`
1 by brian
clean slate
1357
drop table t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1358
create table t2 (a int, b int) ENGINE=MyISAM;
1359
create table t3 (a int) ENGINE=MyISAM;
1 by brian
clean slate
1360
insert into t3 values (6),(7),(3);
1361
select * from t3 where a >= all (select b from t2);
1362
a
1363
6
1364
7
1365
3
1366
explain extended select * from t3 where a >= all (select b from t2);
1367
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1368
1	PRIMARY	t3	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1369
2	SUBQUERY	t2	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
1 by brian
clean slate
1370
Warnings:
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1371
Note	1003	select `test`.`t3`.`a` AS `a` from `test`.`t3` where <not>((`test`.`t3`.`a` < (select max('0') from `test`.`t2`)))
1 by brian
clean slate
1372
select * from t3 where a >= some (select b from t2);
1373
a
1374
explain extended select * from t3 where a >= some (select b from t2);
1375
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1376
1	PRIMARY	t3	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1377
2	SUBQUERY	t2	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
1 by brian
clean slate
1378
Warnings:
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1379
Note	1003	select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>((`test`.`t3`.`a` >= (select min('0') from `test`.`t2`)))
1 by brian
clean slate
1380
select * from t3 where a >= all (select b from t2 group by 1);
1381
a
1382
6
1383
7
1384
3
1385
explain extended select * from t3 where a >= all (select b from t2 group by 1);
1386
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1387
1	PRIMARY	t3	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1388
2	SUBQUERY	t2	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
1 by brian
clean slate
1389
Warnings:
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1390
Note	1003	select `test`.`t3`.`a` AS `a` from `test`.`t3` where <not>((`test`.`t3`.`a` < <max>(select '0' AS `b` from `test`.`t2` group by 1)))
1 by brian
clean slate
1391
select * from t3 where a >= some (select b from t2 group by 1);
1392
a
1393
explain extended select * from t3 where a >= some (select b from t2 group by 1);
1394
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1395
1	PRIMARY	t3	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1396
2	SUBQUERY	t2	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
1 by brian
clean slate
1397
Warnings:
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1398
Note	1003	select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>((`test`.`t3`.`a` >= <min>(select '0' AS `b` from `test`.`t2` group by 1)))
1 by brian
clean slate
1399
select * from t3 where NULL >= any (select b from t2);
1400
a
1401
explain extended select * from t3 where NULL >= any (select b from t2);
1402
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1403
1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1404
2	SUBQUERY	t2	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
1 by brian
clean slate
1405
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1406
Note	1003	select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
1 by brian
clean slate
1407
select * from t3 where NULL >= any (select b from t2 group by 1);
1408
a
1409
explain extended select * from t3 where NULL >= any (select b from t2 group by 1);
1410
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1411
1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1412
2	SUBQUERY	t2	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
1 by brian
clean slate
1413
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1414
Note	1003	select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
1 by brian
clean slate
1415
select * from t3 where NULL >= some (select b from t2);
1416
a
1417
explain extended select * from t3 where NULL >= some (select b from t2);
1418
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1419
1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1420
2	SUBQUERY	t2	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
1 by brian
clean slate
1421
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1422
Note	1003	select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
1 by brian
clean slate
1423
select * from t3 where NULL >= some (select b from t2 group by 1);
1424
a
1425
explain extended select * from t3 where NULL >= some (select b from t2 group by 1);
1426
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1427
1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1428
2	SUBQUERY	t2	system	NULL	NULL	NULL	NULL	0	0.00	const row not found
1 by brian
clean slate
1429
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1430
Note	1003	select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
1 by brian
clean slate
1431
insert into t2 values (2,2), (2,1), (3,3), (3,1);
1432
select * from t3 where a > all (select max(b) from t2 group by a);
1433
a
1434
6
1435
7
1436
explain extended select * from t3 where a > all (select max(b) from t2 group by a);
1437
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1438
1	PRIMARY	t3	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
1439
2	SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	4	100.00	Using temporary; Using filesort
1440
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1441
Note	1003	select `test`.`t3`.`a` AS `a` from `test`.`t3` where <not>((`test`.`t3`.`a` <= <max>(select max(`test`.`t2`.`b`) AS `max(b)` from `test`.`t2` group by `test`.`t2`.`a`)))
1 by brian
clean slate
1442
drop table t2, t3;
873.1.2 by Jay Pipes
Fixed Field_datetime to never accept any bad datetimes as a string. This broke
1443
CREATE TABLE `t1` ( `id` bigint NOT NULL auto_increment, `taskid` bigint NOT NULL default '0', `dbid` int NOT NULL default '0', `create_date` datetime, `last_update` datetime, PRIMARY KEY  (`id`)) ENGINE=MyISAM AUTO_INCREMENT=3 ;
1 by brian
clean slate
1444
INSERT INTO `t1` (`id`, `taskid`, `dbid`, `create_date`,`last_update`) VALUES (1, 1, 15, '2003-09-29 10:31:36', '2003-09-29 10:31:36'), (2, 1, 21, now(), now());
396 by Brian Aker
Cleanup tiny and small int.
1445
CREATE TABLE `t2` (`db_id` int NOT NULL auto_increment,`name` varchar(200) NOT NULL default '',`primary_uid` int NOT NULL default '0',`secondary_uid` int NOT NULL default '0',PRIMARY KEY  (`db_id`),UNIQUE KEY `name_2` (`name`)) ENGINE=MyISAM AUTO_INCREMENT=2147483647;
1 by brian
clean slate
1446
INSERT INTO `t2` (`db_id`, `name`, `primary_uid`, `secondary_uid`) VALUES (18, 'Not Set 1', 0, 0),(19, 'Valid', 1, 2),(20, 'Valid 2', 1, 2),(21, 'Should Not Return', 1, 2),(26, 'Not Set 2', 0, 0),(-1, 'ALL DB\'S', 0, 0);
396 by Brian Aker
Cleanup tiny and small int.
1447
CREATE TABLE `t3` (`taskgenid` bigint NOT NULL auto_increment,`dbid` int NOT NULL default '0',`taskid` int NOT NULL default '0',`mon` int NOT NULL default '1',`tues` int NOT NULL default '1',`wed` int NOT NULL default '1',`thur` int NOT NULL default '1',`fri` int NOT NULL default '1',`sat` int NOT NULL default '0',`sun` int NOT NULL default '0',`how_often` int NOT NULL default '1',`userid` int NOT NULL default '0',`active` int NOT NULL default '1',PRIMARY KEY  (`taskgenid`)) ENGINE=MyISAM AUTO_INCREMENT=2 ;
1 by brian
clean slate
1448
INSERT INTO `t3` (`taskgenid`, `dbid`, `taskid`, `mon`, `tues`,`wed`, `thur`, `fri`, `sat`, `sun`, `how_often`, `userid`, `active`) VALUES (1,-1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1);
396 by Brian Aker
Cleanup tiny and small int.
1449
CREATE TABLE `t4` (`task_id` int NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM;
1 by brian
clean slate
1450
INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status');
1451
select  dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') from t3 a, t2 b, t4  WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid;
1452
dbid	name	(date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01')
1453
-1	Valid	1
1454
-1	Valid 2	1
1455
-1	Should Not Return	0
1456
SELECT dbid, name FROM t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND ((date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01')) AND t4.task_id = taskid;
1457
dbid	name
1458
-1	Valid
1459
-1	Valid 2
1460
drop table t1,t2,t3,t4;
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
1461
CREATE TABLE t1 (id int default NULL) ENGINE=MyISAM;
1 by brian
clean slate
1462
INSERT INTO t1 VALUES (1),(5);
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
1463
CREATE TABLE t2 (id int default NULL) ENGINE=MyISAM;
1 by brian
clean slate
1464
INSERT INTO t2 VALUES (2),(6);
1465
select * from t1 where (1,2,6) in (select * from t2);
1466
ERROR 21000: Operand should contain 3 column(s)
1467
DROP TABLE t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1468
create table t1 (s1 char) ENGINE=MyISAM;
1 by brian
clean slate
1469
insert into t1 values ('e');
1470
select * from t1 where 'f' > any (select s1 from t1);
1471
s1
1472
e
1473
select * from t1 where 'f' > any (select s1 from t1 union select s1 from t1);
1474
s1
1475
e
1476
explain extended select * from t1 where 'f' > any (select s1 from t1 union select s1 from t1);
1477
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1478
1	PRIMARY	t1	system	NULL	NULL	NULL	NULL	1	100.00	
1479
2	SUBQUERY	t1	system	NULL	NULL	NULL	NULL	1	100.00	
1480
3	UNION	t1	system	NULL	NULL	NULL	NULL	1	100.00	
1 by brian
clean slate
1481
NULL	UNION RESULT	<union2,3>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
1482
Warnings:
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1483
Note	1003	select 'e' AS `s1` from `test`.`t1` where 1
1 by brian
clean slate
1484
drop table t1;
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
1485
CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM;
1 by brian
clean slate
1486
INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874');
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
1487
CREATE TABLE t2 (code char(5) NOT NULL default '',UNIQUE KEY code (code)) ENGINE=MyISAM;
1 by brian
clean slate
1488
INSERT INTO t2 VALUES ('1'),('1226'),('1245'),('1862'),('18623'),('1874'),('1967'),('6');
1489
select c.number as phone,(select p.code from t2 p where c.number like concat(p.code, '%') order by length(p.code) desc limit 1) as code from t1 c;
1490
phone	code
1491
69294728265	6
1492
18621828126	1862
1493
89356874041	NULL
1494
95895001874	NULL
1495
drop table t1, t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1496
create table t1 (s1 int) ENGINE=MyISAM;
1497
create table t2 (s1 int) ENGINE=MyISAM;
1 by brian
clean slate
1498
select * from t1 where (select count(*) from t2 where t1.s2) = 1;
1499
ERROR 42S22: Unknown column 't1.s2' in 'where clause'
1500
select * from t1 where (select count(*) from t2 group by t1.s2) = 1;
1501
ERROR 42S22: Unknown column 't1.s2' in 'group statement'
1502
select count(*) from t2 group by t1.s2;
1503
ERROR 42S22: Unknown column 't1.s2' in 'group statement'
1504
drop table t1, t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1505
CREATE TABLE t1(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC VARCHAR(20) DEFAULT NULL,PRIMARY KEY (COLA, COLB)) ENGINE=MyISAM;
1506
CREATE TABLE t2(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC CHAR(1) NOT NULL,PRIMARY KEY (COLA)) ENGINE=MyISAM;
1 by brian
clean slate
1507
INSERT INTO t1 VALUES (1,1,'1A3240'), (1,2,'4W2365');
1508
INSERT INTO t2 VALUES (100, 200, 'C');
1509
SELECT DISTINCT COLC FROM t1 WHERE COLA = (SELECT COLA FROM t2 WHERE COLB = 200 AND COLC ='C' LIMIT 1);
1510
COLC
1511
DROP TABLE t1, t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1512
CREATE TABLE t1 (a int) ENGINE=MyISAM;
1 by brian
clean slate
1513
INSERT INTO t1 VALUES (1),(1),(1),(1),(1),(2),(3),(4),(5);
1514
SELECT DISTINCT (SELECT a) FROM t1 LIMIT 100;
1515
(SELECT a)
1516
1
1517
2
1518
3
1519
4
1520
5
1521
DROP TABLE t1;
1522
CREATE TABLE `t1` (
223 by Brian Aker
Cleanup int() work.
1523
`id` int NOT NULL auto_increment,
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
1524
`id_cns` int NOT NULL default '0',
1 by brian
clean slate
1525
`tipo` enum('','UNO','DUE') NOT NULL default '',
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
1526
`anno_dep` int NOT NULL default '0',
1527
`particolare` bigint NOT NULL default '0',
1528
`generale` bigint NOT NULL default '0',
1529
`bis` int NOT NULL default '0',
1 by brian
clean slate
1530
PRIMARY KEY  (`id`),
1531
UNIQUE KEY `idx_cns_gen_anno` (`anno_dep`,`id_cns`,`generale`,`particolare`),
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1532
UNIQUE KEY `idx_cns_par_anno` (`id_cns`,`anno_dep`,`tipo`,`particolare`,`bis`))
1533
ENGINE=MyISAM;
1 by brian
clean slate
1534
INSERT INTO `t1` VALUES (1,16,'UNO',1987,2048,9681,0),(2,50,'UNO',1987,1536,13987,0),(3,16,'UNO',1987,2432,14594,0),(4,16,'UNO',1987,1792,13422,0),(5,16,'UNO',1987,1025,10240,0),(6,16,'UNO',1987,1026,7089,0);
1535
CREATE TABLE `t2` (
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
1536
`id` int NOT NULL auto_increment,
1537
`max_anno_dep` int NOT NULL default '0',
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1538
PRIMARY KEY  (`id`)) ENGINE=MyISAM;
1 by brian
clean slate
1539
INSERT INTO `t2` VALUES (16,1987),(50,1990),(51,1990);
1540
SELECT cns.id, cns.max_anno_dep, cns.max_anno_dep = (SELECT s.anno_dep FROM t1 AS s WHERE s.id_cns = cns.id ORDER BY s.anno_dep DESC LIMIT 1) AS PIPPO FROM t2 AS cns;
1541
id	max_anno_dep	PIPPO
1542
16	1987	1
1543
50	1990	0
1544
51	1990	NULL
1545
DROP TABLE t1, t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1546
create table t1 (a int) ENGINE=MyISAM;
1 by brian
clean slate
1547
insert into t1 values (1), (2), (3);
1548
SET SQL_SELECT_LIMIT=1;
1549
select sum(a) from (select * from t1) as a;
1550
sum(a)
1551
6
1552
select 2 in (select * from t1);
1553
2 in (select * from t1)
1554
1
1555
SET SQL_SELECT_LIMIT=default;
1556
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1557
CREATE TABLE t1 (a int, b int, INDEX (a)) ENGINE=MyISAM;
1 by brian
clean slate
1558
INSERT INTO t1 VALUES (1, 1), (1, 2), (1, 3);
1559
SELECT * FROM t1 WHERE a = (SELECT MAX(a) FROM t1 WHERE a = 1) ORDER BY b;
1560
a	b
1561
1	1
1562
1	2
1563
1	3
1564
DROP TABLE t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1565
create table t1(val varchar(10)) ENGINE=MyISAM;
1 by brian
clean slate
1566
insert into t1 values ('aaa'), ('bbb'),('eee'),('mmm'),('ppp');
1567
select count(*) from t1 as w1 where w1.val in (select w2.val from t1 as w2 where w2.val like 'm%') and w1.val in (select w3.val from t1 as w3 where w3.val like 'e%');
1568
count(*)
1569
0
1570
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1571
create table t1 (id int not null, text varchar(20) not null default '', primary key (id)) ENGINE=MyISAM;
1 by brian
clean slate
1572
insert into t1 (id, text) values (1, 'text1'), (2, 'text2'), (3, 'text3'), (4, 'text4'), (5, 'text5'), (6, 'text6'), (7, 'text7'), (8, 'text8'), (9, 'text9'), (10, 'text10'), (11, 'text11'), (12, 'text12');
1573
select * from t1 where id not in (select id from t1 where id < 8);
1574
id	text
1575
8	text8
1576
9	text9
1577
10	text10
1578
11	text11
1579
12	text12
1580
select * from t1 as tt where not exists (select id from t1 where id < 8 and (id = tt.id or id is null) having id is not null);
1581
id	text
1582
8	text8
1583
9	text9
1584
10	text10
1585
11	text11
1586
12	text12
1587
explain extended select * from t1 where id not in (select id from t1 where id < 8);
1588
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1589
1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	12	100.00	Using where
1590
2	DEPENDENT SUBQUERY	t1	unique_subquery	PRIMARY	PRIMARY	4	func	1	100.00	Using index; Using where
1591
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1592
Note	1003	select `test`.`t1`.`id` AS `id`,`test`.`t1`.`text` AS `text` from `test`.`t1` where (not(<in_optimizer>(`test`.`t1`.`id`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`id`) in t1 on PRIMARY where ((`test`.`t1`.`id` < 8) and (<cache>(`test`.`t1`.`id`) = `test`.`t1`.`id`)))))))
1 by brian
clean slate
1593
explain extended select * from t1 as tt where not exists (select id from t1 where id < 8 and (id = tt.id or id is null) having id is not null);
1594
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1595
1	PRIMARY	tt	ALL	NULL	NULL	NULL	NULL	12	100.00	Using where
1596
2	DEPENDENT SUBQUERY	t1	eq_ref	PRIMARY	PRIMARY	4	test.tt.id	1	100.00	Using where; Using index
1597
Warnings:
1598
Note	1276	Field or reference 'test.tt.id' of SELECT #2 was resolved in SELECT #1
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1599
Note	1003	select `test`.`tt`.`id` AS `id`,`test`.`tt`.`text` AS `text` from `test`.`t1` `tt` where (not(exists(select `test`.`t1`.`id` AS `id` from `test`.`t1` where ((`test`.`t1`.`id` < 8) and (`test`.`t1`.`id` = `test`.`tt`.`id`)) having (`test`.`t1`.`id` is not null))))
1 by brian
clean slate
1600
insert into t1 (id, text) values (1000, 'text1000'), (1001, 'text1001');
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1601
create table t2 (id int not null, text varchar(20) not null default '', primary key (id)) ENGINE=MyISAM;
1 by brian
clean slate
1602
insert into t2 (id, text) values (1, 'text1'), (2, 'text2'), (3, 'text3'), (4, 'text4'), (5, 'text5'), (6, 'text6'), (7, 'text7'), (8, 'text8'), (9, 'text9'), (10, 'text10'), (11, 'text1'), (12, 'text2'), (13, 'text3'), (14, 'text4'), (15, 'text5'), (16, 'text6'), (17, 'text7'), (18, 'text8'), (19, 'text9'), (20, 'text10'),(21, 'text1'), (22, 'text2'), (23, 'text3'), (24, 'text4'), (25, 'text5'), (26, 'text6'), (27, 'text7'), (28, 'text8'), (29, 'text9'), (30, 'text10'), (31, 'text1'), (32, 'text2'), (33, 'text3'), (34, 'text4'), (35, 'text5'), (36, 'text6'), (37, 'text7'), (38, 'text8'), (39, 'text9'), (40, 'text10'), (41, 'text1'), (42, 'text2'), (43, 'text3'), (44, 'text4'), (45, 'text5'), (46, 'text6'), (47, 'text7'), (48, 'text8'), (49, 'text9'), (50, 'text10');
1603
select * from t1 a left join t2 b on (a.id=b.id or b.id is null) join t1 c on (if(isnull(b.id), 1000, b.id)=c.id);
1604
id	text	id	text	id	text
1605
1	text1	1	text1	1	text1
1606
2	text2	2	text2	2	text2
1607
3	text3	3	text3	3	text3
1608
4	text4	4	text4	4	text4
1609
5	text5	5	text5	5	text5
1610
6	text6	6	text6	6	text6
1611
7	text7	7	text7	7	text7
1612
8	text8	8	text8	8	text8
1613
9	text9	9	text9	9	text9
1614
10	text10	10	text10	10	text10
1615
11	text11	11	text1	11	text11
1616
12	text12	12	text2	12	text12
1617
1000	text1000	NULL	NULL	1000	text1000
1618
1001	text1001	NULL	NULL	1000	text1000
1619
explain extended select * from t1 a left join t2 b on (a.id=b.id or b.id is null) join t1 c on (if(isnull(b.id), 1000, b.id)=c.id);
1620
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1621
1	SIMPLE	a	ALL	NULL	NULL	NULL	NULL	14	100.00	
1622
1	SIMPLE	b	eq_ref	PRIMARY	PRIMARY	4	test.a.id	2	100.00	
201 by Brian Aker
Convert default engine to Innodb
1623
1	SIMPLE	c	eq_ref	PRIMARY	PRIMARY	4	func	1	100.00	Using where
1 by brian
clean slate
1624
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
1625
Note	1003	select `test`.`a`.`id` AS `id`,`test`.`a`.`text` AS `text`,`test`.`b`.`id` AS `id`,`test`.`b`.`text` AS `text`,`test`.`c`.`id` AS `id`,`test`.`c`.`text` AS `text` from `test`.`t1` `a` left join `test`.`t2` `b` on(((`test`.`b`.`id` = `test`.`a`.`id`) or isnull(`test`.`b`.`id`))) join `test`.`t1` `c` where (if(isnull(`test`.`b`.`id`),1000,`test`.`b`.`id`) = `test`.`c`.`id`)
1 by brian
clean slate
1626
drop table t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1627
create table t1 (a int) ENGINE=MyISAM;
1 by brian
clean slate
1628
insert into t1 values (1);
1629
explain select benchmark(1000, (select a from t1 where a=rand()));
1630
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1631
1	PRIMARY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1632
2	SUBQUERY	t1	system	NULL	NULL	NULL	NULL	1	
1 by brian
clean slate
1633
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1634
create table t1(id int) ENGINE=MyISAM;
1635
create table t2(id int) ENGINE=MyISAM;
1636
create table t3(flag int) ENGINE=MyISAM;
1 by brian
clean slate
1637
select (select * from t3 where id not null) from t1, t2;
629.2.6 by Monty
Updated test output with new and improved error messages.
1638
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'null) from t1, t2' at line 1
1 by brian
clean slate
1639
drop table t1,t2,t3;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1640
CREATE TABLE t1 (id INT) ENGINE=MyISAM;
1641
CREATE TABLE t2 (id INT) ENGINE=MyISAM;
1 by brian
clean slate
1642
INSERT INTO t1 VALUES (1), (2);
1643
INSERT INTO t2 VALUES (1);
1644
SELECT t1.id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id);
1645
id	c
1646
1	1
1647
2	0
1648
SELECT id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id);
1649
id	c
1650
1	1
1651
2	0
1652
SELECT t1.id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id) ORDER BY t1.id;
1653
id	c
1654
1	1
1655
2	0
1656
SELECT id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id) ORDER BY id;
1657
id	c
1658
1	1
1659
2	0
1660
DROP TABLE t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
1661
CREATE TABLE t1 ( a int, b int ) ENGINE=MyISAM;
1 by brian
clean slate
1662
INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
1663
SELECT a FROM t1 WHERE a > ANY ( SELECT a FROM t1 WHERE b = 2 );
1664
a
1665
3
1666
SELECT a FROM t1 WHERE a < ANY ( SELECT a FROM t1 WHERE b = 2 );
1667
a
1668
1
1669
SELECT a FROM t1 WHERE a = ANY ( SELECT a FROM t1 WHERE b = 2 );
1670
a
1671
2
1672
SELECT a FROM t1 WHERE a >= ANY ( SELECT a FROM t1 WHERE b = 2 );
1673
a
1674
2
1675
3
1676
SELECT a FROM t1 WHERE a <= ANY ( SELECT a FROM t1 WHERE b = 2 );
1677
a
1678
1
1679
2
1680
SELECT a FROM t1 WHERE a <> ANY ( SELECT a FROM t1 WHERE b = 2 );
1681
a
1682
1
1683
3
1684
SELECT a FROM t1 WHERE a > ALL ( SELECT a FROM t1 WHERE b = 2 );
1685
a
1686
3
1687
SELECT a FROM t1 WHERE a < ALL ( SELECT a FROM t1 WHERE b = 2 );
1688
a
1689
1
1690
SELECT a FROM t1 WHERE a = ALL ( SELECT a FROM t1 WHERE b = 2 );
1691
a
1692
2
1693
SELECT a FROM t1 WHERE a >= ALL ( SELECT a FROM t1 WHERE b = 2 );
1694
a
1695
2
1696
3
1697
SELECT a FROM t1 WHERE a <= ALL ( SELECT a FROM t1 WHERE b = 2 );
1698
a
1699
1
1700
2
1701
SELECT a FROM t1 WHERE a <> ALL ( SELECT a FROM t1 WHERE b = 2 );
1702
a
1703
1
1704
3
1705
ALTER TABLE t1 ADD INDEX (a);
1706
SELECT a FROM t1 WHERE a > ANY ( SELECT a FROM t1 WHERE b = 2 );
1707
a
1708
3
1709
SELECT a FROM t1 WHERE a < ANY ( SELECT a FROM t1 WHERE b = 2 );
1710
a
1711
1
1712
SELECT a FROM t1 WHERE a = ANY ( SELECT a FROM t1 WHERE b = 2 );
1713
a
1714
2
1715
SELECT a FROM t1 WHERE a >= ANY ( SELECT a FROM t1 WHERE b = 2 );
1716
a
1717
2
1718
3
1719
SELECT a FROM t1 WHERE a <= ANY ( SELECT a FROM t1 WHERE b = 2 );
1720
a
1721
1
1722
2
1723
SELECT a FROM t1 WHERE a <> ANY ( SELECT a FROM t1 WHERE b = 2 );
1724
a
1725
1
1726
3
1727
SELECT a FROM t1 WHERE a > ALL ( SELECT a FROM t1 WHERE b = 2 );
1728
a
1729
3
1730
SELECT a FROM t1 WHERE a < ALL ( SELECT a FROM t1 WHERE b = 2 );
1731
a
1732
1
1733
SELECT a FROM t1 WHERE a = ALL ( SELECT a FROM t1 WHERE b = 2 );
1734
a
1735
2
1736
SELECT a FROM t1 WHERE a >= ALL ( SELECT a FROM t1 WHERE b = 2 );
1737
a
1738
2
1739
3
1740
SELECT a FROM t1 WHERE a <= ALL ( SELECT a FROM t1 WHERE b = 2 );
1741
a
1742
1
1743
2
1744
SELECT a FROM t1 WHERE a <> ALL ( SELECT a FROM t1 WHERE b = 2 );
1745
a
1746
1
1747
3
1748
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 HAVING a = 2);
1749
a
1750
3
1751
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 HAVING a = 2);
1752
a
1753
1
1754
SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 HAVING a = 2);
1755
a
1756
2
1757
SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 HAVING a = 2);
1758
a
1759
2
1760
3
1761
SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 HAVING a = 2);
1762
a
1763
1
1764
2
1765
SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 HAVING a = 2);
1766
a
1767
1
1768
3
1769
SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 HAVING a = 2);
1770
a
1771
3
1772
SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 HAVING a = 2);
1773
a
1774
1
1775
SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 HAVING a = 2);
1776
a
1777
2
1778
SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 HAVING a = 2);
1779
a
1780
2
1781
3
1782
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 HAVING a = 2);
1783
a
1784
1
1785
2
1786
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 HAVING a = 2);
1787
a
1788
1
1789
3
1790
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
1791
a
1792
3
1793
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
1794
a
1795
1
1796
SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
1797
a
1798
2
1799
SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
1800
a
1801
2
1802
3
1803
SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
1804
a
1805
1
1806
2
1807
SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
1808
a
1809
1
1810
3
1811
SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
1812
a
1813
3
1814
SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
1815
a
1816
1
1817
SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
1818
a
1819
2
1820
SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
1821
a
1822
2
1823
3
1824
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
1825
a
1826
1
1827
2
1828
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2);
1829
a
1830
1
1831
3
1832
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
1833
a
1834
3
1835
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
1836
a
1837
1
1838
SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
1839
a
1840
2
1841
SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
1842
a
1843
2
1844
3
1845
SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
1846
a
1847
1
1848
2
1849
SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
1850
a
1851
1
1852
3
1853
SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
1854
a
1855
3
1856
SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
1857
a
1858
1
1859
SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
1860
a
1861
2
1862
SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
1863
a
1864
2
1865
3
1866
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
1867
a
1868
1
1869
2
1870
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2);
1871
a
1872
1
1873
3
1874
SELECT a FROM t1 WHERE (1,2) > ANY (SELECT a FROM t1 WHERE b = 2);
1875
ERROR 21000: Operand should contain 1 column(s)
1876
SELECT a FROM t1 WHERE a > ANY (SELECT a,2 FROM t1 WHERE b = 2);
1877
ERROR 21000: Operand should contain 1 column(s)
1878
SELECT a FROM t1 WHERE (1,2) > ANY (SELECT a,2 FROM t1 WHERE b = 2);
1879
ERROR 21000: Operand should contain 1 column(s)
1880
SELECT a FROM t1 WHERE (1,2) > ALL (SELECT a FROM t1 WHERE b = 2);
1881
ERROR 21000: Operand should contain 1 column(s)
1882
SELECT a FROM t1 WHERE a > ALL (SELECT a,2 FROM t1 WHERE b = 2);
1883
ERROR 21000: Operand should contain 1 column(s)
1884
SELECT a FROM t1 WHERE (1,2) > ALL (SELECT a,2 FROM t1 WHERE b = 2);
1885
ERROR 21000: Operand should contain 1 column(s)
1886
SELECT a FROM t1 WHERE (1,2) = ALL (SELECT a,2 FROM t1 WHERE b = 2);
1887
ERROR 21000: Operand should contain 1 column(s)
1888
SELECT a FROM t1 WHERE (1,2) <> ANY (SELECT a,2 FROM t1 WHERE b = 2);
1889
ERROR 21000: Operand should contain 1 column(s)
1890
SELECT a FROM t1 WHERE (1,2) = ANY (SELECT a FROM t1 WHERE b = 2);
1891
ERROR 21000: Operand should contain 2 column(s)
1892
SELECT a FROM t1 WHERE a = ANY (SELECT a,2 FROM t1 WHERE b = 2);
1893
ERROR 21000: Operand should contain 1 column(s)
1894
SELECT a FROM t1 WHERE (1,2) = ANY (SELECT a,2 FROM t1 WHERE b = 2);
1895
a
1896
SELECT a FROM t1 WHERE (1,2) <> ALL (SELECT a FROM t1 WHERE b = 2);
1897
ERROR 21000: Operand should contain 2 column(s)
1898
SELECT a FROM t1 WHERE a <> ALL (SELECT a,2 FROM t1 WHERE b = 2);
1899
ERROR 21000: Operand should contain 1 column(s)
1900
SELECT a FROM t1 WHERE (1,2) <> ALL (SELECT a,2 FROM t1 WHERE b = 2);
1901
a
1902
1
1903
2
1904
3
1905
SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 WHERE b = 2);
1906
a
1907
2
1908
SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 WHERE b = 2);
1909
a
1910
1
1911
3
1912
SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 HAVING a = 2);
1913
a
1914
2
1915
SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 HAVING a = 2);
1916
a
1917
1
1918
3
1919
SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 WHERE b = 2 UNION SELECT a,1 FROM t1 WHERE b = 2);
1920
a
1921
2
1922
SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 WHERE b = 2 UNION SELECT a,1 FROM t1 WHERE b = 2);
1923
a
1924
1
1925
3
1926
SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 HAVING a = 2 UNION SELECT a,1 FROM t1 HAVING a = 2);
1927
a
1928
2
1929
SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 HAVING a = 2 UNION SELECT a,1 FROM t1 HAVING a = 2);
1930
a
1931
1
1932
3
1933
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2 group by a);
1934
a
1935
3
1936
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = 2 group by a);
1937
a
1938
1
1939
SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = 2 group by a);
1940
a
1941
2
1942
SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = 2 group by a);
1943
a
1944
2
1945
3
1946
SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = 2 group by a);
1947
a
1948
1
1949
2
1950
SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = 2 group by a);
1951
a
1952
1
1953
3
1954
SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = 2 group by a);
1955
a
1956
3
1957
SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = 2 group by a);
1958
a
1959
1
1960
SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = 2 group by a);
1961
a
1962
2
1963
SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = 2 group by a);
1964
a
1965
2
1966
3
1967
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = 2 group by a);
1968
a
1969
1
1970
2
1971
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = 2 group by a);
1972
a
1973
1
1974
3
1975
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 group by a HAVING a = 2);
1976
a
1977
3
1978
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 group by a HAVING a = 2);
1979
a
1980
1
1981
SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 group by a HAVING a = 2);
1982
a
1983
2
1984
SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 group by a HAVING a = 2);
1985
a
1986
2
1987
3
1988
SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 group by a HAVING a = 2);
1989
a
1990
1
1991
2
1992
SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 group by a HAVING a = 2);
1993
a
1994
1
1995
3
1996
SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 group by a HAVING a = 2);
1997
a
1998
3
1999
SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 group by a HAVING a = 2);
2000
a
2001
1
2002
SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 group by a HAVING a = 2);
2003
a
2004
2
2005
SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 group by a HAVING a = 2);
2006
a
2007
2
2008
3
2009
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 group by a HAVING a = 2);
2010
a
2011
1
2012
2
2013
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 group by a HAVING a = 2);
2014
a
2015
1
2016
3
2017
SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a > t1.a), '-') from t1 a;
2018
concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a > t1.a), '-')
2019
0-
2020
0-
2021
1-
2022
SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a < t1.a), '-') from t1 a;
2023
concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a < t1.a), '-')
2024
1-
2025
0-
2026
0-
2027
SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a = t1.a), '-') from t1 a;
2028
concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a = t1.a), '-')
2029
0-
2030
1-
2031
0-
2032
DROP TABLE t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2033
CREATE TABLE t1 ( a double, b double ) ENGINE=MyISAM;
1 by brian
clean slate
2034
INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
2035
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2e0);
2036
a
2037
3
2038
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = 2e0);
2039
a
2040
1
2041
SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = 2e0);
2042
a
2043
2
2044
SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = 2e0);
2045
a
2046
2
2047
3
2048
SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = 2e0);
2049
a
2050
1
2051
2
2052
SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = 2e0);
2053
a
2054
1
2055
3
2056
SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = 2e0);
2057
a
2058
3
2059
SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = 2e0);
2060
a
2061
1
2062
SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = 2e0);
2063
a
2064
2
2065
SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = 2e0);
2066
a
2067
2
2068
3
2069
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = 2e0);
2070
a
2071
1
2072
2
2073
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = 2e0);
2074
a
2075
1
2076
3
2077
DROP TABLE t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2078
CREATE TABLE t1 ( a char(1), b char(1)) ENGINE=MyISAM;
1 by brian
clean slate
2079
INSERT INTO t1 VALUES ('1','1'),('2','2'),('3','3');
2080
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = '2');
2081
a
2082
3
2083
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = '2');
2084
a
2085
1
2086
SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = '2');
2087
a
2088
2
2089
SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = '2');
2090
a
2091
2
2092
3
2093
SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = '2');
2094
a
2095
1
2096
2
2097
SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = '2');
2098
a
2099
1
2100
3
2101
SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = '2');
2102
a
2103
3
2104
SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = '2');
2105
a
2106
1
2107
SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = '2');
2108
a
2109
2
2110
SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = '2');
2111
a
2112
2
2113
3
2114
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = '2');
2115
a
2116
1
2117
2
2118
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = '2');
2119
a
2120
1
2121
3
2122
DROP TABLE t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2123
create table t1 (a int, b int) ENGINE=MyISAM;
1 by brian
clean slate
2124
insert into t1 values (1,2),(3,4);
2125
select * from t1 up where exists (select * from t1 where t1.a=up.a);
2126
a	b
2127
1	2
2128
3	4
2129
explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a);
2130
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
2131
1	PRIMARY	up	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
2132
2	DEPENDENT SUBQUERY	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
2133
Warnings:
2134
Note	1276	Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
2135
Note	1003	select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where exists(select 1 AS `Not_used` from `test`.`t1` where (`test`.`t1`.`a` = `test`.`up`.`a`))
1 by brian
clean slate
2136
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2137
CREATE TABLE t1 (t1_a int) ENGINE=MyISAM;
1 by brian
clean slate
2138
INSERT INTO t1 VALUES (1);
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2139
CREATE TABLE t2 (t2_a int, t2_b int, PRIMARY KEY (t2_a, t2_b)) ENGINE=MyISAM;
1 by brian
clean slate
2140
INSERT INTO t2 VALUES (1, 1), (1, 2);
2141
SELECT * FROM t1, t2 table2 WHERE t1_a = 1 AND table2.t2_a = 1
2142
HAVING table2.t2_b = (SELECT MAX(t2_b) FROM t2 WHERE t2_a = table2.t2_a);
2143
t1_a	t2_a	t2_b
2144
1	1	2
2145
DROP TABLE t1, t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2146
CREATE TABLE t1 (id int default NULL,name varchar(10) default NULL) ENGINE=MyISAM;
1 by brian
clean slate
2147
INSERT INTO t1 VALUES (1,'Tim'),(2,'Rebecca'),(3,NULL);
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2148
CREATE TABLE t2 (id int default NULL, pet varchar(10) default NULL) ENGINE=MyISAM;
1 by brian
clean slate
2149
INSERT INTO t2 VALUES (1,'Fido'),(2,'Spot'),(3,'Felix');
2150
SELECT a.*, b.* FROM (SELECT * FROM t1) AS a JOIN t2 as b on a.id=b.id;
2151
id	name	id	pet
2152
1	Tim	1	Fido
2153
2	Rebecca	2	Spot
2154
3	NULL	3	Felix
2155
drop table t1,t2;
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
2156
CREATE TABLE `t1` ( `a` int default NULL) ENGINE=MyISAM;
1 by brian
clean slate
2157
insert into t1 values (1);
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
2158
CREATE TABLE `t2` ( `b` int default NULL, `a` int default NULL) ENGINE=MyISAM;
1 by brian
clean slate
2159
insert into t2 values (1,2);
2160
select t000.a, count(*) `C` FROM t1 t000 GROUP BY t000.a HAVING count(*) > ALL (SELECT count(*) FROM t2 t001 WHERE t001.a=1);
2161
a	C
2162
1	1
2163
drop table t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2164
CREATE TABLE t1(`IZAVORGANG_ID` VARCHAR(11) COLLATE utf8_bin,`KUERZEL` VARCHAR(10) COLLATE utf8_bin,`IZAANALYSEART_ID` VARCHAR(11) COLLATE utf8_bin,`IZAPMKZ_ID` VARCHAR(11) COLLATE utf8_bin) ENGINE=MyISAM;
1 by brian
clean slate
2165
CREATE INDEX AK01IZAVORGANG ON t1(izaAnalyseart_id,Kuerzel);
2166
INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000001','601','D0000000001','I0000000001');
2167
INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000002','602','D0000000001','I0000000001');
2168
INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000003','603','D0000000001','I0000000001');
2169
INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000004','101','D0000000001','I0000000001');
2170
SELECT `IZAVORGANG_ID` FROM t1 WHERE `KUERZEL` IN(SELECT MIN(`KUERZEL`)`Feld1` FROM t1 WHERE `KUERZEL` LIKE'601%'And`IZAANALYSEART_ID`='D0000000001');
2171
IZAVORGANG_ID
2172
D0000000001
2173
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2174
CREATE TABLE `t1` ( `aid` int NOT NULL default '0', `bid` int NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`)) ENGINE=MyISAM;
2175
CREATE TABLE `t2` ( `aid` int NOT NULL default '0', `bid` int NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`)) ENGINE=MyISAM;
1 by brian
clean slate
2176
insert into t1 values (1,1),(1,2),(2,1),(2,2);
2177
insert into t2 values (1,2),(2,2);
2178
select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
2179
aid	bid
2180
1	1
2181
2	1
2182
alter table t2 drop primary key;
2183
alter table t2 add key KEY1 (aid, bid);
2184
select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
2185
aid	bid
2186
1	1
2187
2	1
2188
alter table t2 drop key KEY1;
2189
alter table t2 add primary key (bid, aid);
2190
select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
2191
aid	bid
2192
1	1
2193
2	1
2194
drop table t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2195
CREATE TABLE t1 (howmanyvalues bigint, avalue int) ENGINE=MyISAM;
1 by brian
clean slate
2196
INSERT INTO t1 VALUES (1, 1),(2, 1),(2, 2),(3, 1),(3, 2),(3, 3),(4, 1),(4, 2),(4, 3),(4, 4);
2197
SELECT howmanyvalues, count(*) from t1 group by howmanyvalues;
2198
howmanyvalues	count(*)
2199
1	1
2200
2	2
2201
3	3
2202
4	4
2203
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues;
2204
howmanyvalues	mycount
2205
1	1
2206
2	2
2207
3	3
2208
4	4
2209
CREATE INDEX t1_howmanyvalues_idx ON t1 (howmanyvalues);
2210
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues+1 = a.howmanyvalues+1) as mycount from t1 a group by a.howmanyvalues;
2211
howmanyvalues	mycount
2212
1	1
2213
2	2
2214
3	3
2215
4	4
2216
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues;
2217
howmanyvalues	mycount
2218
1	1
2219
2	2
2220
3	3
2221
4	4
2222
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.avalue) as mycount from t1 a group by a.howmanyvalues;
2223
howmanyvalues	mycount
2224
1	1
2225
2	1
2226
3	1
2227
4	1
2228
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2229
create table t1 (x int) ENGINE=MyISAM;
1 by brian
clean slate
2230
select  (select b.x from t1 as b where b.x=a.x) from t1 as a where a.x=2 group by a.x;
2231
(select b.x from t1 as b where b.x=a.x)
2232
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2233
CREATE TABLE `t1` ( `master` int NOT NULL default '0', `map` int NOT NULL default '0', `slave` int NOT NULL default '0', `access` int NOT NULL default '0', UNIQUE KEY `access_u` (`master`,`map`,`slave`)) ENGINE=MyISAM;
1 by brian
clean slate
2234
INSERT INTO `t1` VALUES (1,0,0,700),(1,1,1,400),(1,5,5,400),(1,12,12,400),(1,12,32,400),(4,12,32,400);
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2235
CREATE TABLE `t2` ( `id` int NOT NULL default '0', `pid` int NOT NULL default '0', `map` int NOT NULL default '0', `level` int NOT NULL default '0', `title` varchar(255) default NULL, PRIMARY KEY  (`id`,`pid`,`map`), KEY `level` (`level`), KEY `id` (`id`,`map`)) ENGINE=MyISAM ;
1 by brian
clean slate
2236
INSERT INTO `t2` VALUES (6,5,12,7,'a'),(12,0,0,7,'a'),(12,1,0,7,'a'),(12,5,5,7,'a'),(12,5,12,7,'a');
2237
SELECT b.sc FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac FROM t2 op WHERE op.id = 12 AND op.map = 0) b;
2238
ERROR 42S22: Unknown column 'b.sc' in 'field list'
2239
SELECT b.ac FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac FROM t2 op WHERE op.id = 12 AND op.map = 0) b;
2240
ac
2241
700
2242
NULL
2243
drop tables t1,t2;
2244
set @got_val= (SELECT 1 FROM (SELECT 'A' as my_col) as T1 ) ;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2245
create table t1 (a int, b int) ENGINE=MyISAM;
2246
create table t2 (a int, b int) ENGINE=MyISAM;
1 by brian
clean slate
2247
insert into t1 values (1,1),(1,2),(1,3),(2,4),(2,5);
2248
insert into t2 values (1,3),(2,1);
2249
select distinct a,b, (select max(b) from t2 where t1.b=t2.a) from t1 order by t1.b;
2250
a	b	(select max(b) from t2 where t1.b=t2.a)
2251
1	1	3
2252
1	2	1
2253
1	3	NULL
2254
2	4	NULL
2255
2	5	NULL
2256
drop table t1, t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2257
create table t1 (s1 int,s2 int) ENGINE=MyISAM;
1 by brian
clean slate
2258
insert into t1 values (20,15);
2259
select * from t1 where  (('a',null) <=> (select 'a',s2 from t1 where s1 = 0));
2260
s1	s2
2261
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2262
create table t1 (s1 int) ENGINE=MyISAM;
1 by brian
clean slate
2263
insert into t1 values (1),(null);
2264
select * from t1 where s1 < all (select s1 from t1);
2265
s1
2266
select s1, s1 < all (select s1 from t1) from t1;
2267
s1	s1 < all (select s1 from t1)
2268
1	0
2269
NULL	NULL
2270
drop table t1;
2271
CREATE TABLE t1 (
2272
Code char(3) NOT NULL default '',
2273
Name char(52) NOT NULL default '',
2274
Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia',
2275
Region char(26) NOT NULL default '',
2276
SurfaceArea float(10,2) NOT NULL default '0.00',
396 by Brian Aker
Cleanup tiny and small int.
2277
IndepYear int default NULL,
223 by Brian Aker
Cleanup int() work.
2278
Population int NOT NULL default '0',
1 by brian
clean slate
2279
LifeExpectancy float(3,1) default NULL,
2280
GNP float(10,2) default NULL,
2281
GNPOld float(10,2) default NULL,
2282
LocalName char(45) NOT NULL default '',
2283
GovernmentForm char(45) NOT NULL default '',
2284
HeadOfState char(60) default NULL,
223 by Brian Aker
Cleanup int() work.
2285
Capital int default NULL,
1 by brian
clean slate
2286
Code2 char(2) NOT NULL default ''
2287
) ENGINE=MyISAM;
2288
INSERT INTO t1 VALUES ('XXX','Xxxxx','Oceania','Xxxxxx',26.00,0,0,0,0,0,'Xxxxx','Xxxxx','Xxxxx',NULL,'XX');
2289
INSERT INTO t1 VALUES ('ASM','American Samoa','Oceania','Polynesia',199.00,0,68000,75.1,334.00,NULL,'Amerika Samoa','US Territory','George W. Bush',54,'AS');
2290
INSERT INTO t1 VALUES ('ATF','French Southern territories','Antarctica','Antarctica',7780.00,0,0,NULL,0.00,NULL,'Terres australes françaises','Nonmetropolitan Territory of France','Jacques Chirac',NULL,'TF');
2291
INSERT INTO t1 VALUES ('UMI','United States Minor Outlying Islands','Oceania','Micronesia/Caribbean',16.00,0,0,NULL,0.00,NULL,'United States Minor Outlying Islands','Dependent Territory of the US','George W. Bush',NULL,'UM');
2292
/*!40000 ALTER TABLE t1 ENABLE KEYS */;
2293
SELECT DISTINCT Continent AS c FROM t1 outr WHERE 
2294
Code <> SOME ( SELECT Code FROM t1 WHERE Continent = outr.Continent AND 
2295
Population < 200);
2296
c
2297
Oceania
2298
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2299
create table t1 (a1 int) ENGINE=MyISAM;
2300
create table t2 (b1 int) ENGINE=MyISAM;
1 by brian
clean slate
2301
select * from t1 where a2 > any(select b1 from t2);
2302
ERROR 42S22: Unknown column 'a2' in 'IN/ALL/ANY subquery'
2303
select * from t1 where a1 > any(select b1 from t2);
2304
a1
2305
drop table t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2306
create table t1 (a integer, b integer) ENGINE=MyISAM;
1 by brian
clean slate
2307
select (select * from t1) = (select 1,2);
2308
(select * from t1) = (select 1,2)
2309
NULL
2310
select (select 1,2) = (select * from t1);
2311
(select 1,2) = (select * from t1)
2312
NULL
2313
select  row(1,2) = ANY (select * from t1);
2314
row(1,2) = ANY (select * from t1)
2315
0
2316
select  row(1,2) != ALL (select * from t1);
2317
row(1,2) != ALL (select * from t1)
2318
1
2319
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2320
create table t1 (a integer, b integer) ENGINE=MyISAM;
1 by brian
clean slate
2321
select row(1,(2,2)) in (select * from t1 );
2322
ERROR 21000: Operand should contain 2 column(s)
2323
select row(1,(2,2)) = (select * from t1 );
2324
ERROR 21000: Operand should contain 2 column(s)
2325
select (select * from t1) = row(1,(2,2));
2326
ERROR 21000: Operand should contain 1 column(s)
2327
drop table t1;
2328
create  table t1 (a integer);
2329
insert into t1 values (1);
2330
select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx ;
2331
ERROR 42S22: Reference 'xx' not supported (forward reference in item list)
2332
select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx;
2333
ERROR 42S22: Reference 'xx' not supported (forward reference in item list)
2334
select 1 as xx, 1 = ALL (  select 1 from t1 where 1 = xx );
2335
xx	1 = ALL (  select 1 from t1 where 1 = xx )
2336
1	1
2337
select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx;
2338
ERROR 42S22: Reference 'xx' not supported (forward reference in item list)
2339
drop table t1;
2340
CREATE TABLE t1 (
223 by Brian Aker
Cleanup int() work.
2341
categoryId int NOT NULL,
2342
courseId int NOT NULL,
1 by brian
clean slate
2343
startDate datetime NOT NULL,
2344
endDate datetime NOT NULL,
2345
createDate datetime NOT NULL,
2346
modifyDate timestamp NOT NULL,
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2347
attributes text NOT NULL)
2348
engine=myisam;
1 by brian
clean slate
2349
INSERT INTO t1 VALUES (1,41,'2004-02-09','2010-01-01','2004-02-09','2004-02-09',''),
2350
(1,86,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''),
2351
(1,87,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''),
2352
(2,52,'2004-03-15','2004-10-01','2004-03-15','2004-09-17',''),
2353
(2,53,'2004-03-16','2004-10-01','2004-03-16','2004-09-17',''),
2354
(2,88,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''),
2355
(2,89,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''),
2356
(3,51,'2004-02-09','2010-01-01','2004-02-09','2004-02-09',''),
2357
(5,12,'2004-02-18','2010-01-01','2004-02-18','2004-02-18','');
2358
CREATE TABLE t2 (
223 by Brian Aker
Cleanup int() work.
2359
userId int NOT NULL,
2360
courseId int NOT NULL,
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2361
date datetime NOT NULL)
2362
engine=myisam;
1 by brian
clean slate
2363
INSERT INTO t2 VALUES (5141,71,'2003-11-18'),
2364
(5141,72,'2003-11-25'),(5141,41,'2004-08-06'),
2365
(5141,52,'2004-08-06'),(5141,53,'2004-08-06'),
2366
(5141,12,'2004-08-06'),(5141,86,'2004-10-21'),
2367
(5141,87,'2004-10-21'),(5141,88,'2004-10-21'),
2368
(5141,89,'2004-10-22'),(5141,51,'2004-10-26');
2369
CREATE TABLE t3 (
223 by Brian Aker
Cleanup int() work.
2370
groupId int NOT NULL,
2371
parentId int NOT NULL,
1 by brian
clean slate
2372
startDate datetime NOT NULL,
2373
endDate datetime NOT NULL,
2374
createDate datetime NOT NULL,
2375
modifyDate timestamp NOT NULL,
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2376
ordering int)
2377
engine=myisam;
1 by brian
clean slate
2378
INSERT INTO t3 VALUES (12,9,'1000-01-01','3999-12-31','2004-01-29','2004-01-29',NULL);
2379
CREATE TABLE t4 (
223 by Brian Aker
Cleanup int() work.
2380
id int NOT NULL,
2381
groupTypeId int NOT NULL,
1 by brian
clean slate
2382
groupKey varchar(50) NOT NULL,
2383
name text,
223 by Brian Aker
Cleanup int() work.
2384
ordering int,
1 by brian
clean slate
2385
description text,
2386
createDate datetime NOT NULL,
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2387
modifyDate timestamp NOT NULL)
2388
engine=myisam;
1 by brian
clean slate
2389
INSERT INTO t4 VALUES (9,5,'stationer','stationer',0,'Stationer','2004-01-29','2004-01-29'),
2390
(12,5,'group2','group2',0,'group2','2004-01-29','2004-01-29');
2391
CREATE TABLE t5 (
223 by Brian Aker
Cleanup int() work.
2392
userId int NOT NULL,
2393
groupId int NOT NULL,
1 by brian
clean slate
2394
createDate datetime NOT NULL,
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2395
modifyDate timestamp NOT NULL) ENGINE=MyISAM;
1 by brian
clean slate
2396
INSERT INTO t5 VALUES (5141,12,'2004-08-06','2004-08-06');
2397
select
2398
count(distinct t2.userid) pass,
2399
groupstuff.*,
2400
count(t2.courseid) crse,
2401
t1.categoryid, 
2402
t2.courseid,
2403
date_format(date, '%b%y') as colhead
2404
from t2   
2405
join t1 on t2.courseid=t1.courseid  
2406
join
2407
(
2408
select 
2409
t5.userid,  
2410
parentid,  
2411
parentgroup,  
2412
childid,  
2413
groupname,  
2414
grouptypeid  
2415
from t5 
2416
join 
2417
(
2418
select t4.id as parentid,  
2419
t4.name as parentgroup,  
2420
t4.id as childid,  
2421
t4.name as groupname,  
2422
t4.grouptypeid  
2423
from   t4  
2424
) as gin on t5.groupid=gin.childid 
2425
) as groupstuff on t2.userid = groupstuff.userid 
2426
group by 
2427
groupstuff.groupname, colhead , t2.courseid;
2428
pass	userid	parentid	parentgroup	childid	groupname	grouptypeid	crse	categoryid	courseid	colhead
2429
1	5141	12	group2	12	group2	5	1	5	12	Aug04
2430
1	5141	12	group2	12	group2	5	1	1	41	Aug04
2431
1	5141	12	group2	12	group2	5	1	2	52	Aug04
2432
1	5141	12	group2	12	group2	5	1	2	53	Aug04
2433
1	5141	12	group2	12	group2	5	1	3	51	Oct04
2434
1	5141	12	group2	12	group2	5	1	1	86	Oct04
2435
1	5141	12	group2	12	group2	5	1	1	87	Oct04
2436
1	5141	12	group2	12	group2	5	1	2	88	Oct04
2437
1	5141	12	group2	12	group2	5	1	2	89	Oct04
2438
drop table t1, t2, t3, t4, t5;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2439
create table t1 (a int) ENGINE=MyISAM;
1 by brian
clean slate
2440
insert into t1 values (1), (2), (3);
2441
SELECT 1 FROM t1 WHERE (SELECT 1) in (SELECT 1);
2442
1
2443
1
2444
1
2445
1
2446
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2447
create table t1 (a int, b int) ENGINE=MyISAM;
1 by brian
clean slate
2448
insert into t1 values (1,2);
2449
select 1 = (select * from t1);
2450
ERROR 21000: Operand should contain 1 column(s)
2451
select (select * from t1) = 1;
2452
ERROR 21000: Operand should contain 2 column(s)
2453
select (1,2) = (select a from t1);
2454
ERROR 21000: Operand should contain 2 column(s)
2455
select (select a from t1) = (1,2);
2456
ERROR 21000: Operand should contain 1 column(s)
2457
select (1,2,3) = (select * from t1);
2458
ERROR 21000: Operand should contain 3 column(s)
2459
select (select * from t1) = (1,2,3);
2460
ERROR 21000: Operand should contain 2 column(s)
2461
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2462
create table t1 (fld enum('0','1')) ENGINE=MyISAM;
1 by brian
clean slate
2463
insert into t1 values ('1');
2464
select * from (select max(fld) from t1) as foo;
2465
max(fld)
2466
1
2467
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2468
CREATE TABLE t1 (one int, two int, flag char(1)) ENGINE=MyISAM;
2469
CREATE TABLE t2 (one int, two int, flag char(1)) ENGINE=MyISAM;
1 by brian
clean slate
2470
INSERT INTO t1 VALUES(1,2,'Y'),(2,3,'Y'),(3,4,'Y'),(5,6,'N'),(7,8,'N');
2471
INSERT INTO t2 VALUES(1,2,'Y'),(2,3,'Y'),(3,4,'Y'),(5,6,'N'),(7,8,'N');
2472
SELECT * FROM t1
2473
WHERE ROW(one,two) IN (SELECT DISTINCT one,two FROM t2 WHERE flag = 'N');
2474
one	two	flag
2475
5	6	N
2476
7	8	N
2477
SELECT * FROM t1
2478
WHERE ROW(one,two) IN (SELECT DISTINCT one,two FROM t1 WHERE flag = 'N');
2479
one	two	flag
2480
5	6	N
2481
7	8	N
2482
insert into t2 values (null,null,'N');
2483
insert into t2 values (null,3,'0');
2484
insert into t2 values (null,5,'0');
2485
insert into t2 values (10,null,'0');
2486
insert into t1 values (10,3,'0');
2487
insert into t1 values (10,5,'0');
2488
insert into t1 values (10,10,'0');
2489
SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N') as 'test' from t1;
2490
one	two	test
2491
1	2	NULL
2492
2	3	NULL
2493
3	4	NULL
2494
5	6	1
2495
7	8	1
2496
10	3	NULL
2497
10	5	NULL
2498
10	10	NULL
2499
SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
2500
one	two
2501
5	6
2502
7	8
2503
SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N' group by one,two) as 'test' from t1;
2504
one	two	test
2505
1	2	NULL
2506
2	3	NULL
2507
3	4	NULL
2508
5	6	1
2509
7	8	1
2510
10	3	NULL
2511
10	5	NULL
2512
10	10	NULL
2513
SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0') as 'test' from t1;
2514
one	two	test
2515
1	2	0
2516
2	3	NULL
2517
3	4	0
2518
5	6	0
2519
7	8	0
2520
10	3	NULL
2521
10	5	NULL
2522
10	10	NULL
2523
SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0' group by one,two) as 'test' from t1;
2524
one	two	test
2525
1	2	0
2526
2	3	NULL
2527
3	4	0
2528
5	6	0
2529
7	8	0
2530
10	3	NULL
2531
10	5	NULL
2532
10	10	NULL
2533
explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0') as 'test' from t1;
2534
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
2535
1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	8	100.00	
2536
2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	9	100.00	Using where
2537
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
2538
Note	1003	select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one` AS `one`,`test`.`t2`.`two` AS `two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1`
1 by brian
clean slate
2539
explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
2540
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
2541
1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	8	100.00	Start temporary
2542
1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	9	100.00	Using where; End temporary; Using join buffer
2543
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
2544
Note	1003	select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`two` = `test`.`t1`.`two`) and (`test`.`t2`.`one` = `test`.`t1`.`one`) and (`test`.`t2`.`flag` = 'N'))
1 by brian
clean slate
2545
explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0' group by one,two) as 'test' from t1;
2546
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
2547
1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	8	100.00	
2548
2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	9	100.00	Using where; Using temporary; Using filesort
2549
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
2550
Note	1003	select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one` AS `one`,`test`.`t2`.`two` AS `two` from `test`.`t2` where (`test`.`t2`.`flag` = '0') group by `test`.`t2`.`one`,`test`.`t2`.`two` having (trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))) and trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1`
1 by brian
clean slate
2551
DROP TABLE t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2552
CREATE TABLE t1 (a char(5), b char(5)) ENGINE=MyISAM;
1 by brian
clean slate
2553
INSERT INTO t1 VALUES (NULL,'aaa'), ('aaa','aaa');
2554
SELECT * FROM t1 WHERE (a,b) IN (('aaa','aaa'), ('aaa','bbb'));
2555
a	b
2556
aaa	aaa
2557
DROP TABLE t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2558
CREATE TABLE t1 (a int) ENGINE=MyISAM;
2559
CREATE TABLE t2 (a int, b int) ENGINE=MyISAM;
2560
CREATE TABLE t3 (b int NOT NULL) ENGINE=MyISAM;
1 by brian
clean slate
2561
INSERT INTO t1 VALUES (1), (2), (3), (4);
2562
INSERT INTO t2 VALUES (1,10), (3,30);
2563
SELECT * FROM t2 LEFT JOIN t3 ON t2.b=t3.b
2564
WHERE t3.b IS NOT NULL OR t2.a > 10;
2565
a	b	b
2566
SELECT * FROM t1
2567
WHERE t1.a NOT IN (SELECT a FROM t2 LEFT JOIN t3 ON t2.b=t3.b
2568
WHERE t3.b IS NOT NULL OR t2.a > 10);
2569
a
2570
1
2571
2
2572
3
2573
4
2574
DROP TABLE t1,t2,t3;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2575
CREATE TABLE t1 (f1 INT) ENGINE=MyISAM;
2576
CREATE TABLE t2 (f2 INT) ENGINE=MyISAM;
1 by brian
clean slate
2577
INSERT INTO t1 VALUES (1);
2578
SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2);
2579
f1
2580
1
2581
SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2 WHERE 1=0);
2582
f1
2583
1
2584
INSERT INTO t2 VALUES (1);
2585
INSERT INTO t2 VALUES (2);
2586
SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2 WHERE f2=0);
2587
f1
2588
1
2589
DROP TABLE t1, t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2590
create table t1 (s1 char) ENGINE=MyISAM;
1 by brian
clean slate
2591
insert into t1 values (1),(2);
2592
select * from t1 where (s1 < any (select s1 from t1));
2593
s1
2594
1
2595
select * from t1 where not (s1 < any (select s1 from t1));
2596
s1
2597
2
2598
select * from t1 where (s1 < ALL (select s1+1 from t1));
2599
s1
2600
1
2601
select * from t1 where not(s1 < ALL (select s1+1 from t1));
2602
s1
2603
2
2604
select * from t1 where (s1+1 = ANY (select s1 from t1));
2605
s1
2606
1
2607
select * from t1 where NOT(s1+1 = ANY (select s1 from t1));
2608
s1
2609
2
2610
select * from t1 where (s1 = ALL (select s1/s1 from t1));
2611
s1
2612
1
2613
select * from t1 where NOT(s1 = ALL (select s1/s1 from t1));
2614
s1
2615
2
2616
drop table t1;
2617
create table t1 (
2618
retailerID varchar(8) NOT NULL,
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
2619
statusID   int NOT NULL,
1 by brian
clean slate
2620
changed    datetime NOT NULL,
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2621
UNIQUE KEY retailerID (retailerID, statusID, changed))
2622
ENGINE=MyISAM;
1 by brian
clean slate
2623
INSERT INTO t1 VALUES("0026", "1", "2005-12-06 12:18:56");
2624
INSERT INTO t1 VALUES("0026", "2", "2006-01-06 12:25:53");
2625
INSERT INTO t1 VALUES("0037", "1", "2005-12-06 12:18:56");
2626
INSERT INTO t1 VALUES("0037", "2", "2006-01-06 12:25:53");
2627
INSERT INTO t1 VALUES("0048", "1", "2006-01-06 12:37:50");
2628
INSERT INTO t1 VALUES("0059", "1", "2006-01-06 12:37:50");
2629
select * from t1 r1 
2630
where (r1.retailerID,(r1.changed)) in 
2631
(SELECT r2.retailerId,(max(changed)) from t1 r2 
2632
group by r2.retailerId);
2633
retailerID	statusID	changed
2634
0026	2	2006-01-06 12:25:53
2635
0037	2	2006-01-06 12:25:53
2636
0048	1	2006-01-06 12:37:50
2637
0059	1	2006-01-06 12:37:50
2638
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2639
create table t1(a int, primary key (a)) ENGINE=MyISAM;
1 by brian
clean slate
2640
insert into t1 values (10);
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2641
create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b)) ENGINE=MyISAM;
1 by brian
clean slate
2642
insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989');
2643
explain SELECT t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r 
2644
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' 
2645
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
2646
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2647
1	PRIMARY	t1	system	PRIMARY	NULL	NULL	NULL	1	
1 by brian
clean slate
2648
1	PRIMARY	r	const	PRIMARY	PRIMARY	4	const	1	
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2649
2	DEPENDENT SUBQUERY	t2	range	b	b	136	NULL	2	Using where
1 by brian
clean slate
2650
SELECT t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r 
2651
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' 
2652
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10;
2653
a	a	b
2654
10	3	35989
2655
explain SELECT t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r 
2656
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' 
2657
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
2658
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2659
1	PRIMARY	t1	system	PRIMARY	NULL	NULL	NULL	1	
1 by brian
clean slate
2660
1	PRIMARY	r	const	PRIMARY	PRIMARY	4	const	1	
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2661
2	DEPENDENT SUBQUERY	t2	range	b	b	136	NULL	2	Using where; Using MRR
1 by brian
clean slate
2662
SELECT t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r 
2663
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' 
2664
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10;
2665
a	a	b
2666
10	1	359
2667
drop table t1,t2;
2668
CREATE TABLE t1 (                  
2669
field1 int NOT NULL,                 
2670
field2 int NOT NULL,                 
2671
field3 int NOT NULL,                 
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2672
PRIMARY KEY  (field1,field2,field3))
2673
ENGINE=MyISAM;
1 by brian
clean slate
2674
CREATE TABLE t2 (             
2675
fieldA int NOT NULL,            
2676
fieldB int NOT NULL,            
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2677
PRIMARY KEY  (fieldA,fieldB))
2678
ENGINE=MyISAM;
1 by brian
clean slate
2679
INSERT INTO t1 VALUES
2680
(1,1,1), (1,1,2), (1,2,1), (1,2,2), (1,2,3), (1,3,1);
2681
INSERT INTO t2 VALUES (1,1), (1,2), (1,3);
2682
SELECT field1, field2, COUNT(*)
2683
FROM t1 GROUP BY field1, field2;
2684
field1	field2	COUNT(*)
2685
1	1	2
2686
1	2	3
2687
1	3	1
2688
SELECT field1, field2
2689
FROM  t1
2690
GROUP BY field1, field2
2691
HAVING COUNT(*) >= ALL (SELECT fieldB 
2692
FROM t2 WHERE fieldA = field1);
2693
field1	field2
2694
1	2
2695
SELECT field1, field2
2696
FROM  t1
2697
GROUP BY field1, field2
2698
HAVING COUNT(*) < ANY (SELECT fieldB 
2699
FROM t2 WHERE fieldA = field1);
2700
field1	field2
2701
1	1
2702
1	3
2703
DROP TABLE t1, t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2704
CREATE TABLE t1(a int, INDEX (a)) ENGINE=MyISAM;
1 by brian
clean slate
2705
INSERT INTO t1 VALUES (1), (3), (5), (7);
2706
INSERT INTO t1 VALUES (NULL);
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2707
CREATE TABLE t2(a int) ENGINE=MyISAM;
1 by brian
clean slate
2708
INSERT INTO t2 VALUES (1),(2),(3);
2709
EXPLAIN SELECT a, a IN (SELECT a FROM t1) FROM t2;
2710
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
2711
1	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	3	
2712
2	DEPENDENT SUBQUERY	t1	index_subquery	a	a	5	func	2	Using index; Full scan on NULL key
2713
SELECT a, a IN (SELECT a FROM t1) FROM t2;
2714
a	a IN (SELECT a FROM t1)
2715
1	1
2716
2	NULL
2717
3	1
2718
DROP TABLE t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2719
CREATE TABLE t1 (a DATETIME) ENGINE=MyISAM;
1 by brian
clean slate
2720
INSERT INTO t1 VALUES ('1998-09-23'), ('2003-03-25');
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2721
CREATE TABLE t2 ENGINE=MyISAM AS SELECT 
1 by brian
clean slate
2722
(SELECT a FROM t1 WHERE a < '2000-01-01') AS sub_a 
2723
FROM t1 WHERE a > '2000-01-01';
2724
SHOW CREATE TABLE t2;
2725
Table	Create Table
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
2726
t2	CREATE TABLE `t2` (
873.2.35 by Monty Taylor
Update tests based on how Toru's latest patch changes create table statements.
2727
  `sub_a` datetime DEFAULT NULL
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2728
) ENGINE=MyISAM
2729
CREATE TABLE t3 ENGINE=MyISAM AS (SELECT a FROM t1 WHERE a < '2000-01-01') UNION (SELECT a FROM t1 WHERE a > '2000-01-01');
1 by brian
clean slate
2730
SHOW CREATE TABLE t3;
2731
Table	Create Table
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
2732
t3	CREATE TABLE `t3` (
873.2.35 by Monty Taylor
Update tests based on how Toru's latest patch changes create table statements.
2733
  `a` datetime DEFAULT NULL
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2734
) ENGINE=MyISAM
1 by brian
clean slate
2735
DROP TABLE t1,t2,t3;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2736
CREATE TABLE t1 (a int) ENGINE=MyISAM;
1 by brian
clean slate
2737
INSERT INTO t1 VALUES (2), (4), (1), (3);
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2738
CREATE TABLE t2 (b int, c int) ENGINE=MyISAM;
1 by brian
clean slate
2739
INSERT INTO t2 VALUES
2740
(2,1), (1,3), (2,1), (4,4), (2,2), (1,4);
2741
SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 2 );
2742
a
2743
2
2744
4
2745
1
2746
3
2747
SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 1);
2748
ERROR 21000: Subquery returns more than 1 row
2749
SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 2), a;
2750
a
2751
1
2752
2
2753
3
2754
4
2755
SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 1), a;
2756
ERROR 21000: Subquery returns more than 1 row
2757
SELECT b, MAX(c) FROM t2 GROUP BY b, (SELECT c FROM t2 WHERE b > 2);
2758
b	MAX(c)
2759
1	4
2760
2	2
2761
4	4
2762
SELECT b, MAX(c) FROM t2 GROUP BY b, (SELECT c FROM t2 WHERE b > 1);
2763
ERROR 21000: Subquery returns more than 1 row
2764
SELECT a FROM t1 GROUP BY a
2765
HAVING IFNULL((SELECT b FROM t2 WHERE b > 2),
2766
(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b)) > 3;
2767
a
2768
1
2769
2
2770
3
2771
4
2772
SELECT a FROM t1 GROUP BY a
2773
HAVING IFNULL((SELECT b FROM t2 WHERE b > 1),
2774
(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b)) > 3;
2775
ERROR 21000: Subquery returns more than 1 row
2776
SELECT a FROM t1 GROUP BY a
2777
HAVING IFNULL((SELECT b FROM t2 WHERE b > 4),
2778
(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b)) > 3;
2779
a
2780
4
2781
SELECT a FROM t1 GROUP BY a
2782
HAVING IFNULL((SELECT b FROM t2 WHERE b > 4),
2783
(SELECT c FROM t2 WHERE c=a AND b > 1 ORDER BY b)) > 3;
2784
ERROR 21000: Subquery returns more than 1 row
2785
SELECT a FROM t1
2786
ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 2),
2787
(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b));
2788
a
2789
2
2790
4
2791
1
2792
3
2793
SELECT a FROM t1
2794
ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 1),
2795
(SELECT c FROM t2 WHERE c=a AND b > 1 ORDER BY b));
2796
ERROR 21000: Subquery returns more than 1 row
2797
SELECT a FROM t1
2798
ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 4),
2799
(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b));
2800
a
2801
2
2802
1
2803
3
2804
4
2805
SELECT a FROM t1
2806
ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 4),
2807
(SELECT c FROM t2 WHERE c=a AND b > 1 ORDER BY b));
2808
ERROR 21000: Subquery returns more than 1 row
2809
DROP TABLE t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2810
create table t1 (df decimal(5,1)) ENGINE=MyISAM;
1 by brian
clean slate
2811
insert into t1 values(1.1);
2812
insert into t1 values(2.2);
2813
select * from t1 where df <= all (select avg(df) from t1 group by df);
2814
df
2815
1.1
2816
select * from t1 where df >= all (select avg(df) from t1 group by df);
2817
df
2818
2.2
2819
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2820
create table t1 (df decimal(5,1)) ENGINE=MyISAM;
1 by brian
clean slate
2821
insert into t1 values(1.1);
2822
select 1.1 * exists(select * from t1);
2823
1.1 * exists(select * from t1)
2824
1.1
2825
drop table t1;
2826
CREATE TABLE t1 (
223 by Brian Aker
Cleanup int() work.
2827
grp int default NULL,
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2828
a decimal(10,2) default NULL) ENGINE=MyISAM;
1 by brian
clean slate
2829
insert into t1 values (1, 1), (2, 2), (2, 3), (3, 4), (3, 5), (3, 6), (NULL, NULL);
2830
select * from t1;
2831
grp	a
2832
1	1.00
2833
2	2.00
2834
2	3.00
2835
3	4.00
2836
3	5.00
2837
3	6.00
2838
NULL	NULL
2839
select min(a) from t1 group by grp;
2840
min(a)
2841
NULL
2842
1.00
2843
2.00
2844
4.00
2845
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2846
CREATE table t1 ( c1 integer ) ENGINE=MyISAM;
1 by brian
clean slate
2847
INSERT INTO t1 VALUES ( 1 );
2848
INSERT INTO t1 VALUES ( 2 );
2849
INSERT INTO t1 VALUES ( 3 );
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2850
CREATE TABLE t2 ( c2 integer ) ENGINE=MyISAM;
1 by brian
clean slate
2851
INSERT INTO t2 VALUES ( 1 );
2852
INSERT INTO t2 VALUES ( 4 );
2853
INSERT INTO t2 VALUES ( 5 );
2854
SELECT * FROM t1 LEFT JOIN t2 ON c1 = c2 WHERE c2 IN (1);
2855
c1	c2
2856
1	1
2857
SELECT * FROM t1 LEFT JOIN t2 ON c1 = c2
2858
WHERE c2 IN ( SELECT c2 FROM t2 WHERE c2 IN ( 1 ) );
2859
c1	c2
2860
1	1
2861
DROP TABLE t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2862
CREATE TABLE t1 ( c1 integer ) ENGINE=MyISAM;
1 by brian
clean slate
2863
INSERT INTO t1 VALUES ( 1 );
2864
INSERT INTO t1 VALUES ( 2 );
2865
INSERT INTO t1 VALUES ( 3 );
2866
INSERT INTO t1 VALUES ( 6 );
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2867
CREATE TABLE t2 ( c2 integer ) ENGINE=MyISAM;
1 by brian
clean slate
2868
INSERT INTO t2 VALUES ( 1 );
2869
INSERT INTO t2 VALUES ( 4 );
2870
INSERT INTO t2 VALUES ( 5 );
2871
INSERT INTO t2 VALUES ( 6 );
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2872
CREATE TABLE t3 ( c3 integer ) ENGINE=MyISAM;
1 by brian
clean slate
2873
INSERT INTO t3 VALUES ( 7 );
2874
INSERT INTO t3 VALUES ( 8 );
2875
SELECT c1,c2 FROM t1 LEFT JOIN t2 ON c1 = c2 
2876
WHERE EXISTS (SELECT c3 FROM t3 WHERE c2 IS NULL );
2877
c1	c2
2878
2	NULL
2879
3	NULL
2880
DROP TABLE t1,t2,t3;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2881
CREATE TABLE t1 (EMPNUM   CHAR(3)) ENGINE=MyISAM;
2882
CREATE TABLE t2 (EMPNUM   CHAR(3) ) ENGINE=MyISAM;
1 by brian
clean slate
2883
INSERT INTO t1 VALUES ('E1'),('E2');
2884
INSERT INTO t2 VALUES ('E1');
2885
DELETE FROM t1
2886
WHERE t1.EMPNUM NOT IN
2887
(SELECT t2.EMPNUM
2888
FROM t2
2889
WHERE t1.EMPNUM = t2.EMPNUM);
2890
select * from t1;
2891
EMPNUM
2892
E1
2893
DROP TABLE t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2894
CREATE TABLE t1(select_id BIGINT, values_id BIGINT) ENGINE=MyISAM;
1 by brian
clean slate
2895
INSERT INTO t1 VALUES (1, 1);
2896
CREATE TABLE t2 (select_id BIGINT, values_id BIGINT, 
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2897
PRIMARY KEY(select_id,values_id)) ENGINE=MyISAM;
1 by brian
clean slate
2898
INSERT INTO t2 VALUES (0, 1), (0, 2), (0, 3), (1, 5);
2899
SELECT values_id FROM t1 
2900
WHERE values_id IN (SELECT values_id FROM t2
2901
WHERE select_id IN (1, 0));
2902
values_id
2903
1
2904
SELECT values_id FROM t1 
2905
WHERE values_id IN (SELECT values_id FROM t2
2906
WHERE select_id BETWEEN 0 AND 1);
2907
values_id
2908
1
2909
SELECT values_id FROM t1 
2910
WHERE values_id IN (SELECT values_id FROM t2
2911
WHERE select_id = 0 OR select_id = 1);
2912
values_id
2913
1
2914
DROP TABLE t1, t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2915
create table t1 (fld enum('0','1')) ENGINE=MyISAM;
1 by brian
clean slate
2916
insert into t1 values ('1');
2917
select * from (select max(fld) from t1) as foo;
2918
max(fld)
2919
1
2920
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
2921
CREATE TABLE t1 (a int, b int) ENGINE=MyISAM;
2922
CREATE TABLE t2 (c int, d int) ENGINE=MyISAM;
2923
CREATE TABLE t3 (e int) ENGINE=MyISAM;
1 by brian
clean slate
2924
INSERT INTO t1 VALUES 
2925
(1,10), (2,10), (1,20), (2,20), (3,20), (2,30), (4,40);
2926
INSERT INTO t2 VALUES
2927
(2,10), (2,20), (4,10), (5,10), (3,20), (2,40);
2928
INSERT INTO t3 VALUES (10), (30), (10), (20) ;
2929
SELECT a, MAX(b), MIN(b) FROM t1 GROUP BY a;
2930
a	MAX(b)	MIN(b)
2931
1	20	10
2932
2	30	10
2933
3	20	20
2934
4	40	40
2935
SELECT * FROM t2;
2936
c	d
2937
2	10
2938
2	20
2939
4	10
2940
5	10
2941
3	20
2942
2	40
2943
SELECT * FROM t3;
2944
e
2945
10
2946
30
2947
10
2948
20
2949
SELECT a FROM t1 GROUP BY a
2950
HAVING a IN (SELECT c FROM t2 WHERE MAX(b)>20);
2951
a
2952
2
2953
4
2954
SELECT a FROM t1 GROUP BY a
2955
HAVING a IN (SELECT c FROM t2 WHERE MAX(b)<d);
2956
a
2957
2
2958
SELECT a FROM t1 GROUP BY a
2959
HAVING a IN (SELECT c FROM t2 WHERE MAX(b)>d);
2960
a
2961
2
2962
4
2963
SELECT a FROM t1 GROUP BY a
2964
HAVING a IN (SELECT c FROM t2
2965
WHERE d >= SOME(SELECT e FROM t3 WHERE MAX(b)=e));
2966
a
2967
2
2968
3
2969
SELECT a FROM t1 GROUP BY a
2970
HAVING a IN (SELECT c FROM t2
2971
WHERE  EXISTS(SELECT e FROM t3 WHERE MAX(b)=e AND e <= d));
2972
a
2973
2
2974
3
2975
SELECT a FROM t1 GROUP BY a
2976
HAVING a IN (SELECT c FROM t2
2977
WHERE d > SOME(SELECT e FROM t3 WHERE MAX(b)=e));
2978
a
2979
2
2980
SELECT a FROM t1 GROUP BY a
2981
HAVING a IN (SELECT c FROM t2
2982
WHERE  EXISTS(SELECT e FROM t3 WHERE MAX(b)=e AND e < d));
2983
a
2984
2
2985
SELECT a FROM t1 GROUP BY a
2986
HAVING a IN (SELECT c FROM t2
2987
WHERE MIN(b) < d AND 
2988
EXISTS(SELECT e FROM t3 WHERE MAX(b)=e AND e <= d));
2989
a
2990
2
2991
SELECT a, SUM(a) FROM t1 GROUP BY a;
2992
a	SUM(a)
2993
1	2
2994
2	6
2995
3	3
2996
4	4
2997
SELECT a FROM t1
2998
WHERE EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) = c) GROUP BY a;
2999
a
3000
3
3001
4
3002
SELECT a FROM t1 GROUP BY a
3003
HAVING EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) = c);
3004
a
3005
1
3006
3
3007
4
3008
SELECT a FROM t1
3009
WHERE a < 3 AND
3010
EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) != c) GROUP BY a;
3011
a
3012
1
3013
2
3014
SELECT a FROM t1
3015
WHERE a < 3 AND
3016
EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) != c);
3017
a
3018
1
3019
2
3020
1
3021
2
3022
2
3023
SELECT t1.a FROM t1 GROUP BY t1.a
3024
HAVING t1.a < ALL(SELECT t2.c FROM t2 GROUP BY t2.c
3025
HAVING EXISTS(SELECT t3.e FROM t3 GROUP BY t3.e
3026
HAVING SUM(t1.a+t2.c) < t3.e/4));
3027
a
3028
1
3029
2
3030
SELECT t1.a FROM t1 GROUP BY t1.a
3031
HAVING t1.a > ALL(SELECT t2.c FROM t2
3032
WHERE EXISTS(SELECT t3.e FROM t3 GROUP BY t3.e
3033
HAVING SUM(t1.a+t2.c) < t3.e/4));
3034
a
3035
4
3036
SELECT t1.a FROM t1 GROUP BY t1.a
3037
HAVING t1.a > ALL(SELECT t2.c FROM t2
3038
WHERE EXISTS(SELECT t3.e FROM t3 
3039
WHERE SUM(t1.a+t2.c) < t3.e/4));
3040
ERROR HY000: Invalid use of group function
3041
SELECT t1.a from t1 GROUP BY t1.a HAVING AVG(SUM(t1.b)) > 20;
3042
ERROR HY000: Invalid use of group function
3043
SELECT t1.a FROM t1 GROUP BY t1.a
3044
HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c
3045
HAVING AVG(t2.c+SUM(t1.b)) > 20);
3046
a
3047
2
3048
3
3049
4
3050
SELECT t1.a FROM t1 GROUP BY t1.a
3051
HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c
3052
HAVING AVG(SUM(t1.b)) > 20);
3053
a
3054
2
3055
4
3056
SELECT t1.a, SUM(b) AS sum  FROM t1 GROUP BY t1.a
3057
HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c
3058
HAVING t2.c+sum > 20);
3059
a	sum
3060
2	60
3061
3	20
3062
4	40
3063
DROP TABLE t1,t2,t3;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3064
CREATE TABLE t1 (a varchar(5), b varchar(10)) ENGINE=MyISAM;
1 by brian
clean slate
3065
INSERT INTO t1 VALUES
3066
('AAA', 5), ('BBB', 4), ('BBB', 1), ('CCC', 2),
3067
('CCC', 7), ('AAA', 2), ('AAA', 4), ('BBB', 3), ('AAA', 8);
3068
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
3069
a	b
3070
BBB	4
3071
CCC	7
3072
AAA	8
3073
EXPLAIN
3074
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
3075
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
3076
1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	9	Using where
3077
2	SUBQUERY	t1	ALL	NULL	NULL	NULL	NULL	9	Using temporary; Using filesort
3078
ALTER TABLE t1 ADD INDEX(a);
3079
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
3080
a	b
3081
BBB	4
3082
CCC	7
3083
AAA	8
3084
EXPLAIN
3085
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
3086
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
3087
1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	9	Using where
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3088
2	SUBQUERY	t1	ALL	NULL	NULL	NULL	NULL	9	Using temporary; Using filesort
1 by brian
clean slate
3089
DROP TABLE t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3090
create table t1( f1 int,f2 int) ENGINE=MyISAM;
1 by brian
clean slate
3091
insert into t1 values (1,1),(2,2);
3092
select tt.t from (select 'crash1' as t, f2 from t1) as tt left join t1 on tt.t = 'crash2' and tt.f2 = t1.f2 where tt.t = 'crash1';
3093
t
3094
crash1
3095
crash1
3096
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3097
create table t1 (c int, key(c)) ENGINE=MyISAM;
1 by brian
clean slate
3098
insert into t1 values (1142477582), (1142455969);
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3099
create table t2 (a int, b int) ENGINE=MyISAM;
1 by brian
clean slate
3100
insert into t2 values (2, 1), (1, 0);
3101
delete from t1 where c <= 1140006215 and (select b from t2 where a = 2) = 1;
3102
drop table t1, t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3103
create table t1 (i int, j bigint) ENGINE=MyISAM;
1 by brian
clean slate
3104
insert into t1 values (1, 2), (2, 2), (3, 2);
3105
select * from (select min(i) from t1 where j=(select * from (select min(j) from t1) t2)) t3;
3106
min(i)
3107
1
3108
drop table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3109
CREATE TABLE t1 (i BIGINT) ENGINE=MyISAM;
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
3110
INSERT INTO t1 VALUES (10000000000000000);
1 by brian
clean slate
3111
INSERT INTO t1 VALUES (1);
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3112
CREATE TABLE t2 (i BIGINT) ENGINE=MyISAM;
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
3113
INSERT INTO t2 VALUES (10000000000000000);
1 by brian
clean slate
3114
INSERT INTO t2 VALUES (1);
3115
/* simple test */
3116
SELECT t1.i FROM t1 JOIN t2 ON t1.i = t2.i;
3117
i
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
3118
10000000000000000
1 by brian
clean slate
3119
1
3120
/* subquery test */
3121
SELECT t1.i FROM t1 WHERE t1.i = (SELECT MAX(i) FROM t2);
3122
i
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
3123
10000000000000000
1 by brian
clean slate
3124
/* subquery test with cast*/
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
3125
SELECT t1.i FROM t1 WHERE t1.i = (SELECT MAX(i) FROM t2);
1 by brian
clean slate
3126
i
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
3127
10000000000000000
1 by brian
clean slate
3128
DROP TABLE t1;
3129
DROP TABLE t2;
3130
CREATE TABLE t1 (
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
3131
id bigint NOT NULL auto_increment,
1 by brian
clean slate
3132
name varchar(255) NOT NULL,
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3133
PRIMARY KEY  (id))
3134
ENGINE=MyISAM;
1 by brian
clean slate
3135
INSERT INTO t1 VALUES
3136
(1, 'Balazs'), (2, 'Joe'), (3, 'Frank');
3137
CREATE TABLE t2 (
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
3138
id bigint NOT NULL auto_increment,
3139
mid bigint NOT NULL,
1 by brian
clean slate
3140
date date NOT NULL,
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3141
PRIMARY KEY  (id))
3142
ENGINE=MyISAM;
1 by brian
clean slate
3143
INSERT INTO t2 VALUES 
3144
(1, 1, '2006-03-30'), (2, 2, '2006-04-06'), (3, 3, '2006-04-13'),
3145
(4, 2, '2006-04-20'), (5, 1, '2006-05-01');
3146
SELECT *,
3147
(SELECT date FROM t2 WHERE mid = t1.id
3148
ORDER BY date DESC LIMIT 0, 1) AS date_last,
3149
(SELECT date FROM t2 WHERE mid = t1.id
3150
ORDER BY date DESC LIMIT 3, 1) AS date_next_to_last
3151
FROM t1;
3152
id	name	date_last	date_next_to_last
3153
1	Balazs	2006-05-01	NULL
3154
2	Joe	2006-04-20	NULL
3155
3	Frank	2006-04-13	NULL
3156
SELECT *,
3157
(SELECT COUNT(*) FROM t2 WHERE mid = t1.id
3158
ORDER BY date DESC LIMIT 1, 1) AS date_count
3159
FROM t1;
3160
id	name	date_count
3161
1	Balazs	NULL
3162
2	Joe	NULL
3163
3	Frank	NULL
3164
SELECT *,
3165
(SELECT date FROM t2 WHERE mid = t1.id
3166
ORDER BY date DESC LIMIT 0, 1) AS date_last,
3167
(SELECT date FROM t2 WHERE mid = t1.id
3168
ORDER BY date DESC LIMIT 1, 1) AS date_next_to_last
3169
FROM t1;
3170
id	name	date_last	date_next_to_last
3171
1	Balazs	2006-05-01	2006-03-30
3172
2	Joe	2006-04-20	2006-04-06
3173
3	Frank	2006-04-13	NULL
3174
DROP TABLE t1,t2;
3175
CREATE TABLE t1 (
223 by Brian Aker
Cleanup int() work.
3176
i1 int NOT NULL default '0',
3177
i2 int NOT NULL default '0',
873.1.2 by Jay Pipes
Fixed Field_datetime to never accept any bad datetimes as a string. This broke
3178
t datetime,
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3179
PRIMARY KEY  (i1,i2,t))
3180
ENGINE=MyISAM;
1 by brian
clean slate
3181
INSERT INTO t1 VALUES 
3182
(24,1,'2005-03-03 16:31:31'),(24,1,'2005-05-27 12:40:07'),
3183
(24,1,'2005-05-27 12:40:08'),(24,1,'2005-05-27 12:40:10'),
3184
(24,1,'2005-05-27 12:40:25'),(24,1,'2005-05-27 12:40:30'),
3185
(24,2,'2005-03-03 13:43:05'),(24,2,'2005-03-03 16:23:31'),
3186
(24,2,'2005-03-03 16:31:30'),(24,2,'2005-05-27 12:37:02'),
3187
(24,2,'2005-05-27 12:40:06');
3188
CREATE TABLE t2 (
223 by Brian Aker
Cleanup int() work.
3189
i1 int NOT NULL default '0',
3190
i2 int NOT NULL default '0',
1 by brian
clean slate
3191
t datetime default NULL,
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3192
PRIMARY KEY  (i1))
3193
ENGINE=MyISAM;
1 by brian
clean slate
3194
INSERT INTO t2 VALUES (24,1,'2006-06-20 12:29:40');
3195
EXPLAIN
3196
SELECT * FROM t1,t2
3197
WHERE t1.t = (SELECT t1.t FROM t1 
3198
WHERE t1.t < t2.t  AND t1.i2=1 AND t2.i1=t1.i1
3199
ORDER BY t1.t DESC LIMIT 1);
3200
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3201
1	PRIMARY	t2	system	NULL	NULL	NULL	NULL	1	
3202
1	PRIMARY	t1	index	NULL	PRIMARY	16	NULL	11	Using where; Using index
3203
2	DEPENDENT SUBQUERY	t1	range	PRIMARY	PRIMARY	16	NULL	5	Using where; Using index
1 by brian
clean slate
3204
SELECT * FROM t1,t2
3205
WHERE t1.t = (SELECT t1.t FROM t1 
3206
WHERE t1.t < t2.t  AND t1.i2=1 AND t2.i1=t1.i1
3207
ORDER BY t1.t DESC LIMIT 1);
3208
i1	i2	t	i1	i2	t
3209
24	1	2005-05-27 12:40:30	24	1	2006-06-20 12:29:40
3210
DROP TABLE t1, t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3211
CREATE TABLE t1 (i INT) ENGINE=MyISAM;
1 by brian
clean slate
3212
(SELECT i FROM t1) UNION (SELECT i FROM t1);
3213
i
3214
SELECT * FROM t1 WHERE NOT EXISTS 
3215
(
3216
(SELECT i FROM t1) UNION 
3217
(SELECT i FROM t1)
3218
);
3219
i
3220
SELECT * FROM t1 
3221
WHERE NOT EXISTS (((SELECT i FROM t1) UNION (SELECT i FROM t1)));
629.2.6 by Monty
Updated test output with new and improved error messages.
3222
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'UNION (SELECT i FROM t1)))' at line 1
1 by brian
clean slate
3223
explain select ((select t11.i from t1 t11) union (select t12.i from t1 t12))
3224
from t1;
629.2.6 by Monty
Updated test output with new and improved error messages.
3225
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'union (select t12.i from t1 t12))
1 by brian
clean slate
3226
from t1' at line 1
3227
explain select * from t1 where not exists 
3228
((select t11.i from t1 t11) union (select t12.i from t1 t12));
3229
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3230
1	PRIMARY	t1	system	NULL	NULL	NULL	NULL	0	const row not found
3231
2	SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
3232
3	UNION	NULL	NULL	NULL	NULL	NULL	NULL	NULL	no matching row in const table
1 by brian
clean slate
3233
NULL	UNION RESULT	<union2,3>	ALL	NULL	NULL	NULL	NULL	NULL	
3234
DROP TABLE t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3235
CREATE TABLE t1 (a INT, b INT) ENGINE=MyISAM;
3236
CREATE TABLE t2 (a INT) ENGINE=MyISAM;
1 by brian
clean slate
3237
INSERT INTO t2 values (1);
3238
INSERT INTO t1 VALUES (1,1),(1,2),(2,3),(3,4);
3239
SELECT (SELECT COUNT(DISTINCT t1.b) from t2) FROM t1 GROUP BY t1.a;
3240
(SELECT COUNT(DISTINCT t1.b) from t2)
3241
2
3242
1
3243
1
3244
SELECT (SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3)
3245
FROM t1 GROUP BY t1.a;
3246
(SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3)
3247
2
3248
1
3249
1
3250
SELECT COUNT(DISTINCT t1.b), (SELECT COUNT(DISTINCT t1.b)) FROM t1 GROUP BY t1.a;
3251
COUNT(DISTINCT t1.b)	(SELECT COUNT(DISTINCT t1.b))
3252
2	2
3253
1	1
3254
1	1
3255
SELECT (
3256
SELECT (
3257
SELECT (
3258
SELECT COUNT(DISTINCT t1.b)
3259
)
3260
) 
3261
FROM t1 GROUP BY t1.a LIMIT 1) 
3262
FROM t1 t2
3263
GROUP BY t2.a;
3264
(
3265
SELECT (
3266
SELECT (
3267
SELECT COUNT(DISTINCT t1.b)
3268
)
3269
) 
3270
FROM t1 GROUP BY t1.a LIMIT 1)
3271
2
3272
2
3273
2
3274
DROP TABLE t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3275
CREATE TABLE t1 (a int, b int auto_increment, PRIMARY KEY (b)) ENGINE=MyISAM;
1 by brian
clean slate
3276
CREATE TABLE t2 (x int auto_increment, y int, z int,
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3277
PRIMARY KEY (x), FOREIGN KEY (y) REFERENCES t1 (b)) ENGINE=MyISAM;
1 by brian
clean slate
3278
SET SESSION sort_buffer_size = 32 * 1024;
3279
Warnings:
910.4.10 by Stewart Smith
fix system variables for correct endian architectures.
3280
Error	1292	Truncated incorrect sort_buffer_size value: '32768'
1 by brian
clean slate
3281
SELECT COUNT(*) 
3282
FROM (SELECT  a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c
3283
FROM t1) t;
3284
COUNT(*)
3285
3000
3286
SET SESSION sort_buffer_size = 8 * 1024 * 1024;
3287
SELECT COUNT(*) 
3288
FROM (SELECT  a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c
3289
FROM t1) t;
3290
COUNT(*)
3291
3000
201 by Brian Aker
Convert default engine to Innodb
3292
DROP TABLE t2,t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3293
CREATE TABLE t1 (id char(4) PRIMARY KEY, c int) ENGINE=MyISAM;
3294
CREATE TABLE t2 (c int) ENGINE=MyISAM;
1 by brian
clean slate
3295
INSERT INTO t1 VALUES ('aa', 1);
3296
INSERT INTO t2 VALUES (1);
3297
SELECT * FROM t1
3298
WHERE EXISTS (SELECT c FROM t2 WHERE c=1
3299
UNION
3300
SELECT c from t2 WHERE c=t1.c);
3301
id	c
3302
aa	1
3303
INSERT INTO t1 VALUES ('bb', 2), ('cc', 3), ('dd',1);
3304
SELECT * FROM t1
3305
WHERE EXISTS (SELECT c FROM t2 WHERE c=1
3306
UNION
3307
SELECT c from t2 WHERE c=t1.c);
3308
id	c
3309
aa	1
3310
bb	2
3311
cc	3
3312
dd	1
3313
INSERT INTO t2 VALUES (2);
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3314
CREATE TABLE t3 (c int) ENGINE=MyISAM;
1 by brian
clean slate
3315
INSERT INTO t3 VALUES (1);
3316
SELECT * FROM t1
3317
WHERE EXISTS (SELECT t2.c FROM t2 JOIN t3 ON t2.c=t3.c WHERE t2.c=1
3318
UNION
3319
SELECT c from t2 WHERE c=t1.c);
3320
id	c
3321
aa	1
3322
bb	2
3323
cc	3
3324
dd	1
3325
DROP TABLE t1,t2,t3;
3326
DROP TABLE IF EXISTS t1;
3327
DROP TABLE IF EXISTS t2;
3328
DROP TABLE IF EXISTS t1xt2;
3329
CREATE TABLE t1 (
223 by Brian Aker
Cleanup int() work.
3330
id_1 int NOT NULL,
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3331
t varchar(4) DEFAULT NULL)
3332
ENGINE=MyISAM;
1 by brian
clean slate
3333
CREATE TABLE t2 (
223 by Brian Aker
Cleanup int() work.
3334
id_2 int NOT NULL,
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3335
t varchar(4) DEFAULT NULL)
3336
ENGINE=MyISAM;
1 by brian
clean slate
3337
CREATE TABLE t1xt2 (
223 by Brian Aker
Cleanup int() work.
3338
id_1 int NOT NULL,
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3339
id_2 int NOT NULL)
3340
ENGINE=MyISAM;
1 by brian
clean slate
3341
INSERT INTO t1 VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd');
3342
INSERT INTO t2 VALUES (2, 'bb'), (3, 'cc'), (4, 'dd'), (12, 'aa');
3343
INSERT INTO t1xt2 VALUES (2, 2), (3, 3), (4, 4);
3344
SELECT DISTINCT t1.id_1 FROM t1 WHERE
3345
(12 IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1));
3346
id_1
3347
SELECT DISTINCT t1.id_1 FROM t1 WHERE
3348
(12 IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)));
3349
id_1
3350
SELECT DISTINCT t1.id_1 FROM t1 WHERE
3351
(12 IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))));
3352
id_1
3353
SELECT DISTINCT t1.id_1 FROM t1 WHERE
3354
(12 NOT IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1));
3355
id_1
3356
1
3357
2
3358
3
3359
4
3360
SELECT DISTINCT t1.id_1 FROM t1 WHERE
3361
(12 NOT IN ((SELECT t1xt2.id_2 FROM t1xt2 where t1.id_1 = t1xt2.id_1)));
3362
id_1
3363
1
3364
2
3365
3
3366
4
3367
SELECT DISTINCT t1.id_1 FROM t1 WHERE
3368
(12 NOT IN (((SELECT t1xt2.id_2 FROM t1xt2 where t1.id_1 = t1xt2.id_1))));
3369
id_1
3370
1
3371
2
3372
3
3373
4
3374
insert INTO t1xt2 VALUES (1, 12);
3375
SELECT DISTINCT t1.id_1 FROM t1 WHERE
3376
(12 IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1));
3377
id_1
3378
1
3379
SELECT DISTINCT t1.id_1 FROM t1 WHERE
3380
(12 IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)));
3381
id_1
3382
1
3383
SELECT DISTINCT t1.id_1 FROM t1 WHERE
3384
(12 IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))));
3385
id_1
3386
1
3387
SELECT DISTINCT t1.id_1 FROM t1 WHERE
3388
(12 NOT IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1));
3389
id_1
3390
2
3391
3
3392
4
3393
SELECT DISTINCT t1.id_1 FROM t1 WHERE
3394
(12 NOT IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)));
3395
id_1
3396
2
3397
3
3398
4
3399
SELECT DISTINCT t1.id_1 FROM t1 WHERE
3400
(12 NOT IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))));
3401
id_1
3402
2
3403
3
3404
4
3405
insert INTO t1xt2 VALUES (2, 12);
3406
SELECT DISTINCT t1.id_1 FROM t1 WHERE
3407
(12 IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1));
3408
id_1
3409
1
3410
2
3411
SELECT DISTINCT t1.id_1 FROM t1 WHERE
3412
(12 IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)));
3413
id_1
3414
1
3415
2
3416
SELECT DISTINCT t1.id_1 FROM t1 WHERE
3417
(12 IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))));
3418
id_1
3419
1
3420
2
3421
SELECT DISTINCT t1.id_1 FROM t1 WHERE
3422
(12 NOT IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1));
3423
id_1
3424
3
3425
4
3426
SELECT DISTINCT t1.id_1 FROM t1 WHERE
3427
(12 NOT IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)));
3428
id_1
3429
3
3430
4
3431
SELECT DISTINCT t1.id_1 FROM t1 WHERE
3432
(12 NOT IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))));
3433
id_1
3434
3
3435
4
3436
DROP TABLE t1;
3437
DROP TABLE t2;
3438
DROP TABLE t1xt2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3439
CREATE TABLE t1 (a int) ENGINE=MyISAM;
1 by brian
clean slate
3440
INSERT INTO t1 VALUES (3), (1), (2);
3441
SELECT 'this is ' 'a test.' AS col1, a AS col2 FROM t1;
3442
col1	col2
3443
this is a test.	3
3444
this is a test.	1
3445
this is a test.	2
3446
SELECT * FROM (SELECT 'this is ' 'a test.' AS col1, a AS t2 FROM t1) t;
3447
col1	t2
3448
this is a test.	3
3449
this is a test.	1
3450
this is a test.	2
3451
DROP table t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3452
CREATE TABLE t1 (a int, b int) ENGINE=MyISAM;
3453
CREATE TABLE t2 (m int, n int) ENGINE=MyISAM;
1 by brian
clean slate
3454
INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4);
3455
INSERT INTO t2 VALUES (1,11), (2,22), (3,32), (4,44), (4,44);
3456
SELECT COUNT(*), a,
3457
(SELECT m FROM t2 WHERE m = count(*) LIMIT 1)
3458
FROM t1 GROUP BY a;
3459
COUNT(*)	a	(SELECT m FROM t2 WHERE m = count(*) LIMIT 1)
3460
2	2	2
3461
3	3	3
3462
1	4	1
3463
SELECT COUNT(*), a,
3464
(SELECT MIN(m) FROM t2 WHERE m = count(*))
3465
FROM t1 GROUP BY a;
3466
COUNT(*)	a	(SELECT MIN(m) FROM t2 WHERE m = count(*))
3467
2	2	2
3468
3	3	3
3469
1	4	1
3470
SELECT COUNT(*), a       
3471
FROM t1 GROUP BY a
3472
HAVING (SELECT MIN(m) FROM t2 WHERE m = count(*)) > 1;
3473
COUNT(*)	a
3474
2	2
3475
3	3
3476
DROP TABLE t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3477
CREATE TABLE t1 (a int, b int) ENGINE=MyISAM;
3478
CREATE TABLE t2 (m int, n int) ENGINE=MyISAM;
1 by brian
clean slate
3479
INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4);
3480
INSERT INTO t2 VALUES (1,11), (2,22), (3,32), (4,44), (4,44);
3481
SELECT COUNT(*) c, a,
3482
(SELECT GROUP_CONCAT(COUNT(a)) FROM t2 WHERE m = a)
3483
FROM t1 GROUP BY a;
3484
c	a	(SELECT GROUP_CONCAT(COUNT(a)) FROM t2 WHERE m = a)
3485
2	2	2
3486
3	3	3
3487
1	4	1,1
3488
SELECT COUNT(*) c, a,
3489
(SELECT GROUP_CONCAT(COUNT(a)+1) FROM t2 WHERE m = a)
3490
FROM t1 GROUP BY a;
3491
c	a	(SELECT GROUP_CONCAT(COUNT(a)+1) FROM t2 WHERE m = a)
3492
2	2	3
3493
3	3	4
3494
1	4	2,2
3495
DROP table t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3496
CREATE TABLE t1 (a int, b INT, d INT, c CHAR(10) NOT NULL, PRIMARY KEY (a, b)) ENGINE=MyISAM;
1 by brian
clean slate
3497
INSERT INTO t1 VALUES (1,1,0,'a'), (1,2,0,'b'), (1,3,0,'c'), (1,4,0,'d'),
3498
(1,5,0,'e'), (2,1,0,'f'), (2,2,0,'g'), (2,3,0,'h'), (3,4,0,'i'), (3,3,0,'j'),
3499
(3,2,0,'k'), (3,1,0,'l'), (1,9,0,'m'), (1,0,10,'n'), (2,0,5,'o'), (3,0,7,'p');
3500
SELECT a, MAX(b),
3501
(SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b + 0)) as test 
3502
FROM t1 GROUP BY a;
3503
a	MAX(b)	test
3504
1	9	m
3505
2	3	h
3506
3	4	i
3507
SELECT a x, MAX(b),
3508
(SELECT t.c FROM t1 AS t WHERE x=t.a AND t.b=MAX(t1.b + 0)) as test
3509
FROM t1 GROUP BY a;
3510
x	MAX(b)	test
3511
1	9	m
3512
2	3	h
3513
3	4	i
3514
SELECT a, AVG(b),
3515
(SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=AVG(t1.b)) AS test
3516
FROM t1 WHERE t1.d=0 GROUP BY a;
3517
a	AVG(b)	test
3518
1	4.0000	d
3519
2	2.0000	g
3520
3	2.5000	NULL
3521
SELECT tt.a,
3522
(SELECT (SELECT c FROM t1 as t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a)
3523
LIMIT 1) FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1) as test 
3524
FROM t1 as tt;
3525
a	test
3526
1	n
3527
1	n
3528
1	n
3529
1	n
3530
1	n
3531
1	n
3532
1	n
3533
2	o
3534
2	o
3535
2	o
3536
2	o
3537
3	p
3538
3	p
3539
3	p
3540
3	p
3541
3	p
3542
SELECT tt.a,
3543
(SELECT (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a)
3544
LIMIT 1)
3545
FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1) as test 
3546
FROM t1 as tt GROUP BY tt.a;
3547
a	test
3548
1	n
3549
2	o
3550
3	p
3551
SELECT tt.a, MAX(
3552
(SELECT (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a)
3553
LIMIT 1)
3554
FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1)) as test 
3555
FROM t1 as tt GROUP BY tt.a;
3556
a	test
3557
1	n
3558
2	o
3559
3	p
3560
DROP TABLE t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3561
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
1 by brian
clean slate
3562
INSERT INTO t1 values (1),(1),(1),(1);
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3563
CREATE TABLE t2 (x INT) ENGINE=MyISAM;
1 by brian
clean slate
3564
INSERT INTO t1 values (1000),(1001),(1002);
3565
SELECT SUM( (SELECT COUNT(a) FROM t2) ) FROM t1;
3566
ERROR HY000: Invalid use of group function
3567
SELECT SUM( (SELECT SUM(COUNT(a)) FROM t2) ) FROM t1;
3568
ERROR HY000: Invalid use of group function
3569
SELECT 
3570
SUM( (SELECT AVG( (SELECT COUNT(*) FROM t1 t HAVING t1.a < 12) ) FROM t2) )
3571
FROM t1;
3572
ERROR HY000: Invalid use of group function
3573
SELECT t1.a as XXA, 
3574
SUM( (SELECT AVG( (SELECT COUNT(*) FROM t1 t HAVING XXA < 12) ) FROM t2) )
3575
FROM t1;
3576
ERROR HY000: Invalid use of group function
3577
DROP TABLE t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3578
CREATE TABLE t1 (a int, b int, KEY (a)) ENGINE=MyISAM;
1 by brian
clean slate
3579
INSERT INTO t1 VALUES (1,1),(2,1);
3580
EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT COUNT(*) FROM t1 GROUP BY b);
3581
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
3582
1	PRIMARY	t1	ref	a	a	5	const	1	Using where; Using index
3583
2	SUBQUERY	t1	ALL	NULL	NULL	NULL	NULL	2	Using temporary; Using filesort
3584
DROP TABLE t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3585
CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id)) ENGINE=MyISAM;
1 by brian
clean slate
3586
INSERT INTO t1 VALUES
3587
(3,'FL'), (2,'GA'), (4,'FL'), (1,'GA'), (5,'NY'), (7,'FL'), (6,'NY');
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3588
CREATE TABLE t2 (id int NOT NULL, INDEX idx(id)) ENGINE=MyISAM;
1 by brian
clean slate
3589
INSERT INTO t2 VALUES (7), (5), (1), (3);
3590
SELECT id, st FROM t1 
3591
WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id);
3592
id	st
3593
3	FL
3594
1	GA
3595
7	FL
3596
SELECT id, st FROM t1 
3597
WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id)
3598
GROUP BY id;
3599
id	st
3600
1	GA
3601
3	FL
3602
7	FL
3603
SELECT id, st FROM t1 
3604
WHERE st IN ('GA','FL') AND NOT EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id);
3605
id	st
3606
2	GA
3607
4	FL
3608
SELECT id, st FROM t1 
3609
WHERE st IN ('GA','FL') AND NOT EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id)
3610
GROUP BY id;
3611
id	st
3612
2	GA
3613
4	FL
3614
DROP TABLE t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3615
CREATE TABLE t1 (a int) ENGINE=MyISAM;
1 by brian
clean slate
3616
INSERT INTO t1 VALUES (1), (2);
3617
EXPLAIN EXTENDED
3618
SELECT * FROM (SELECT count(*) FROM t1 GROUP BY a) as res;
3619
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
3620
1	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	2	100.00	
3621
2	DERIVED	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	Using temporary; Using filesort
3622
Warnings:
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
3623
Note	1003	select `res`.`count(*)` AS `count(*)` from (select count(0) AS `count(*)` from `test`.`t1` group by `test`.`t1`.`a`) `res`
1 by brian
clean slate
3624
DROP TABLE t1;
3625
CREATE TABLE t1 (
3626
a varchar(255) default NULL,
3627
b timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3628
INDEX idx(a,b))
3629
ENGINE=MyISAM;
1 by brian
clean slate
3630
CREATE TABLE t2 (
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3631
a varchar(255) default NULL)
3632
ENGINE=MyISAM;
1 by brian
clean slate
3633
INSERT INTO t1 VALUES ('abcdefghijk','2007-05-07 06:00:24');
3634
INSERT INTO t1 SELECT * FROM t1;
3635
INSERT INTO t1 SELECT * FROM t1;
3636
INSERT INTO t1 SELECT * FROM t1;
3637
INSERT INTO t1 SELECT * FROM t1;
3638
INSERT INTO t1 SELECT * FROM t1;
3639
INSERT INTO t1 SELECT * FROM t1;
3640
INSERT INTO t1 SELECT * FROM t1;
3641
INSERT INTO t1 SELECT * FROM t1;
3642
INSERT INTO `t1` VALUES ('asdf','2007-02-08 01:11:26');
3643
INSERT INTO `t2` VALUES ('abcdefghijk');
3644
INSERT INTO `t2` VALUES ('asdf');
3645
SET session sort_buffer_size=8192;
3646
Warnings:
910.4.10 by Stewart Smith
fix system variables for correct endian architectures.
3647
Error	1292	Truncated incorrect sort_buffer_size value: '8192'
1 by brian
clean slate
3648
SELECT (SELECT 1 FROM  t1 WHERE t1.a=t2.a ORDER BY t1.b LIMIT 1) AS d1 FROM t2;
3649
d1
3650
1
3651
1
3652
DROP TABLE t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3653
CREATE TABLE t1 (a INTEGER, b INTEGER) ENGINE=MyISAM;
3654
CREATE TABLE t2 (x INTEGER) ENGINE=MyISAM;
1 by brian
clean slate
3655
INSERT INTO t1 VALUES (1,11), (2,22), (2,22);
3656
INSERT INTO t2 VALUES (1), (2);
3657
SELECT a, COUNT(b), (SELECT COUNT(b) FROM t2) FROM t1 GROUP BY a;
3658
ERROR 21000: Subquery returns more than 1 row
3659
SELECT a, COUNT(b), (SELECT COUNT(b)+0 FROM t2) FROM t1 GROUP BY a;
3660
ERROR 21000: Subquery returns more than 1 row
3661
SELECT (SELECT SUM(t1.a)/AVG(t2.x) FROM t2) FROM t1;
3662
(SELECT SUM(t1.a)/AVG(t2.x) FROM t2)
3663
3.3333
3664
DROP TABLE t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3665
CREATE TABLE t1 (a INT, b INT) ENGINE=MyISAM;
1 by brian
clean slate
3666
INSERT INTO t1 VALUES (1, 2), (1,3), (1,4), (2,1), (2,2);
3667
SELECT a1.a, COUNT(*) FROM t1 a1 WHERE a1.a = 1
3668
AND EXISTS( SELECT a2.a FROM t1 a2 WHERE a2.a = a1.a)
3669
GROUP BY a1.a;
3670
a	COUNT(*)
3671
1	3
3672
DROP TABLE t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3673
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
3674
CREATE TABLE t2 (a INT) ENGINE=MyISAM;
1 by brian
clean slate
3675
INSERT INTO t1 VALUES (1),(2);
3676
INSERT INTO t2 VALUES (1),(2);
3677
SELECT (SELECT SUM(t1.a) FROM t2 WHERE a=0) FROM t1;
3678
(SELECT SUM(t1.a) FROM t2 WHERE a=0)
3679
NULL
3680
SELECT (SELECT SUM(t1.a) FROM t2 WHERE a!=0) FROM t1;
3681
ERROR 21000: Subquery returns more than 1 row
3682
SELECT (SELECT SUM(t1.a) FROM t2 WHERE a=1) FROM t1;
3683
(SELECT SUM(t1.a) FROM t2 WHERE a=1)
3684
3
3685
DROP TABLE t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3686
CREATE TABLE t1 (a1 INT, a2 INT) ENGINE=MyISAM;
3687
CREATE TABLE t2 (b1 INT, b2 INT) ENGINE=MyISAM;
1 by brian
clean slate
3688
INSERT INTO t1 VALUES (100, 200);
3689
INSERT INTO t1 VALUES (101, 201);
3690
INSERT INTO t2 VALUES (101, 201);
3691
INSERT INTO t2 VALUES (103, 203);
3692
SELECT ((a1,a2) IN (SELECT * FROM t2 WHERE b2 > 0)) IS NULL FROM t1;
3693
((a1,a2) IN (SELECT * FROM t2 WHERE b2 > 0)) IS NULL 
3694
0
3695
0
3696
DROP TABLE t1, t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3697
CREATE TABLE t1 (a CHAR(1), b VARCHAR(10)) ENGINE=MyISAM;
1 by brian
clean slate
3698
INSERT INTO t1 VALUES ('a', 'aa');
3699
INSERT INTO t1 VALUES ('a', 'aaa');
3700
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
3701
a	b
3702
CREATE INDEX I1 ON t1 (a);
3703
CREATE INDEX I2 ON t1 (b);
3704
EXPLAIN SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
3705
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
383.1.16 by Brian Aker
Force client communication into UTF8
3706
1	PRIMARY	t1	index	I1	I1	7	NULL	2	Using index; LooseScan
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3707
1	PRIMARY	t1	ref	I2	I2	43	test.t1.a	2	Using where
1 by brian
clean slate
3708
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
3709
a	b
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3710
CREATE TABLE t2 (a VARCHAR(1), b VARCHAR(10)) ENGINE=MyISAM;
1 by brian
clean slate
3711
INSERT INTO t2 SELECT * FROM t1;
3712
CREATE INDEX I1 ON t2 (a);
3713
CREATE INDEX I2 ON t2 (b);
3714
EXPLAIN SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2);
3715
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
383.1.16 by Brian Aker
Force client communication into UTF8
3716
1	PRIMARY	t2	index	I1	I1	7	NULL	2	Using index; LooseScan
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3717
1	PRIMARY	t2	ref	I2	I2	43	test.t2.a	2	Using where
1 by brian
clean slate
3718
SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2);
3719
a	b
3720
EXPLAIN
3721
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500);
3722
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
383.1.16 by Brian Aker
Force client communication into UTF8
3723
1	PRIMARY	t1	index	I1	I1	7	NULL	2	Using where; Using index; LooseScan
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3724
1	PRIMARY	t1	ref	I2	I2	43	test.t1.a	2	Using where
1 by brian
clean slate
3725
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500);
3726
a	b
3727
DROP TABLE t1,t2;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3728
CREATE TABLE t1(a INT, b INT) ENGINE=MyISAM;
1 by brian
clean slate
3729
INSERT INTO t1 VALUES (1,1), (1,2), (2,3), (2,4);
3730
EXPLAIN 
3731
SELECT a AS out_a, MIN(b) FROM t1
3732
WHERE b > (SELECT MIN(b) FROM t1 WHERE a = out_a)
3733
GROUP BY a;
3734
ERROR 42S22: Unknown column 'out_a' in 'where clause'
3735
SELECT a AS out_a, MIN(b) FROM t1
3736
WHERE b > (SELECT MIN(b) FROM t1 WHERE a = out_a)
3737
GROUP BY a;
3738
ERROR 42S22: Unknown column 'out_a' in 'where clause'
3739
EXPLAIN 
3740
SELECT a AS out_a, MIN(b) FROM t1 t1_outer
3741
WHERE b > (SELECT MIN(b) FROM t1 WHERE a = t1_outer.a)
3742
GROUP BY a;
3743
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
3744
1	PRIMARY	t1_outer	ALL	NULL	NULL	NULL	NULL	4	Using where; Using temporary; Using filesort
3745
2	DEPENDENT SUBQUERY	t1	ALL	NULL	NULL	NULL	NULL	4	Using where
3746
SELECT a AS out_a, MIN(b) FROM t1 t1_outer
3747
WHERE b > (SELECT MIN(b) FROM t1 WHERE a = t1_outer.a)
3748
GROUP BY a;
3749
out_a	MIN(b)
3750
1	2
3751
2	4
3752
DROP TABLE t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3753
CREATE TABLE t1 (a INT) ENGINE=MyISAM;
3754
CREATE TABLE t2 (a INT) ENGINE=MyISAM;
1 by brian
clean slate
3755
INSERT INTO t1 VALUES (1),(2);
3756
INSERT INTO t2 VALUES (1),(2);
3757
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
3758
2
3759
2
3760
2
3761
EXPLAIN EXTENDED
3762
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a));
3763
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
3764
1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
3765
2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
3766
Warnings:
3767
Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
3768
Note	1003	select 2 AS `2` from `test`.`t1` where exists(select 1 AS `1` from `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`))
1 by brian
clean slate
3769
EXPLAIN EXTENDED
3770
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION 
3771
(SELECT 1 FROM t2 WHERE t1.a = t2.a));
3772
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
3773
1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
3774
2	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
3775
3	DEPENDENT UNION	t2	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
3776
NULL	UNION RESULT	<union2,3>	ALL	NULL	NULL	NULL	NULL	NULL	NULL	
3777
Warnings:
3778
Note	1276	Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
3779
Note	1276	Field or reference 'test.t1.a' of SELECT #3 was resolved in SELECT #1
352.2.1 by Harrison Fisk
Fix for bugs 259843 and 256482
3780
Note	1003	select 2 AS `2` from `test`.`t1` where exists((select 1 AS `1` from `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`)) union (select 1 AS `1` from `test`.`t2` where (`test`.`t1`.`a` = `test`.`t2`.`a`)))
1 by brian
clean slate
3781
DROP TABLE t1,t2;
3782
CREATE TABLE t4 (
3783
f7 varchar(32) collate utf8_bin NOT NULL default '',
3784
f10 varchar(32) collate utf8_bin default NULL,
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3785
PRIMARY KEY  (f7))
3786
ENGINE=MyISAM;
1 by brian
clean slate
3787
INSERT INTO t4 VALUES(1,1), (2,null);
3788
CREATE TABLE t2 (
3789
f4 varchar(32) collate utf8_bin NOT NULL default '',
3790
f2 varchar(50) collate utf8_bin default NULL,
3791
f3 varchar(10) collate utf8_bin default NULL,
3792
PRIMARY KEY  (f4),
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3793
UNIQUE KEY uk1 (f2))
3794
ENGINE=MyISAM;
1 by brian
clean slate
3795
INSERT INTO t2 VALUES(1,1,null), (2,2,null);
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3796
CREATE TABLE t1  (
1 by brian
clean slate
3797
f8 varchar(32) collate utf8_bin NOT NULL default '',
3798
f1 varchar(10) collate utf8_bin default NULL,
3799
f9 varchar(32) collate utf8_bin default NULL,
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3800
PRIMARY KEY  (f8))
3801
ENGINE=MyISAM;
1 by brian
clean slate
3802
INSERT INTO t1 VALUES (1,'P',1), (2,'P',1), (3,'R',2);
3803
CREATE TABLE t3 (
3804
f6 varchar(32) collate utf8_bin NOT NULL default '',
3805
f5 varchar(50) collate utf8_bin default NULL,
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3806
PRIMARY KEY (f6))
3807
ENGINE=MyISAM;
1 by brian
clean slate
3808
INSERT INTO t3 VALUES (1,null), (2,null);
3809
SELECT
3810
IF(t1.f1 = 'R', a1.f2, t2.f2) AS a4,
3811
IF(t1.f1 = 'R', a1.f3, t2.f3) AS f3,
3812
SUM(
3813
IF(
3814
(SELECT VPC.f2
3815
FROM t2 VPC, t4 a2, t2 a3
3816
WHERE
3817
VPC.f4 = a2.f10 AND a3.f2 = a4
3818
LIMIT 1) IS NULL, 
3819
0, 
3820
t3.f5
3821
)
3822
) AS a6
3823
FROM 
3824
t2, t3, t1 JOIN t2 a1 ON t1.f9 = a1.f4
3825
GROUP BY a4;
3826
a4	f3	a6
3827
1	NULL	NULL
3828
2	NULL	NULL
3829
DROP TABLE t1, t2, t3, t4;
3830
End of 5.0 tests.
3831
create table t_out (subcase char(3),
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
3832
a1 char(2), b1 char(2), c1 char(2)) ENGINE=MyISAM;
3833
create table t_in  (a2 char(2), b2 char(2), c2 char(2)) ENGINE=MyISAM;
1 by brian
clean slate
3834
insert into t_out values ('A.1','2a', NULL, '2a');
3835
insert into t_out values ('A.3', '2a', NULL, '2a');
3836
insert into t_out values ('A.4', '2a', NULL, 'xx');
3837
insert into t_out values ('B.1', '2a', '2a', '2a');
3838
insert into t_out values ('B.2', '2a', '2a', '2a');
3839
insert into t_out values ('B.3', '3a', 'xx', '3a');
3840
insert into t_out values ('B.4', 'xx', '3a', '3a');
3841
insert into t_in values ('1a', '1a', '1a');
3842
insert into t_in values ('2a', '2a', '2a');
3843
insert into t_in values (NULL, '2a', '2a');
3844
insert into t_in values ('3a', NULL, '3a');
3845
3846
Test general IN semantics (not top-level)
3847
3848
case A.1
3849
select subcase,
3850
(a1, b1, c1)     IN (select * from t_in where a2 = 'no_match') pred_in,
3851
(a1, b1, c1) NOT IN (select * from t_in where a2 = 'no_match') pred_not_in
3852
from t_out where subcase = 'A.1';
3853
subcase	pred_in	pred_not_in
3854
A.1	0	1
3855
case A.2 - impossible
3856
case A.3
3857
select subcase,
3858
(a1, b1, c1)     IN (select * from t_in) pred_in,
3859
(a1, b1, c1) NOT IN (select * from t_in) pred_not_in
3860
from t_out where subcase = 'A.3';
3861
subcase	pred_in	pred_not_in
3862
A.3	NULL	NULL
3863
case A.4
3864
select subcase,
3865
(a1, b1, c1)     IN (select * from t_in) pred_in,
3866
(a1, b1, c1) NOT IN (select * from t_in) pred_not_in
3867
from t_out where subcase = 'A.4';
3868
subcase	pred_in	pred_not_in
3869
A.4	0	1
3870
case B.1
3871
select subcase,
3872
(a1, b1, c1)     IN (select * from t_in where a2 = 'no_match') pred_in,
3873
(a1, b1, c1) NOT IN (select * from t_in where a2 = 'no_match') pred_not_in
3874
from t_out where subcase = 'B.1';
3875
subcase	pred_in	pred_not_in
3876
B.1	0	1
3877
case B.2
3878
select subcase,
3879
(a1, b1, c1)     IN (select * from t_in) pred_in,
3880
(a1, b1, c1) NOT IN (select * from t_in) pred_not_in
3881
from t_out where subcase = 'B.2';
3882
subcase	pred_in	pred_not_in
3883
B.2	1	0
3884
case B.3
3885
select subcase,
3886
(a1, b1, c1)     IN (select * from t_in) pred_in,
3887
(a1, b1, c1) NOT IN (select * from t_in) pred_not_in
3888
from t_out where subcase = 'B.3';
3889
subcase	pred_in	pred_not_in
3890
B.3	NULL	NULL
3891
case B.4
3892
select subcase,
3893
(a1, b1, c1)     IN (select * from t_in) pred_in,
3894
(a1, b1, c1) NOT IN (select * from t_in) pred_not_in
3895
from t_out where subcase = 'B.4';
3896
subcase	pred_in	pred_not_in
3897
B.4	0	1
3898
3899
Test IN as top-level predicate, and
3900
as non-top level for cases A.3, B.3 (the only cases with NULL result).
3901
3902
case A.1
3903
select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out
3904
where subcase = 'A.1' and
3905
(a1, b1, c1) IN (select * from t_in where a1 = 'no_match');
3906
pred_in
3907
F
3908
select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out
3909
where subcase = 'A.1' and
3910
(a1, b1, c1) NOT IN (select * from t_in where a1 = 'no_match');
3911
pred_not_in
3912
T
3913
select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out
3914
where subcase = 'A.1' and
3915
NOT((a1, b1, c1) IN (select * from t_in where a1 = 'no_match'));
3916
not_pred_in
3917
T
3918
case A.3
3919
select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out
3920
where subcase = 'A.3' and
3921
(a1, b1, c1) IN (select * from t_in);
3922
pred_in
3923
F
3924
select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out
3925
where subcase = 'A.3' and
3926
(a1, b1, c1) NOT IN (select * from t_in);
3927
pred_not_in
3928
F
3929
select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out
3930
where subcase = 'A.3' and
3931
NOT((a1, b1, c1) IN (select * from t_in));
3932
not_pred_in
3933
F
3934
select case when count(*) > 0 then 'N' else 'wrong result' end as pred_in from t_out
3935
where subcase = 'A.3' and
3936
((a1, b1, c1) IN (select * from t_in)) is NULL and
3937
((a1, b1, c1) NOT IN (select * from t_in)) is NULL;
3938
pred_in
3939
N
3940
case A.4
3941
select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out
3942
where subcase = 'A.4' and
3943
(a1, b1, c1) IN (select * from t_in);
3944
pred_in
3945
F
3946
select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out
3947
where subcase = 'A.4' and
3948
(a1, b1, c1) NOT IN (select * from t_in);
3949
pred_not_in
3950
T
3951
select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out
3952
where subcase = 'A.4' and
3953
NOT((a1, b1, c1) IN (select * from t_in));
3954
not_pred_in
3955
T
3956
case B.1
3957
select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out
3958
where subcase = 'B.1' and
3959
(a1, b1, c1) IN (select * from t_in where a1 = 'no_match');
3960
pred_in
3961
F
3962
select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out
3963
where subcase = 'B.1' and
3964
(a1, b1, c1) NOT IN (select * from t_in where a1 = 'no_match');
3965
pred_not_in
3966
T
3967
select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out
3968
where subcase = 'B.1' and
3969
NOT((a1, b1, c1) IN (select * from t_in where a1 = 'no_match'));
3970
not_pred_in
3971
T
3972
case B.2
3973
select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out
3974
where subcase = 'B.2' and
3975
(a1, b1, c1) IN (select * from t_in);
3976
pred_in
3977
T
3978
select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out
3979
where subcase = 'B.2' and
3980
(a1, b1, c1) NOT IN (select * from t_in);
3981
pred_not_in
3982
F
3983
select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out
3984
where subcase = 'B.2' and
3985
NOT((a1, b1, c1) IN (select * from t_in));
3986
not_pred_in
3987
F
3988
case B.3
3989
select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out
3990
where subcase = 'B.3' and
3991
(a1, b1, c1) IN (select * from t_in);
3992
pred_in
3993
F
3994
select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out
3995
where subcase = 'B.3' and
3996
(a1, b1, c1) NOT IN (select * from t_in);
3997
pred_not_in
3998
F
3999
select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out
4000
where subcase = 'B.3' and
4001
NOT((a1, b1, c1) IN (select * from t_in));
4002
not_pred_in
4003
F
4004
select case when count(*) > 0 then 'N' else 'wrong result' end as pred_in from t_out
4005
where subcase = 'B.3' and
4006
((a1, b1, c1) IN (select * from t_in)) is NULL and
4007
((a1, b1, c1) NOT IN (select * from t_in)) is NULL;
4008
pred_in
4009
N
4010
case B.4
4011
select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out
4012
where subcase = 'B.4' and
4013
(a1, b1, c1) IN (select * from t_in);
4014
pred_in
4015
F
4016
select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out
4017
where subcase = 'B.4' and
4018
(a1, b1, c1) NOT IN (select * from t_in);
4019
pred_not_in
4020
T
4021
select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out
4022
where subcase = 'B.4' and
4023
NOT((a1, b1, c1) IN (select * from t_in));
4024
not_pred_in
4025
T
4026
drop table t_out;
4027
drop table t_in;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
4028
CREATE TABLE t1 (s1 char(1)) ENGINE=MyISAM;
1 by brian
clean slate
4029
INSERT INTO t1 VALUES ('a');
779.3.10 by Monty Taylor
Turned on -Wshadow.
4030
SELECT * FROM t1 WHERE 'a' = ANY (SELECT s1 FROM t1);
1 by brian
clean slate
4031
s1
4032
a
4033
DROP TABLE t1;
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
4034
CREATE TABLE t1( a INT ) ENGINE=MyISAM;
1 by brian
clean slate
4035
INSERT INTO t1 VALUES (1),(2);
642.1.58 by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB
4036
CREATE TABLE t2( a INT, b INT ) ENGINE=MyISAM;
1 by brian
clean slate
4037
SELECT * 
4038
FROM (SELECT a INTO @var FROM t1 WHERE a = 2) t1a;
629.2.6 by Monty
Updated test output with new and improved error messages.
4039
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO @var FROM t1 WHERE a = 2) t1a' at line 2
1 by brian
clean slate
4040
SELECT * 
4041
FROM (SELECT a INTO OUTFILE 'file' FROM t1 WHERE a = 2) t1a;
629.2.6 by Monty
Updated test output with new and improved error messages.
4042
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO OUTFILE 'file' FROM t1 WHERE a = 2) t1a' at line 2
1 by brian
clean slate
4043
SELECT * 
4044
FROM (SELECT a INTO DUMPFILE 'file' FROM t1 WHERE a = 2) t1a;
629.2.6 by Monty
Updated test output with new and improved error messages.
4045
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO DUMPFILE 'file' FROM t1 WHERE a = 2) t1a' at line 2
1 by brian
clean slate
4046
SELECT * FROM ( 
4047
SELECT 1 a 
4048
UNION 
4049
SELECT a INTO @var FROM t1 WHERE a = 2 
4050
) t1a;
629.2.6 by Monty
Updated test output with new and improved error messages.
4051
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO @var FROM t1 WHERE a = 2 
1 by brian
clean slate
4052
) t1a' at line 2
4053
SELECT * FROM ( 
4054
SELECT 1 a 
4055
UNION 
4056
SELECT a INTO OUTFILE 'file' FROM t1 WHERE a = 2 
4057
) t1a;
629.2.6 by Monty
Updated test output with new and improved error messages.
4058
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO OUTFILE 'file' FROM t1 WHERE a = 2 
1 by brian
clean slate
4059
) t1a' at line 2
4060
SELECT * FROM ( 
4061
SELECT 1 a 
4062
UNION 
4063
SELECT a INTO DUMPFILE 'file' FROM t1 WHERE a = 2 
4064
) t1a;
629.2.6 by Monty
Updated test output with new and improved error messages.
4065
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO DUMPFILE 'file' FROM t1 WHERE a = 2 
1 by brian
clean slate
4066
) t1a' at line 2
4067
SELECT * FROM (SELECT a FROM t1 WHERE a = 2) t1a;
4068
a
4069
2
4070
SELECT * FROM ( 
4071
SELECT a FROM t1 WHERE a = 2 
4072
UNION 
4073
SELECT a FROM t1 WHERE a = 2 
4074
) t1a;
4075
a
4076
2
4077
SELECT * FROM ( 
4078
SELECT 1 a 
4079
UNION 
4080
SELECT a FROM t1 WHERE a = 2 
4081
UNION 
4082
SELECT a FROM t1 WHERE a = 2 
4083
) t1a;
4084
a
4085
1
4086
2
4087
SELECT * FROM ((SELECT 1 a) UNION SELECT 1 a);
629.2.6 by Monty
Updated test output with new and improved error messages.
4088
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near ')' at line 1
1 by brian
clean slate
4089
SELECT * FROM (SELECT 1 a UNION (SELECT 1 a)) alias;
4090
a
4091
1
4092
SELECT * FROM (SELECT 1 UNION SELECT 1) t1a;
4093
1
4094
1
4095
SELECT * FROM ((SELECT 1 a INTO @a)) t1a;
629.2.6 by Monty
Updated test output with new and improved error messages.
4096
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO @a)) t1a' at line 1
1 by brian
clean slate
4097
SELECT * FROM ((SELECT 1 a INTO OUTFILE 'file' )) t1a;
629.2.6 by Monty
Updated test output with new and improved error messages.
4098
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO OUTFILE 'file' )) t1a' at line 1
1 by brian
clean slate
4099
SELECT * FROM ((SELECT 1 a INTO DUMPFILE 'file' )) t1a;
629.2.6 by Monty
Updated test output with new and improved error messages.
4100
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO DUMPFILE 'file' )) t1a' at line 1
1 by brian
clean slate
4101
SELECT * FROM (SELECT 1 a UNION (SELECT 1 a INTO @a)) t1a;
629.2.6 by Monty
Updated test output with new and improved error messages.
4102
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO @a)) t1a' at line 1
1 by brian
clean slate
4103
SELECT * FROM (SELECT 1 a UNION (SELECT 1 a INTO DUMPFILE 'file' )) t1a;
629.2.6 by Monty
Updated test output with new and improved error messages.
4104
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO DUMPFILE 'file' )) t1a' at line 1
1 by brian
clean slate
4105
SELECT * FROM (SELECT 1 a UNION (SELECT 1 a INTO OUTFILE 'file' )) t1a;
629.2.6 by Monty
Updated test output with new and improved error messages.
4106
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO OUTFILE 'file' )) t1a' at line 1
1 by brian
clean slate
4107
SELECT * FROM (SELECT 1 a UNION ((SELECT 1 a INTO @a))) t1a;
629.2.6 by Monty
Updated test output with new and improved error messages.
4108
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO @a))) t1a' at line 1
1 by brian
clean slate
4109
SELECT * FROM (SELECT 1 a UNION ((SELECT 1 a INTO DUMPFILE 'file' ))) t1a;
629.2.6 by Monty
Updated test output with new and improved error messages.
4110
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO DUMPFILE 'file' ))) t1a' at line 1
1 by brian
clean slate
4111
SELECT * FROM (SELECT 1 a UNION ((SELECT 1 a INTO OUTFILE 'file' ))) t1a;
629.2.6 by Monty
Updated test output with new and improved error messages.
4112
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO OUTFILE 'file' ))) t1a' at line 1
1 by brian
clean slate
4113
SELECT * FROM (SELECT 1 a ORDER BY a) t1a;
4114
a
4115
1
4116
SELECT * FROM (SELECT 1 a UNION SELECT 1 a ORDER BY a) t1a;
4117
a
4118
1
4119
SELECT * FROM (SELECT 1 a UNION SELECT 1 a LIMIT 1) t1a;
4120
a
4121
1
4122
SELECT * FROM (SELECT 1 a UNION SELECT 1 a ORDER BY a LIMIT 1) t1a;
4123
a
4124
1
4125
SELECT * FROM t1 JOIN  (SELECT 1 UNION SELECT 1) alias ON 1;
4126
a	1
4127
1	1
4128
2	1
4129
SELECT * FROM t1 JOIN ((SELECT 1 UNION SELECT 1)) ON 1;
629.2.6 by Monty
Updated test output with new and improved error messages.
4130
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near ')) ON 1' at line 1
1 by brian
clean slate
4131
SELECT * FROM t1 JOIN  (t1 t1a UNION SELECT 1)  ON 1;
629.2.6 by Monty
Updated test output with new and improved error messages.
4132
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'ON 1' at line 1
1 by brian
clean slate
4133
SELECT * FROM t1 JOIN ((t1 t1a UNION SELECT 1)) ON 1;
629.2.6 by Monty
Updated test output with new and improved error messages.
4134
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near ') ON 1' at line 1
1 by brian
clean slate
4135
SELECT * FROM t1 JOIN  (t1 t1a)  t1a ON 1;
629.2.6 by Monty
Updated test output with new and improved error messages.
4136
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 't1a ON 1' at line 1
1 by brian
clean slate
4137
SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1;
629.2.6 by Monty
Updated test output with new and improved error messages.
4138
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 't1a ON 1' at line 1
1 by brian
clean slate
4139
SELECT * FROM t1 JOIN  (t1 t1a)  ON 1;
4140
a	a
4141
1	1
4142
2	1
4143
1	2
4144
2	2
4145
SELECT * FROM t1 JOIN ((t1 t1a)) ON 1;
4146
a	a
4147
1	1
4148
2	1
4149
1	2
4150
2	2
4151
SELECT * FROM (t1 t1a);
4152
a
4153
1
4154
2
4155
SELECT * FROM ((t1 t1a));
4156
a
4157
1
4158
2
4159
SELECT * FROM t1 JOIN  (SELECT 1 t1a) alias ON 1;
4160
a	t1a
4161
1	1
4162
2	1
4163
SELECT * FROM t1 JOIN ((SELECT 1 t1a)) alias ON 1;
4164
a	t1a
4165
1	1
4166
2	1
4167
SELECT * FROM t1 JOIN  (SELECT 1 a)  a ON 1;
4168
a	a
4169
1	1
4170
2	1
4171
SELECT * FROM t1 JOIN ((SELECT 1 a)) a ON 1;
4172
a	a
4173
1	1
4174
2	1
4175
SELECT * FROM (t1 JOIN (SELECT 1) t1a1 ON 1) t1a2;
629.2.6 by Monty
Updated test output with new and improved error messages.
4176
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 't1a2' at line 1
1 by brian
clean slate
4177
SELECT * FROM t1 WHERE a = ALL ( SELECT 1 );
4178
a
4179
1
4180
SELECT * FROM t1 WHERE a = ALL ( SELECT 1 UNION SELECT 1 );
4181
a
4182
1
4183
SELECT * FROM t1 WHERE a = ANY ( SELECT 3 UNION SELECT 1 );
4184
a
4185
1
4186
SELECT * FROM t1 WHERE a = ANY ( SELECT 1 UNION SELECT 1 INTO @a);
629.2.6 by Monty
Updated test output with new and improved error messages.
4187
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO @a)' at line 1
1 by brian
clean slate
4188
SELECT * FROM t1 WHERE a = ANY ( SELECT 1 UNION SELECT 1 INTO OUTFILE 'file' );
629.2.6 by Monty
Updated test output with new and improved error messages.
4189
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO OUTFILE 'file' )' at line 1
1 by brian
clean slate
4190
SELECT * FROM t1 WHERE a = ANY ( SELECT 1 UNION SELECT 1 INTO DUMPFILE 'file' );
629.2.6 by Monty
Updated test output with new and improved error messages.
4191
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO DUMPFILE 'file' )' at line 1
1 by brian
clean slate
4192
SELECT * FROM t1 WHERE a = ( SELECT 1 );
4193
a
4194
1
4195
SELECT * FROM t1 WHERE a = ( SELECT 1 UNION SELECT 1 );
4196
a
4197
1
4198
SELECT * FROM t1 WHERE a = ( SELECT 1 INTO @a);
629.2.6 by Monty
Updated test output with new and improved error messages.
4199
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO @a)' at line 1
1 by brian
clean slate
4200
SELECT * FROM t1 WHERE a = ( SELECT 1 INTO OUTFILE 'file' );
629.2.6 by Monty
Updated test output with new and improved error messages.
4201
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO OUTFILE 'file' )' at line 1
1 by brian
clean slate
4202
SELECT * FROM t1 WHERE a = ( SELECT 1 INTO DUMPFILE 'file' );
629.2.6 by Monty
Updated test output with new and improved error messages.
4203
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO DUMPFILE 'file' )' at line 1
1 by brian
clean slate
4204
SELECT * FROM t1 WHERE a = ( SELECT 1 UNION SELECT 1 INTO @a);
629.2.6 by Monty
Updated test output with new and improved error messages.
4205
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO @a)' at line 1
1 by brian
clean slate
4206
SELECT * FROM t1 WHERE a = ( SELECT 1 UNION SELECT 1 INTO OUTFILE 'file' );
629.2.6 by Monty
Updated test output with new and improved error messages.
4207
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO OUTFILE 'file' )' at line 1
1 by brian
clean slate
4208
SELECT * FROM t1 WHERE a = ( SELECT 1 UNION SELECT 1 INTO DUMPFILE 'file' );
629.2.6 by Monty
Updated test output with new and improved error messages.
4209
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO DUMPFILE 'file' )' at line 1
1 by brian
clean slate
4210
SELECT ( SELECT 1 INTO @v );
629.2.6 by Monty
Updated test output with new and improved error messages.
4211
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO @v )' at line 1
1 by brian
clean slate
4212
SELECT ( SELECT 1 INTO OUTFILE 'file' );
629.2.6 by Monty
Updated test output with new and improved error messages.
4213
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO OUTFILE 'file' )' at line 1
1 by brian
clean slate
4214
SELECT ( SELECT 1 INTO DUMPFILE 'file' );
629.2.6 by Monty
Updated test output with new and improved error messages.
4215
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO DUMPFILE 'file' )' at line 1
1 by brian
clean slate
4216
SELECT ( SELECT 1 UNION SELECT 1 INTO @v );
629.2.6 by Monty
Updated test output with new and improved error messages.
4217
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO @v )' at line 1
1 by brian
clean slate
4218
SELECT ( SELECT 1 UNION SELECT 1 INTO OUTFILE 'file' );
629.2.6 by Monty
Updated test output with new and improved error messages.
4219
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO OUTFILE 'file' )' at line 1
1 by brian
clean slate
4220
SELECT ( SELECT 1 UNION SELECT 1 INTO DUMPFILE 'file' );
629.2.6 by Monty
Updated test output with new and improved error messages.
4221
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO DUMPFILE 'file' )' at line 1
1 by brian
clean slate
4222
SELECT ( SELECT a FROM t1 WHERE a = 1 ), a FROM t1;
4223
( SELECT a FROM t1 WHERE a = 1 )	a
4224
1	1
4225
1	2
4226
SELECT ( SELECT a FROM t1 WHERE a = 1 UNION SELECT 1 ), a FROM t1;
4227
( SELECT a FROM t1 WHERE a = 1 UNION SELECT 1 )	a
4228
1	1
4229
1	2
4230
SELECT * FROM t2 WHERE (a, b) IN (SELECT a, b FROM t2);
4231
a	b
4232
SELECT 1 UNION ( SELECT 1 UNION SELECT 1 );
629.2.6 by Monty
Updated test output with new and improved error messages.
4233
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'UNION SELECT 1 )' at line 1
1 by brian
clean slate
4234
( SELECT 1 UNION SELECT 1 ) UNION SELECT 1;
629.2.6 by Monty
Updated test output with new and improved error messages.
4235
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'UNION SELECT 1 ) UNION SELECT 1' at line 1
1 by brian
clean slate
4236
SELECT ( SELECT 1 UNION ( SELECT 1 UNION SELECT 1 ) );
629.2.6 by Monty
Updated test output with new and improved error messages.
4237
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'UNION SELECT 1 ) )' at line 1
1 by brian
clean slate
4238
SELECT ( ( SELECT 1 UNION SELECT 1 ) UNION SELECT 1;
629.2.6 by Monty
Updated test output with new and improved error messages.
4239
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'UNION SELECT 1' at line 1
1 by brian
clean slate
4240
SELECT ( SELECT 1 UNION SELECT 1 UNION SELECT 1 );
4241
( SELECT 1 UNION SELECT 1 UNION SELECT 1 )
4242
1
4243
SELECT ((SELECT 1 UNION SELECT 1 UNION SELECT 1));
4244
((SELECT 1 UNION SELECT 1 UNION SELECT 1))
4245
1
4246
SELECT * FROM ( SELECT 1 UNION ( SELECT 1 UNION SELECT 1 ) );
629.2.6 by Monty
Updated test output with new and improved error messages.
4247
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'UNION SELECT 1 ) )' at line 1
1 by brian
clean slate
4248
SELECT * FROM ( ( SELECT 1 UNION SELECT 1 ) UNION SELECT 1 );
629.2.6 by Monty
Updated test output with new and improved error messages.
4249
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near ') UNION SELECT 1 )' at line 1
1 by brian
clean slate
4250
SELECT * FROM ( SELECT 1 UNION SELECT 1 UNION SELECT 1 ) a;
4251
1
4252
1
4253
SELECT * FROM t1 WHERE a =     ( SELECT 1 UNION ( SELECT 1 UNION SELECT 1 ) );
629.2.6 by Monty
Updated test output with new and improved error messages.
4254
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'UNION SELECT 1 ) )' at line 1
1 by brian
clean slate
4255
SELECT * FROM t1 WHERE a = ALL ( SELECT 1 UNION ( SELECT 1 UNION SELECT 1 ) );
629.2.6 by Monty
Updated test output with new and improved error messages.
4256
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'UNION SELECT 1 ) )' at line 1
1 by brian
clean slate
4257
SELECT * FROM t1 WHERE a = ANY ( SELECT 1 UNION ( SELECT 1 UNION SELECT 1 ) );
629.2.6 by Monty
Updated test output with new and improved error messages.
4258
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'UNION SELECT 1 ) )' at line 1
1 by brian
clean slate
4259
SELECT * FROM t1 WHERE a IN    ( SELECT 1 UNION ( SELECT 1 UNION SELECT 1 ) );
629.2.6 by Monty
Updated test output with new and improved error messages.
4260
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'UNION SELECT 1 ) )' at line 1
1 by brian
clean slate
4261
SELECT * FROM t1 WHERE a =     ( ( SELECT 1 UNION SELECT 1 )  UNION SELECT 1 );
629.2.6 by Monty
Updated test output with new and improved error messages.
4262
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'UNION SELECT 1 )' at line 1
1 by brian
clean slate
4263
SELECT * FROM t1 WHERE a = ALL ( ( SELECT 1 UNION SELECT 1 )  UNION SELECT 1 );
629.2.6 by Monty
Updated test output with new and improved error messages.
4264
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'UNION SELECT 1 )  UNION SELECT 1 )' at line 1
1 by brian
clean slate
4265
SELECT * FROM t1 WHERE a = ANY ( ( SELECT 1 UNION SELECT 1 )  UNION SELECT 1 );
629.2.6 by Monty
Updated test output with new and improved error messages.
4266
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'UNION SELECT 1 )  UNION SELECT 1 )' at line 1
1 by brian
clean slate
4267
SELECT * FROM t1 WHERE a IN    ( ( SELECT 1 UNION SELECT 1 )  UNION SELECT 1 );
629.2.6 by Monty
Updated test output with new and improved error messages.
4268
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'UNION SELECT 1 )' at line 1
1 by brian
clean slate
4269
SELECT * FROM t1 WHERE a =     ( SELECT 1 UNION SELECT 1 UNION SELECT 1 );
4270
a
4271
1
4272
SELECT * FROM t1 WHERE a = ALL ( SELECT 1 UNION SELECT 1 UNION SELECT 1 );
4273
a
4274
1
4275
SELECT * FROM t1 WHERE a = ANY ( SELECT 1 UNION SELECT 1 UNION SELECT 1 );
4276
a
4277
1
4278
SELECT * FROM t1 WHERE a IN    ( SELECT 1 UNION SELECT 1 UNION SELECT 1 );
4279
a
4280
1
4281
SELECT * FROM t1 WHERE EXISTS ( SELECT 1 UNION SELECT 1 INTO @v );
629.2.6 by Monty
Updated test output with new and improved error messages.
4282
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO @v )' at line 1
1 by brian
clean slate
4283
SELECT EXISTS(SELECT 1+1);
4284
EXISTS(SELECT 1+1)
4285
1
4286
SELECT EXISTS(SELECT 1+1 INTO @test);
629.2.6 by Monty
Updated test output with new and improved error messages.
4287
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO @test)' at line 1
1 by brian
clean slate
4288
SELECT * FROM t1 WHERE a IN ( SELECT 1 UNION SELECT 1 INTO @v );
629.2.6 by Monty
Updated test output with new and improved error messages.
4289
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO @v )' at line 1
1 by brian
clean slate
4290
SELECT * FROM t1 WHERE EXISTS ( SELECT 1 INTO @v );
629.2.6 by Monty
Updated test output with new and improved error messages.
4291
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO @v )' at line 1
1 by brian
clean slate
4292
SELECT * FROM t1 WHERE a IN ( SELECT 1 INTO @v );
629.2.6 by Monty
Updated test output with new and improved error messages.
4293
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'INTO @v )' at line 1
1 by brian
clean slate
4294
DROP TABLE t1, t2;