1
drop table if exists t0, t1, t2, t3, t4;
2
create table t1 (oref int, grp int, ie int) ;
3
insert into t1 (oref, grp, ie) values
10
create table t2 (oref int, a int);
17
select a, oref, a in (select max(ie)
18
from t1 where oref=t2.oref group by grp) Z from t2;
26
select a, oref, a in (select max(ie)
27
from t1 where oref=t2.oref group by grp) Z from t2;
28
id select_type table type possible_keys key key_len ref rows filtered Extra
29
1 PRIMARY t2 ALL NULL NULL NULL NULL 5 100.00
30
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using temporary; Using filesort
32
Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
33
Note 1003 select "test"."t2"."a" AS "a","test"."t2"."oref" AS "oref",<in_optimizer>("test"."t2"."a",<exists>(select max("test"."t1"."ie") AS "max(ie)" from "test"."t1" where ("test"."t1"."oref" = "test"."t2"."oref") group by "test"."t1"."grp" having trigcond((<cache>("test"."t2"."a") = <ref_null_helper>(max("test"."t1"."ie")))))) AS "Z" from "test"."t2"
35
select a, oref from t2
36
where a in (select max(ie) from t1 where oref=t2.oref group by grp);
37
id select_type table type possible_keys key key_len ref rows filtered Extra
38
1 PRIMARY t2 ALL NULL NULL NULL NULL 5 100.00 Using where
39
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using temporary; Using filesort
41
Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
42
Note 1003 select "test"."t2"."a" AS "a","test"."t2"."oref" AS "oref" from "test"."t2" where <in_optimizer>("test"."t2"."a",<exists>(select max("test"."t1"."ie") AS "max(ie)" from "test"."t1" where ("test"."t1"."oref" = "test"."t2"."oref") group by "test"."t1"."grp" having (<cache>("test"."t2"."a") = <ref_null_helper>(max("test"."t1"."ie")))))
43
select a, oref, a in (
44
select max(ie) from t1 where oref=t2.oref group by grp union
45
select max(ie) from t1 where oref=t2.oref group by grp
53
create table t3 (a int);
54
insert into t3 values (NULL), (NULL);
56
select a in (select max(ie) from t1 where oref=4 group by grp) from t3;
57
a in (select max(ie) from t1 where oref=4 group by grp)
60
show status like 'Handler_read_rnd_next';
62
Handler_read_rnd_next 11
63
select ' ^ This must show 11' Z;
66
explain extended select a in (select max(ie) from t1 where oref=4 group by grp) from t3;
67
id select_type table type possible_keys key key_len ref rows filtered Extra
68
1 PRIMARY t3 ALL NULL NULL NULL NULL 2 100.00
69
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 6 100.00 Using where; Using temporary; Using filesort
71
Note 1003 select <in_optimizer>("test"."t3"."a",<exists>(select max("test"."t1"."ie") AS "max(ie)" from "test"."t1" where ("test"."t1"."oref" = 4) group by "test"."t1"."grp" having trigcond((<cache>("test"."t3"."a") = <ref_null_helper>(max("test"."t1"."ie")))))) AS "a in (select max(ie) from t1 where oref=4 group by grp)" from "test"."t3"
72
drop table t1, t2, t3;
73
create table t1 (a int, oref int, key(a));
80
create table t2 (a int, oref int);
81
insert into t2 values (1, 1), (2,2), (NULL, 3), (NULL, 4);
82
select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2;
89
select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2;
90
id select_type table type possible_keys key key_len ref rows filtered Extra
91
1 PRIMARY t2 ALL NULL NULL NULL NULL 4 100.00
92
2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 2 100.00 Using where; Full scan on NULL key
94
Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
95
Note 1003 select "test"."t2"."oref" AS "oref","test"."t2"."a" AS "a",<in_optimizer>("test"."t2"."a",<exists>(<index_lookup>(<cache>("test"."t2"."a") in t1 on a checking NULL where ("test"."t1"."oref" = "test"."t2"."oref") having trigcond(<is_not_null_test>("test"."t1"."a"))))) AS "Z" from "test"."t2"
97
select oref, a from t2 where a in (select a from t1 where oref=t2.oref);
100
show status like '%Handler_read_rnd_next';
102
Handler_read_rnd_next 11
104
insert into t2 values (NULL, 0),(NULL, 0), (NULL, 0), (NULL, 0);
106
select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2;
112
show status like '%Handler_read%';
119
Handler_read_rnd_next 29
120
select 'No key lookups, seq reads: 29= 5 reads from t2 + 4 * 6 reads from t1.' Z;
122
No key lookups, seq reads: 29= 5 reads from t2 + 4 * 6 reads from t1.
124
create table t1 (a int, b int, primary key (a));
125
insert into t1 values (1,1), (3,1),(100,1);
126
create table t2 (a int, b int);
127
insert into t2 values (1,1),(2,1),(NULL,1),(NULL,0);
128
select a,b, a in (select a from t1 where t1.b = t2.b) Z from t2 ;
135
create table t1 (a int, b int, key(a));
136
insert into t1 values
137
(0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
138
create table t2 like t1;
139
insert into t2 select * from t1;
141
create table t3 (a int, oref int);
142
insert into t3 values (1, 1), (NULL,1), (NULL,0);
144
t3.a in (select t1.a from t1, t2 where t1.b=t2.a and t2.b=t3.oref) Z
152
t3.a in (select t1.a from t1, t2 where t1.b=t2.a and t2.b=t3.oref) Z
154
id select_type table type possible_keys key key_len ref rows filtered Extra
155
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00
156
2 DEPENDENT SUBQUERY t1 ref_or_null a a 5 func 4 100.00 Using where; Full scan on NULL key
157
2 DEPENDENT SUBQUERY t2 ref a a 5 test.t1.b 1 100.00 Using where
159
Note 1276 Field or reference 'test.t3.oref' of SELECT #2 was resolved in SELECT #1
160
Note 1003 select "test"."t3"."a" AS "a","test"."t3"."oref" AS "oref",<in_optimizer>("test"."t3"."a",<exists>(select 1 AS "Not_used" from "test"."t1" join "test"."t2" where (("test"."t2"."a" = "test"."t1"."b") and ("test"."t2"."b" = "test"."t3"."oref") and trigcond(((<cache>("test"."t3"."a") = "test"."t1"."a") or isnull("test"."t1"."a")))) having trigcond(<is_not_null_test>("test"."t1"."a")))) AS "Z" from "test"."t3"
161
drop table t1, t2, t3;
162
create table t1 (a int NOT NULL, b int NOT NULL, key(a));
163
insert into t1 values
164
(0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
165
create table t2 like t1;
166
insert into t2 select * from t1;
168
create table t3 (a int, oref int);
169
insert into t3 values (1, 1), (NULL,1), (NULL,0);
171
t3.a in (select t1.a from t1, t2 where t1.b=t2.a and t2.b=t3.oref) Z
177
This must show a trig_cond:
180
t3.a in (select t1.a from t1, t2 where t1.b=t2.a and t2.b=t3.oref) Z
182
id select_type table type possible_keys key key_len ref rows filtered Extra
183
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00
184
2 DEPENDENT SUBQUERY t1 ref a a 4 func 2 100.00 Using where; Full scan on NULL key
185
2 DEPENDENT SUBQUERY t2 ref a a 4 test.t1.b 1 100.00 Using where
187
Note 1276 Field or reference 'test.t3.oref' of SELECT #2 was resolved in SELECT #1
188
Note 1003 select "test"."t3"."a" AS "a","test"."t3"."oref" AS "oref",<in_optimizer>("test"."t3"."a",<exists>(select 1 AS "Not_used" from "test"."t1" join "test"."t2" where (("test"."t2"."a" = "test"."t1"."b") and ("test"."t2"."b" = "test"."t3"."oref") and trigcond((<cache>("test"."t3"."a") = "test"."t1"."a"))))) AS "Z" from "test"."t3"
190
create table t1 (oref int, grp int);
191
insert into t1 (oref, grp) values
194
create table t2 (oref int, a int);
195
insert into t2 values
199
a in (select count(*) from t1 group by grp having grp=t2.oref) Z from t2;
203
This must show a trig_cond:
206
a in (select count(*) from t1 group by grp having grp=t2.oref) Z from t2;
207
id select_type table type possible_keys key key_len ref rows filtered Extra
208
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00
209
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary; Using filesort
211
Note 1276 Field or reference 't2.oref' of SELECT #2 was resolved in SELECT #1
212
Note 1003 select "test"."t2"."a" AS "a","test"."t2"."oref" AS "oref",<in_optimizer>("test"."t2"."a",<exists>(select count(0) AS "count(*)" from "test"."t1" group by "test"."t1"."grp" having (("test"."t1"."grp" = "test"."t2"."oref") and trigcond((<cache>("test"."t2"."a") = <ref_null_helper>(count(0))))))) AS "Z" from "test"."t2"
214
create table t1 (a int, b int, primary key (a));
215
insert into t1 values (1,1), (3,1),(100,1);
216
create table t2 (a int, b int);
217
insert into t2 values (1,1),(2,1),(NULL,1),(NULL,0);
218
select a,b, a in (select a from t1 where t1.b = t2.b union select a from
219
t1 where t1.b = t2.b) Z from t2 ;
225
select a,b, a in (select a from t1 where t1.b = t2.b) Z from t2 ;
232
create table t3 (a int);
233
insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
234
create table t2 (a int, b int, oref int);
235
insert into t2 values (NULL,1, 100), (NULL,2, 100);
236
create table t1 (a int, b int, c int, key(a,b));
237
insert into t1 select 2*A, 2*A, 100 from t3;
238
explain extended select a,b, oref, (a,b) in (select a,b from t1 where c=t2.oref) Z from t2;
239
id select_type table type possible_keys key key_len ref rows filtered Extra
240
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00
241
2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 2 100.00 Using where; Full scan on NULL key
243
Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
244
Note 1003 select "test"."t2"."a" AS "a","test"."t2"."b" AS "b","test"."t2"."oref" AS "oref",<in_optimizer>(("test"."t2"."a","test"."t2"."b"),<exists>(<index_lookup>(<cache>("test"."t2"."a") in t1 on a checking NULL where (("test"."t1"."c" = "test"."t2"."oref") and trigcond(((<cache>("test"."t2"."a") = "test"."t1"."a") or isnull("test"."t1"."a"))) and trigcond(((<cache>("test"."t2"."b") = "test"."t1"."b") or isnull("test"."t1"."b")))) having (trigcond(<is_not_null_test>("test"."t1"."a")) and trigcond(<is_not_null_test>("test"."t1"."b")))))) AS "Z" from "test"."t2"
245
select a,b, oref, (a,b) in (select a,b from t1 where c=t2.oref) Z from t2;
249
create table t4 (x int);
250
insert into t4 select A.a + 10*B.a from t1 A, t1 B;
253
(a,b) in (select a,b from t1,t4 where c=t2.oref) Z
255
id select_type table type possible_keys key key_len ref rows filtered Extra
256
1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00
257
2 DEPENDENT SUBQUERY t1 ref_or_null a a 5 func 2 100.00 Using where; Full scan on NULL key
258
2 DEPENDENT SUBQUERY t4 ALL NULL NULL NULL NULL 100 100.00 Using where; Using join buffer
260
Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
261
Note 1003 select "test"."t2"."a" AS "a","test"."t2"."b" AS "b","test"."t2"."oref" AS "oref",<in_optimizer>(("test"."t2"."a","test"."t2"."b"),<exists>(select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1" join "test"."t4" where (("test"."t1"."c" = "test"."t2"."oref") and trigcond(((<cache>("test"."t2"."a") = "test"."t1"."a") or isnull("test"."t1"."a"))) and trigcond(((<cache>("test"."t2"."b") = "test"."t1"."b") or isnull("test"."t1"."b")))) having (trigcond(<is_not_null_test>("test"."t1"."a")) and trigcond(<is_not_null_test>("test"."t1"."b"))))) AS "Z" from "test"."t2"
263
(a,b) in (select a,b from t1,t4 where c=t2.oref) Z
268
drop table t1,t2,t3,t4;
269
create table t1 (oref char(4), grp int, ie1 int, ie2 int);
270
insert into t1 (oref, grp, ie1, ie2) values
281
create table t2 (oref char(4), a int, b int);
282
insert into t2 values
290
alter table t1 add index idx(ie1,ie2);
291
select oref, a, b, (a,b) in (select ie1,ie2 from t1 where oref=t2.oref) Z from t2 where a=3 and b is null ;
294
insert into t2 values ('new1', 10,10);
295
insert into t1 values ('new1', 1234, 10, NULL);
296
select oref, a, b, (a,b) in (select ie1,ie2 from t1 where oref=t2.oref) Z from t2 where a=10 and b=10;
300
select oref, a, b, (a,b) in (select ie1,ie2 from t1 where oref=t2.oref) Z from t2 where a=10 and b=10;
301
id select_type table type possible_keys key key_len ref rows filtered Extra
302
1 PRIMARY t2 ALL NULL NULL NULL NULL 8 100.00 Using where
303
2 DEPENDENT SUBQUERY t1 index_subquery idx idx 5 func 4 100.00 Using where; Full scan on NULL key
305
Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
306
Note 1003 select "test"."t2"."oref" AS "oref","test"."t2"."a" AS "a","test"."t2"."b" AS "b",<in_optimizer>(("test"."t2"."a","test"."t2"."b"),<exists>(<index_lookup>(<cache>("test"."t2"."a") in t1 on idx checking NULL where (("test"."t1"."oref" = "test"."t2"."oref") and trigcond(((<cache>("test"."t2"."a") = "test"."t1"."ie1") or isnull("test"."t1"."ie1"))) and trigcond(((<cache>("test"."t2"."b") = "test"."t1"."ie2") or isnull("test"."t1"."ie2")))) having (trigcond(<is_not_null_test>("test"."t1"."ie1")) and trigcond(<is_not_null_test>("test"."t1"."ie2")))))) AS "Z" from "test"."t2" where (("test"."t2"."b" = 10) and ("test"."t2"."a" = 10))
308
create table t1 (oref char(4), grp int, ie int);
309
insert into t1 (oref, grp, ie) values
320
create table t2 (oref char(4), a int);
321
insert into t2 values
329
select oref, a, a in (select ie from t1 where oref=t2.oref) Z from t2;
338
select oref, a from t2 where a in (select ie from t1 where oref=t2.oref);
342
select oref, a from t2 where a not in (select ie from t1 where oref=t2.oref);
346
select oref, a, a in (select min(ie) from t1 where oref=t2.oref group by grp) Z from t2;
355
select oref, a from t2 where
356
a in (select min(ie) from t1 where oref=t2.oref group by grp);
359
select oref, a from t2 where
360
a not in (select min(ie) from t1 where oref=t2.oref group by grp);
365
update t1 set ie=3 where oref='ff' and ie=1;
366
select oref, a, a in (select min(ie) from t1 where oref=t2.oref group by
376
select oref, a from t2 where a in (select min(ie) from t1 where
377
oref=t2.oref group by grp);
381
select oref, a from t2 where a not in (select min(ie) from t1 where
382
oref=t2.oref group by grp);
386
select oref, a, a in (select min(ie) from t1 where oref=t2.oref group by
387
grp having min(ie) > 1) Z from t2;
396
select oref, a from t2 where a in (select min(ie) from t1 where
397
oref=t2.oref group by grp having min(ie) > 1);
400
select oref, a from t2 where a not in (select min(ie) from t1 where
401
oref=t2.oref group by grp having min(ie) > 1);
408
alter table t1 add index idx(ie);
409
explain select oref, a, a in (select ie from t1 where oref=t2.oref) Z from t2;
410
id select_type table type possible_keys key key_len ref rows Extra
411
1 PRIMARY t2 ALL NULL NULL NULL NULL 7
412
2 DEPENDENT SUBQUERY t1 index_subquery idx idx 5 func 4 Using where; Full scan on NULL key
413
select oref, a, a in (select ie from t1 where oref=t2.oref) Z from t2;
422
select oref, a from t2 where a in (select ie from t1 where oref=t2.oref);
426
select oref, a from t2 where a not in (select ie from t1 where oref=t2.oref);
430
alter table t1 drop index idx;
431
alter table t1 add index idx(oref,ie);
432
explain select oref, a, a in (select ie from t1 where oref=t2.oref) Z from t2;
433
id select_type table type possible_keys key key_len ref rows Extra
434
1 PRIMARY t2 ALL NULL NULL NULL NULL 7
435
2 DEPENDENT SUBQUERY t1 ref_or_null idx idx 10 test.t2.oref,func 4 Using where; Using index; Full scan on NULL key
436
select oref, a, a in (select ie from t1 where oref=t2.oref) Z from t2;
445
select oref, a from t2 where a in (select ie from t1 where oref=t2.oref);
449
select oref, a from t2 where a not in (select ie from t1 where oref=t2.oref);
455
a in (select min(ie) from t1 where oref=t2.oref
456
group by grp having min(ie) > 1) Z
458
id select_type table type possible_keys key key_len ref rows Extra
459
1 PRIMARY t2 ALL NULL NULL NULL NULL 7
460
2 DEPENDENT SUBQUERY t1 ref idx idx 5 test.t2.oref 2 Using where; Using temporary; Using filesort
462
a in (select min(ie) from t1 where oref=t2.oref
463
group by grp having min(ie) > 1) Z
473
select oref, a from t2 where a in (select min(ie) from t1 where oref=t2.oref
474
group by grp having min(ie) > 1);
477
select oref, a from t2 where a not in (select min(ie) from t1 where oref=t2.oref
478
group by grp having min(ie) > 1);
486
create table t1 (oref char(4), grp int, ie1 int, ie2 int);
487
insert into t1 (oref, grp, ie1, ie2) values
498
create table t2 (oref char(4), a int, b int);
499
insert into t2 values
507
select oref, a, b, (a,b) in (select ie1,ie2 from t1 where oref=t2.oref) Z from t2;
516
select oref, a, b from t2 where (a,b) in (select ie1,ie2 from t1 where oref=t2.oref);
520
select oref, a, b from t2 where (a,b) not in (select ie1,ie2 from t1 where oref=t2.oref);
525
(a,b) in (select min(ie1),max(ie2) from t1
526
where oref=t2.oref group by grp) Z
536
select oref, a, b from t2 where
537
(a,b) in (select min(ie1), max(ie2) from t1 where oref=t2.oref group by grp);
540
select oref, a, b from t2 where
541
(a,b) not in (select min(ie1), max(ie2) from t1 where oref=t2.oref group by grp);
547
alter table t1 add index idx(ie1,ie2);
548
explain select oref, a, b, (a,b) in (select ie1,ie2 from t1 where oref=t2.oref) Z from t2;
549
id select_type table type possible_keys key key_len ref rows Extra
550
1 PRIMARY t2 ALL NULL NULL NULL NULL 7
551
2 DEPENDENT SUBQUERY t1 index_subquery idx idx 5 func 4 Using where; Full scan on NULL key
552
select oref, a, b, (a,b) in (select ie1,ie2 from t1 where oref=t2.oref) Z from t2;
561
select oref, a, b from t2 where (a,b) in (select ie1,ie2 from t1 where oref=t2.oref);
565
select oref, a, b from t2 where (a,b) not in (select ie1,ie2 from t1 where oref=t2.oref);
570
select oref, a, b, (a,b) in (select ie1,ie2 from t1 where oref=t2.oref) Z from t2;
571
id select_type table type possible_keys key key_len ref rows filtered Extra
572
1 PRIMARY t2 ALL NULL NULL NULL NULL 7 100.00
573
2 DEPENDENT SUBQUERY t1 index_subquery idx idx 5 func 4 100.00 Using where; Full scan on NULL key
575
Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1
576
Note 1003 select "test"."t2"."oref" AS "oref","test"."t2"."a" AS "a","test"."t2"."b" AS "b",<in_optimizer>(("test"."t2"."a","test"."t2"."b"),<exists>(<index_lookup>(<cache>("test"."t2"."a") in t1 on idx checking NULL where (("test"."t1"."oref" = "test"."t2"."oref") and trigcond(((<cache>("test"."t2"."a") = "test"."t1"."ie1") or isnull("test"."t1"."ie1"))) and trigcond(((<cache>("test"."t2"."b") = "test"."t1"."ie2") or isnull("test"."t1"."ie2")))) having (trigcond(<is_not_null_test>("test"."t1"."ie1")) and trigcond(<is_not_null_test>("test"."t1"."ie2")))))) AS "Z" from "test"."t2"
578
create table t1 (oref char(4), grp int, ie int primary key);
579
insert into t1 (oref, grp, ie) values
586
create table t2 (oref char(4), a int);
587
insert into t2 values
595
explain select oref, a, a in (select ie from t1 where oref=t2.oref) Z from t2;
596
id select_type table type possible_keys key key_len ref rows Extra
597
1 PRIMARY t2 ALL NULL NULL NULL NULL 7
598
2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 Using where; Full scan on NULL key
599
select oref, a, a in (select ie from t1 where oref=t2.oref) Z from t2;
608
select oref, a from t2 where a in (select ie from t1 where oref=t2.oref);
612
select oref, a from t2 where a not in (select ie from t1 where oref=t2.oref);
618
select oref, a, a in (select min(ie) from t1 where oref=t2.oref group by grp) Z from t2;
619
id select_type table type possible_keys key key_len ref rows Extra
620
1 PRIMARY t2 ALL NULL NULL NULL NULL 7
621
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 6 Using where; Using temporary; Using filesort
622
select oref, a, a in (select min(ie) from t1 where oref=t2.oref group by grp) Z from t2;
632
create table t1 (a int, b int);
633
insert into t1 values (0,0), (2,2), (3,3);
634
create table t2 (a int, b int);
635
insert into t2 values (1,1), (3,3);
636
select a, b, (a,b) in (select a, min(b) from t2 group by a) Z from t1;
641
insert into t2 values (NULL,4);
642
select a, b, (a,b) in (select a, min(b) from t2 group by a) Z from t1;
648
CREATE TABLE t1 (a int, b INT, c CHAR(10) NOT NULL, PRIMARY KEY (a, b));
649
INSERT INTO t1 VALUES (1,1,'a'), (1,2,'b'), (1,3,'c'), (1,4,'d'), (1,5,'e'),
650
(2,1,'f'), (2,2,'g'), (2,3,'h'), (3,4,'i'),(3,3,'j'), (3,2,'k'), (3,1,'l'),
652
CREATE TABLE t2 (a int, b INT, c CHAR(10) NOT NULL, PRIMARY KEY (a, b));
653
INSERT INTO t2 SELECT * FROM t1;
654
SELECT a, MAX(b), (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b))
655
as test FROM t1 GROUP BY a;
660
SELECT * FROM t1 GROUP by t1.a
661
HAVING (MAX(t1.b) > (SELECT MAX(t2.b) FROM t2 WHERE t2.c < t1.c
662
HAVING MAX(t2.b+t1.a) < 10));
664
SELECT a,b,c FROM t1 WHERE b in (9,3,4) ORDER BY b,c;
673
(SELECT COUNT(DISTINCT t.c) FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b)
676
(SELECT t.b FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b) LIMIT 1)
678
(SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b) LIMIT 1)
680
(SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b) ORDER BY t.c LIMIT 1)
683
a MAX(b) cnt t_b t_b t_b
688
(SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b) LIMIT 1) as test
695
CREATE TABLE t1 (a int);
696
CREATE TABLE t2 (b int, PRIMARY KEY(b));
697
INSERT INTO t1 VALUES (1), (NULL), (4);
698
INSERT INTO t2 VALUES (3), (1),(2), (5), (4), (7), (6);
700
SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1));
701
id select_type table type possible_keys key key_len ref rows filtered Extra
702
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
703
1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index
704
2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
706
Note 1003 select "test"."t1"."a" AS "a" from "test"."t1" join "test"."t2" where (("test"."t2"."b" = "test"."t1"."a") and (not(<in_optimizer>("test"."t1"."a",<exists>(select 1 AS "Not_used" from "test"."t1" where ((<cache>("test"."t2"."b") = "test"."t1"."a") or isnull("test"."t1"."a")) having <is_not_null_test>("test"."t1"."a"))))))
707
SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1));
709
SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1 WHERE a > 4));
714
CREATE TABLE t1 (id int);
715
CREATE TABLE t2 (id int PRIMARY KEY);
716
CREATE TABLE t3 (id int PRIMARY KEY, name varchar(10));
717
INSERT INTO t1 VALUES (2), (NULL), (3), (1);
718
INSERT INTO t2 VALUES (234), (345), (457);
719
INSERT INTO t3 VALUES (222,'bbb'), (333,'ccc'), (111,'aaa');
722
WHERE t1.id NOT IN (SELECT t2.id FROM t2,t3
723
WHERE t3.name='xxx' AND t2.id=t3.id);
724
id select_type table type possible_keys key key_len ref rows Extra
725
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
726
2 DEPENDENT SUBQUERY t2 eq_ref PRIMARY PRIMARY 4 func 1 Using where; Using index; Full scan on NULL key
727
2 DEPENDENT SUBQUERY t3 eq_ref PRIMARY PRIMARY 4 func 1 Using index condition; Using where; Full scan on NULL key
729
WHERE t1.id NOT IN (SELECT t2.id FROM t2,t3
730
WHERE t3.name='xxx' AND t2.id=t3.id);
736
SELECT (t1.id IN (SELECT t2.id FROM t2,t3
737
WHERE t3.name='xxx' AND t2.id=t3.id)) AS x
745
CREATE TABLE t1 (a INT NOT NULL);
746
INSERT INTO t1 VALUES (1),(-1), (65),(66);
747
CREATE TABLE t2 (a INT UNSIGNED NOT NULL PRIMARY KEY);
748
INSERT INTO t2 VALUES (65),(66);
749
SELECT a FROM t1 WHERE a NOT IN (65,66);
753
SELECT a FROM t1 WHERE a NOT IN (SELECT a FROM t2);
757
EXPLAIN SELECT a FROM t1 WHERE a NOT IN (SELECT a FROM t2);
758
id select_type table type possible_keys key key_len ref rows Extra
759
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where
760
2 DEPENDENT SUBQUERY t2 unique_subquery PRIMARY PRIMARY 4 func 1 Using index; Using where
762
CREATE TABLE t1 (a INT);
763
INSERT INTO t1 VALUES(1);
764
CREATE TABLE t2 (placeholder CHAR(11));
765
INSERT INTO t2 VALUES("placeholder");
766
SELECT ROW(1, 2) IN (SELECT t1.a, 2) FROM t1 GROUP BY t1.a;
767
ROW(1, 2) IN (SELECT t1.a, 2)
769
SELECT ROW(1, 2) IN (SELECT t1.a, 2 FROM t2) FROM t1 GROUP BY t1.a;
770
ROW(1, 2) IN (SELECT t1.a, 2 FROM t2)
773
create table t1 (a int, b decimal(13, 3));
774
insert into t1 values (1, 0.123);
775
select a, (select max(b) from t1) into outfile "subselect.out.file.1" from t1;
777
load data infile "subselect.out.file.1" into table t1;