1
drop table if exists t0, t1, t2, t3;
2
create table t0 (a int);
3
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
8
insert into t1 values (1,1),(1,1),(2,2);
14
insert into t2 select a, a/2 from t0;
32
explain select * from t2 where b in (select a from t1);
33
id select_type table type possible_keys key key_len ref rows Extra
34
1 PRIMARY t2 ALL NULL NULL NULL NULL 10 Using where
35
2 SUBQUERY t1 ALL NULL NULL NULL NULL 3
36
select * from t2 where b in (select a from t1);
46
pk1 char(100), pk2 char(100), pk3 char(100),
47
primary key(pk1, pk2, pk3)
49
insert into t3 select a,a, a,a,a from t0;
50
explain select * from t3 where b in (select a from t1);
51
id select_type table type possible_keys key key_len ref rows Extra
52
1 PRIMARY t3 ALL NULL NULL NULL NULL 10 Using where
53
2 SUBQUERY t1 ALL NULL NULL NULL NULL 3
54
select * from t3 where b in (select a from t1);
58
set @save_max_heap_table_size= @@max_heap_table_size;
59
set max_heap_table_size=16384;
60
set @save_join_buffer_size = @@join_buffer_size;
66
pk1 char(100), pk2 char(100),
70
A.a + 10*B.a, A.a + 10*B.a, A.a + 10*B.a, A.a + 10*B.a
71
from t0 A, t0 B where B.a <5;
72
explain select * from t3 where b in (select a from t0);
73
id select_type table type possible_keys key key_len ref rows Extra
74
1 PRIMARY t3 ALL NULL NULL NULL NULL 50 Using where
75
2 SUBQUERY t0 ALL NULL NULL NULL NULL 10
76
select * from t3 where b in (select A.a+B.a from t0 A, t0 B where B.a<5);
92
set join_buffer_size= @save_join_buffer_size;
93
set max_heap_table_size= @save_max_heap_table_size;
94
explain select * from t1 where a in (select b from t2);
95
id select_type table type possible_keys key key_len ref rows Extra
96
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
97
2 SUBQUERY t2 ALL NULL NULL NULL NULL 10
103
select * from t1 where a in (select b from t2);
108
drop table t1, t2, t3;
109
set @save_join_buffer_size = @@join_buffer_size;
110
set join_buffer_size=8000;
112
Error 1292 Truncated incorrect join_buffer_size value: '8000'
113
create table t1 (a int, filler1 varbinary(20), filler2 varbinary(20));
114
insert into t1 select a, 'filler123456', 'filler123456' from t0;
115
insert into t1 select a+10, 'filler123456', 'filler123456' from t0;
116
create table t2 as select * from t1;
117
insert into t1 select a+20, 'filler123456', 'filler123456' from t0;
118
insert into t1 values (2, 'duplicate ok', 'duplicate ok');
119
insert into t1 values (18, 'duplicate ok', 'duplicate ok');
120
insert into t2 values (3, 'duplicate ok', 'duplicate ok');
121
insert into t2 values (19, 'duplicate ok', 'duplicate ok');
123
a, mid(filler1, 1,10), length(filler1)=length(filler2) as Z
124
from t1 t0 where a in (select a from t2 it);
125
id select_type table type possible_keys key key_len ref rows Extra
126
1 PRIMARY t0 ALL NULL NULL NULL NULL 32 Using where
127
2 SUBQUERY it ALL NULL NULL NULL NULL 22
129
a, mid(filler1, 1,10), length(filler1)=length(filler2) as Z
130
from t1 t0 where a in (select a from t2 it);
131
a mid(filler1, 1,10) Z
155
a, mid(filler1, 1,10), length(filler1)=length(filler2)
156
from t2 t0 where a in (select a from t1 it);
157
id select_type table type possible_keys key key_len ref rows Extra
158
1 PRIMARY t0 ALL NULL NULL NULL NULL 22 Using where
159
2 SUBQUERY it ALL NULL NULL NULL NULL 32
161
a, mid(filler1, 1,10), length(filler1)=length(filler2)
162
from t2 t0 where a in (select a from t1 it);
163
a mid(filler1, 1,10) length(filler1)=length(filler2)
186
insert into t1 select a+20, 'filler123456', 'filler123456' from t0;
187
insert into t1 select a+20, 'filler123456', 'filler123456' from t0;
189
a, mid(filler1, 1,10), length(filler1)=length(filler2) as Z
190
from t1 t0 where a in (select a from t2 it);
191
id select_type table type possible_keys key key_len ref rows Extra
192
1 PRIMARY t0 ALL NULL NULL NULL NULL 52 Using where
193
2 SUBQUERY it ALL NULL NULL NULL NULL 22
195
a, mid(filler1, 1,10), length(filler1)=length(filler2) as Z
196
from t1 t0 where a in (select a from t2 it);
197
a mid(filler1, 1,10) Z
221
a, mid(filler1, 1,10), length(filler1)=length(filler2)
222
from t2 t0 where a in (select a from t1 it);
223
id select_type table type possible_keys key key_len ref rows Extra
224
1 PRIMARY t0 ALL NULL NULL NULL NULL 22 Using where
225
2 SUBQUERY it ALL NULL NULL NULL NULL 52
227
a, mid(filler1, 1,10), length(filler1)=length(filler2)
228
from t2 t0 where a in (select a from t1 it);
229
a mid(filler1, 1,10) length(filler1)=length(filler2)
253
create table t1 (a int, b int, key(a));
254
create table t2 (a int, b int, key(a));
255
create table t3 (a int, b int, key(a));
256
insert into t1 select a,a from t0;
257
insert into t2 select a,a from t0;
258
insert into t3 select a,a from t0;
259
t2 and t3 must be use 'ref', not 'ALL':
262
(select t2.a+t3.a from t1 left join (t2 join t3) on t2.a=t1.a and t3.a=t1.a);
263
id select_type table type possible_keys key key_len ref rows Extra
264
1 PRIMARY t0 ALL NULL NULL NULL NULL 10 Using where
265
2 SUBQUERY t1 ALL NULL NULL NULL NULL 10
266
2 SUBQUERY t2 ref a a 5 test.t1.a 1
267
2 SUBQUERY t3 ref a a 5 test.t1.a 1
268
drop table t0, t1,t2,t3;
270
ID int NOT NULL auto_increment,
271
Name char(35) NOT NULL default '',
272
Country char(3) NOT NULL default '',
273
Population int NOT NULL default '0',
279
Code char(3) NOT NULL default '',
280
Name char(52) NOT NULL default '',
281
SurfaceArea float(10,2) NOT NULL default '0.00',
282
Population int NOT NULL default '0',
283
Capital int default NULL,
289
Country char(3) NOT NULL default '',
290
Language char(30) NOT NULL default '',
291
Percentage float(3,1) NOT NULL default '0.0',
292
PRIMARY KEY (Country, Language),
297
WHERE t2.Code IN (SELECT Country FROM t1 WHERE Population > 5000000)
299
t2.Code IN (SELECT Country FROM t3
300
WHERE Language='English' AND Percentage > 10 AND
301
t2.Population > 100000);
302
id select_type table type possible_keys key key_len ref rows Extra
303
1 PRIMARY t2 ALL NULL NULL NULL NULL 16 Using where
304
3 DEPENDENT SUBQUERY t3 unique_subquery PRIMARY,Percentage PRIMARY 136 func,const 1 Using where
305
2 SUBQUERY t1 ALL Population NULL NULL NULL 30 Using where
308
Code char(3) NOT NULL DEFAULT '',
309
Name char(52) NOT NULL DEFAULT '',
310
Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL DEFAULT 'Asia',
311
Region char(26) NOT NULL DEFAULT '',
312
SurfaceArea float(10,2) NOT NULL DEFAULT '0.00',
313
IndepYear int DEFAULT NULL,
314
Population int NOT NULL DEFAULT '0',
315
LifeExpectancy float(3,1) DEFAULT NULL,
316
GNP float(10,2) DEFAULT NULL,
317
GNPOld float(10,2) DEFAULT NULL,
318
LocalName char(45) NOT NULL DEFAULT '',
319
GovernmentForm char(45) NOT NULL DEFAULT '',
320
HeadOfState char(60) DEFAULT NULL,
321
Capital int DEFAULT NULL,
322
Code2 char(2) NOT NULL DEFAULT '',
327
Name char(35) NOT NULL DEFAULT '',
328
CountryCode char(3) NOT NULL DEFAULT '',
329
Population int NOT NULL DEFAULT '0',
331
KEY CountryCode (CountryCode)
333
Fill the table with test data
334
This must not use LooseScan:
335
EXPLAIN SELECT Name FROM t1
337
SELECT t2.CountryCode FROM t2 WHERE Population > 5000000);
338
id select_type table type possible_keys key key_len ref rows Extra
339
1 PRIMARY t1 ALL NULL NULL NULL NULL 31 Using where
340
2 SUBQUERY t2 ALL NULL NULL NULL NULL 125 Using where
343
SELECT t2.CountryCode FROM t2 WHERE Population > 5000000);
347
# MySQL BUG #42742: crash in setup_sj_materialization, Copy_field::set
349
create table t3 ( c1 date) engine=innodb;
350
insert into t3 values ('2009-10-22'),('2142-10-22');
351
create table t2 (c1 tinytext,c2 text,c6 timestamp) engine=innodb;
356
explain select 1 from t2 where c2 in (select 1 from t3, t2) and c1 in (select convert(c6,char(1)) from t2);
357
id select_type table type possible_keys key key_len ref rows Extra
358
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where
359
3 SUBQUERY t2 ALL NULL NULL NULL NULL 1
360
2 SUBQUERY t2 ALL NULL NULL NULL NULL 1
361
2 SUBQUERY t3 ALL NULL NULL NULL NULL 2 Using join buffer