46
pk1 char(200), pk2 char(200), pk3 char(200),
46
pk1 char(100), pk2 char(100), pk3 char(100),
47
47
primary key(pk1, pk2, pk3)
49
49
insert into t3 select a,a, a,a,a from t0;
50
50
explain select * from t3 where b in (select a from t1);
51
51
id select_type table type possible_keys key key_len ref rows Extra
52
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Start temporary
53
1 PRIMARY t3 ref b b 5 test.t1.a 1 End temporary
52
1 PRIMARY t3 ALL NULL NULL NULL NULL 10 Using where
53
2 SUBQUERY t1 ALL NULL NULL NULL NULL 3
54
54
select * from t3 where b in (select a from t1);
111
108
drop table t1, t2, t3;
112
109
set @save_join_buffer_size = @@join_buffer_size;
113
set join_buffer_size= 8000;
110
set join_buffer_size=8000;
115
Warning 1292 Truncated incorrect join_buffer_size value: '8000'
116
create table t1 (a int, filler1 binary(200), filler2 binary(200));
112
Error 1292 Truncated incorrect join_buffer_size value: '8000'
113
create table t1 (a int, filler1 varbinary(20), filler2 varbinary(20));
117
114
insert into t1 select a, 'filler123456', 'filler123456' from t0;
118
115
insert into t1 select a+10, 'filler123456', 'filler123456' from t0;
119
116
create table t2 as select * from t1;
124
121
insert into t2 values (19, 'duplicate ok', 'duplicate ok');
126
123
a, mid(filler1, 1,10), length(filler1)=length(filler2) as Z
127
from t1 ot where a in (select a from t2 it);
124
from t1 t0 where a in (select a from t2 it);
128
125
id select_type table type possible_keys key key_len ref rows Extra
129
1 PRIMARY it ALL NULL NULL NULL NULL 22 Start temporary
130
1 PRIMARY ot ALL NULL NULL NULL NULL 32 Using where; End temporary; Using join buffer
126
1 PRIMARY t0 ALL NULL NULL NULL NULL 32 Using where
127
2 SUBQUERY it ALL NULL NULL NULL NULL 22
132
129
a, mid(filler1, 1,10), length(filler1)=length(filler2) as Z
133
from t1 ot where a in (select a from t2 it);
130
from t1 t0 where a in (select a from t2 it);
134
131
a mid(filler1, 1,10) Z
158
155
a, mid(filler1, 1,10), length(filler1)=length(filler2)
159
from t2 ot where a in (select a from t1 it);
156
from t2 t0 where a in (select a from t1 it);
160
157
id select_type table type possible_keys key key_len ref rows Extra
161
1 PRIMARY ot ALL NULL NULL NULL NULL 22 Start temporary
162
1 PRIMARY it ALL NULL NULL NULL NULL 32 Using where; End temporary; Using join buffer
158
1 PRIMARY t0 ALL NULL NULL NULL NULL 22 Using where
159
2 SUBQUERY it ALL NULL NULL NULL NULL 32
164
161
a, mid(filler1, 1,10), length(filler1)=length(filler2)
165
from t2 ot where a in (select a from t1 it);
162
from t2 t0 where a in (select a from t1 it);
166
163
a mid(filler1, 1,10) length(filler1)=length(filler2)
189
186
insert into t1 select a+20, 'filler123456', 'filler123456' from t0;
190
187
insert into t1 select a+20, 'filler123456', 'filler123456' from t0;
192
189
a, mid(filler1, 1,10), length(filler1)=length(filler2) as Z
193
from t1 ot where a in (select a from t2 it);
190
from t1 t0 where a in (select a from t2 it);
194
191
id select_type table type possible_keys key key_len ref rows Extra
195
1 PRIMARY it ALL NULL NULL NULL NULL 22 Start temporary
196
1 PRIMARY ot ALL NULL NULL NULL NULL 52 Using where; End temporary; Using join buffer
192
1 PRIMARY t0 ALL NULL NULL NULL NULL 52 Using where
193
2 SUBQUERY it ALL NULL NULL NULL NULL 22
198
195
a, mid(filler1, 1,10), length(filler1)=length(filler2) as Z
199
from t1 ot where a in (select a from t2 it);
196
from t1 t0 where a in (select a from t2 it);
200
197
a mid(filler1, 1,10) Z
224
221
a, mid(filler1, 1,10), length(filler1)=length(filler2)
225
from t2 ot where a in (select a from t1 it);
222
from t2 t0 where a in (select a from t1 it);
226
223
id select_type table type possible_keys key key_len ref rows Extra
227
1 PRIMARY ot ALL NULL NULL NULL NULL 22 Start temporary
228
1 PRIMARY it ALL NULL NULL NULL NULL 52 Using where; End temporary; Using join buffer
224
1 PRIMARY t0 ALL NULL NULL NULL NULL 22 Using where
225
2 SUBQUERY it ALL NULL NULL NULL NULL 52
230
227
a, mid(filler1, 1,10), length(filler1)=length(filler2)
231
from t2 ot where a in (select a from t1 it);
228
from t2 t0 where a in (select a from t1 it);
232
229
a mid(filler1, 1,10) length(filler1)=length(filler2)
264
261
from t0 where a in
265
262
(select t2.a+t3.a from t1 left join (t2 join t3) on t2.a=t1.a and t3.a=t1.a);
266
263
id select_type table type possible_keys key key_len ref rows Extra
267
1 PRIMARY t0 ALL NULL NULL NULL NULL 10 Start temporary
268
1 PRIMARY t1 index NULL a 5 NULL 10 Using index; Using join buffer
269
1 PRIMARY t2 ref a a 5 test.t1.a 1 Using index
270
1 PRIMARY t3 ref a a 5 test.t1.a 1 Using where; Using index; End temporary
264
1 PRIMARY t0 ALL NULL NULL NULL NULL 10 Using where
265
2 SUBQUERY t1 index NULL a 5 NULL 10 Using index
266
2 SUBQUERY t2 ref a a 5 test.t1.a 1 Using index
267
2 SUBQUERY t3 ref a a 5 test.t1.a 1 Using index
271
268
drop table t0, t1,t2,t3;
272
269
CREATE TABLE t1 (
273
ID int(11) NOT NULL auto_increment,
270
ID int NOT NULL auto_increment,
274
271
Name char(35) NOT NULL default '',
275
272
Country char(3) NOT NULL default '',
276
Population int(11) NOT NULL default '0',
273
Population int NOT NULL default '0',
277
274
PRIMARY KEY (ID),
278
275
INDEX (Population),
303
300
WHERE Language='English' AND Percentage > 10 AND
304
301
t2.Population > 100000);
305
302
id select_type table type possible_keys key key_len ref rows Extra
306
1 PRIMARY t1 ALL Population,Country NULL NULL NULL 30 Using where; Start temporary
307
1 PRIMARY t3 eq_ref PRIMARY,Percentage PRIMARY 33 test.t1.Country,const 1 Using index condition; Using where
308
1 PRIMARY t2 eq_ref PRIMARY,Population PRIMARY 3 test.t3.Country 1 Using index condition; Using where; End temporary
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 range Population Population 4 NULL 1 Using where
309
306
DROP TABLE t1,t2,t3;
310
307
CREATE TABLE t1 (
311
308
Code char(3) NOT NULL DEFAULT '',
313
310
Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL DEFAULT 'Asia',
314
311
Region char(26) NOT NULL DEFAULT '',
315
312
SurfaceArea float(10,2) NOT NULL DEFAULT '0.00',
316
IndepYear smallint(6) DEFAULT NULL,
317
Population int(11) NOT NULL DEFAULT '0',
313
IndepYear int DEFAULT NULL,
314
Population int NOT NULL DEFAULT '0',
318
315
LifeExpectancy float(3,1) DEFAULT NULL,
319
316
GNP float(10,2) DEFAULT NULL,
320
317
GNPOld float(10,2) DEFAULT NULL,
321
318
LocalName char(45) NOT NULL DEFAULT '',
322
319
GovernmentForm char(45) NOT NULL DEFAULT '',
323
320
HeadOfState char(60) DEFAULT NULL,
324
Capital int(11) DEFAULT NULL,
321
Capital int DEFAULT NULL,
325
322
Code2 char(2) NOT NULL DEFAULT '',
326
323
PRIMARY KEY (Code)
328
325
CREATE TABLE t2 (
329
ID int(11) NOT NULL AUTO_INCREMENT,
330
327
Name char(35) NOT NULL DEFAULT '',
331
328
CountryCode char(3) NOT NULL DEFAULT '',
332
District char(20) NOT NULL DEFAULT '',
333
Population int(11) NOT NULL DEFAULT '0',
329
Population int NOT NULL DEFAULT '0',
334
330
PRIMARY KEY (ID),
335
331
KEY CountryCode (CountryCode)
340
336
WHERE t1.Code IN (
341
337
SELECT t2.CountryCode FROM t2 WHERE Population > 5000000);
342
338
id select_type table type possible_keys key key_len ref rows Extra
343
1 PRIMARY t2 ALL CountryCode NULL NULL NULL 545 Using where; Start temporary
344
1 PRIMARY t1 eq_ref PRIMARY PRIMARY 3 test.t2.CountryCode 1 End temporary
339
1 PRIMARY t1 ALL NULL NULL NULL NULL 31 Using where
340
2 SUBQUERY t2 ALL NULL NULL NULL NULL 125 Using where
345
341
SELECT Name FROM t1
346
342
WHERE t1.Code IN (
347
343
SELECT t2.CountryCode FROM t2 WHERE Population > 5000000);
353
345
drop table t1, t2;
354
CREATE TABLE t1(a INT);
355
CREATE TABLE t2(c INT);
356
CREATE PROCEDURE p1(v1 int)
358
SELECT 1 FROM t1 WHERE a = v1 AND a IN (SELECT c FROM t2);
361
CREATE PROCEDURE p2(v1 int)
363
SELECT 1 FROM t1 WHERE a IN (SELECT c FROM t2);
366
CREATE PROCEDURE p3(v1 int)
370
t1 t01,t1 t02,t1 t03,t1 t04,t1 t05,t1 t06,t1 t07,t1 t08,
371
t1 t09,t1 t10,t1 t11,t1 t12,t1 t13,t1 t14,t1 t15,t1 t16,
372
t1 t17,t1 t18,t1 t19,t1 t20,t1 t21,t1 t22,t1 t23,t1 t24,
373
t1 t25,t1 t26,t1 t27,t1 t28,t1 t29,t1 t30,t1 t31,t1 t32,
374
t1 t33,t1 t34,t1 t35,t1 t36,t1 t37,t1 t38,t1 t39,t1 t40,
375
t1 t41,t1 t42,t1 t43,t1 t44,t1 t45,t1 t46,t1 t47,t1 t48,
376
t1 t49,t1 t50,t1 t51,t1 t52,t1 t53,t1 t54,t1 t55,t1 t56,
377
t1 t57,t1 t58,t1 t59,t1 t60
378
WHERE t01.a IN (SELECT c FROM t2);
381
CREATE PROCEDURE p4(v1 int)
385
t1 t01,t1 t02,t1 t03,t1 t04,t1 t05,t1 t06,t1 t07,t1 t08,
386
t1 t09,t1 t10,t1 t11,t1 t12,t1 t13,t1 t14,t1 t15,t1 t16,
387
t1 t17,t1 t18,t1 t19,t1 t20,t1 t21,t1 t22,t1 t23,t1 t24,
388
t1 t25,t1 t26,t1 t27,t1 t28,t1 t29,t1 t30,t1 t31,t1 t32,
389
t1 t33,t1 t34,t1 t35,t1 t36,t1 t37,t1 t38,t1 t39,t1 t40,
390
t1 t41,t1 t42,t1 t43,t1 t44,t1 t45,t1 t46,t1 t47,t1 t48,
391
t1 t49,t1 t50,t1 t51,t1 t52,t1 t53,t1 t54,t1 t55,t1 t56,
392
t1 t57,t1 t58,t1 t59,t1 t60
393
WHERE t01.a = v1 AND t01.a IN (SELECT c FROM t2);