1DROP TABLE IF EXISTS t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11;
2DROP DATABASE IF EXISTS world;
3set @org_optimizer_switch=@@optimizer_switch;
4set @save_join_cache_level=@@join_cache_level;
5set @save_join_buffer_space_limit=@@join_buffer_space_limit;
6set @save_join_buffer_size=@@join_buffer_size;
7set @save_expensive_subquery_limit=@@expensive_subquery_limit;
8set @@optimizer_switch='optimize_join_buffer_size=on';
9set @@optimizer_switch='semijoin=on,firstmatch=on,loosescan=on';
10set @@optimizer_switch='semijoin_with_cache=on';
11set @@optimizer_switch='outer_join_with_cache=on';
12set @@optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on';
13set @local_optimizer_switch=@@optimizer_switch;
14set @innodb_stats_persistent_save= @@innodb_stats_persistent;
15set @innodb_stats_persistent_sample_pages_save=
16@@innodb_stats_persistent_sample_pages;
17set global innodb_stats_persistent= 1;
18set global innodb_stats_persistent_sample_pages=100;
19set names utf8;
20CREATE DATABASE world;
21use world;
22CREATE TABLE Country (
23Code char(3) NOT NULL default '',
24Name char(52) NOT NULL default '',
25SurfaceArea float(10,2) NOT NULL default '0.00',
26Population int(11) NOT NULL default '0',
27Capital int(11) default NULL
28);
29CREATE TABLE City (
30ID int(11) NOT NULL,
31Name char(35) NOT NULL default '',
32Country char(3) NOT NULL default '',
33Population int(11) NOT NULL default '0'
34);
35CREATE TABLE CountryLanguage (
36Country char(3) NOT NULL default '',
37Language char(30) NOT NULL default '',
38Percentage float(3,1) NOT NULL default '0.0'
39);
40SELECT COUNT(*) FROM Country;
41COUNT(*)
42239
43SELECT COUNT(*) FROM City;
44COUNT(*)
454079
46SELECT COUNT(*) FROM CountryLanguage;
47COUNT(*)
48984
49show variables like 'join_buffer_size';
50Variable_name	Value
51join_buffer_size	262144
52set join_cache_level=1;
53show variables like 'join_cache_level';
54Variable_name	Value
55join_cache_level	1
56EXPLAIN
57SELECT City.Name, Country.Name FROM City,Country
58WHERE City.Country=Country.Code AND
59Country.Name LIKE 'L%' AND City.Population > 100000;
60id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
611	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
621	SIMPLE	City	ALL	NULL	NULL	NULL	NULL	4079	Using where; Using join buffer (flat, BNL join)
63SELECT City.Name, Country.Name FROM City,Country
64WHERE City.Country=Country.Code AND
65Country.Name LIKE 'L%' AND City.Population > 100000;
66Name	Name
67?iauliai	Lithuania
68Beirut	Lebanon
69Bengasi	Libyan Arab Jamahiriya
70Daugavpils	Latvia
71Kaunas	Lithuania
72Klaipeda	Lithuania
73Maseru	Lesotho
74Misrata	Libyan Arab Jamahiriya
75Monrovia	Liberia
76Panevezys	Lithuania
77Riga	Latvia
78Tripoli	Lebanon
79Tripoli	Libyan Arab Jamahiriya
80Vientiane	Laos
81Vilnius	Lithuania
82EXPLAIN
83SELECT City.Name, Country.Name, CountryLanguage.Language
84FROM City,Country,CountryLanguage
85WHERE City.Country=Country.Code AND
86CountryLanguage.Country=Country.Code AND
87City.Name LIKE 'L%' AND Country.Population > 3000000 AND
88CountryLanguage.Percentage > 50 AND
89LENGTH(Language) < LENGTH(City.Name) - 2;
90id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
911	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
921	SIMPLE	CountryLanguage	ALL	NULL	NULL	NULL	NULL	984	Using where; Using join buffer (flat, BNL join)
931	SIMPLE	City	ALL	NULL	NULL	NULL	NULL	4079	Using where; Using join buffer (flat, BNL join)
94SELECT City.Name, Country.Name, CountryLanguage.Language
95FROM City,Country,CountryLanguage
96WHERE City.Country=Country.Code AND
97CountryLanguage.Country=Country.Code AND
98City.Name LIKE 'L%' AND Country.Population > 3000000 AND
99CountryLanguage.Percentage > 50 AND
100LENGTH(Language) < LENGTH(City.Name) - 2;
101Name	Name	Language
102La Matanza	Argentina	Spanish
103Lagos de Moreno	Mexico	Spanish
104Lalitapur	Nepal	Nepali
105Las Margaritas	Mexico	Spanish
106Las Palmas de Gran Canaria	Spain	Spanish
107Lashio (Lasho)	Myanmar	Burmese
108Lauro de Freitas	Brazil	Portuguese
109Lengshuijiang	China	Chinese
110Leninsk-Kuznetski	Russian Federation	Russian
111Leverkusen	Germany	German
112Lexington-Fayette	United States	English
113Liangcheng	China	Chinese
114Lianyungang	China	Chinese
115Little Rock	United States	English
116Liupanshui	China	Chinese
117Lleida (Lérida)	Spain	Spanish
118Lomas de Zamora	Argentina	Spanish
119Long Beach	United States	English
120Los Angeles	Chile	Spanish
121Los Angeles	United States	English
122Los Teques	Venezuela	Spanish
123Louisville	United States	English
124Lower Hutt	New Zealand	English
125Luchou	Taiwan	Min
126Ludwigshafen am Rhein	Germany	German
127Lungtan	Taiwan	Min
128L´Hospitalet de Llobregat	Spain	Spanish
129Lázaro Cárdenas	Mexico	Spanish
130set join_cache_level=2;
131show variables like 'join_cache_level';
132Variable_name	Value
133join_cache_level	2
134EXPLAIN
135SELECT City.Name, Country.Name FROM City,Country
136WHERE City.Country=Country.Code AND
137Country.Name LIKE 'L%' AND City.Population > 100000;
138id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1391	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
1401	SIMPLE	City	ALL	NULL	NULL	NULL	NULL	4079	Using where; Using join buffer (flat, BNL join)
141SELECT City.Name, Country.Name FROM City,Country
142WHERE City.Country=Country.Code AND
143Country.Name LIKE 'L%' AND City.Population > 100000;
144Name	Name
145?iauliai	Lithuania
146Beirut	Lebanon
147Bengasi	Libyan Arab Jamahiriya
148Daugavpils	Latvia
149Kaunas	Lithuania
150Klaipeda	Lithuania
151Maseru	Lesotho
152Misrata	Libyan Arab Jamahiriya
153Monrovia	Liberia
154Panevezys	Lithuania
155Riga	Latvia
156Tripoli	Lebanon
157Tripoli	Libyan Arab Jamahiriya
158Vientiane	Laos
159Vilnius	Lithuania
160EXPLAIN
161SELECT City.Name, Country.Name, CountryLanguage.Language
162FROM City,Country,CountryLanguage
163WHERE City.Country=Country.Code AND
164CountryLanguage.Country=Country.Code AND
165City.Name LIKE 'L%' AND Country.Population > 3000000 AND
166CountryLanguage.Percentage > 50 AND
167LENGTH(Language) < LENGTH(City.Name) - 2;
168id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1691	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
1701	SIMPLE	CountryLanguage	ALL	NULL	NULL	NULL	NULL	984	Using where; Using join buffer (flat, BNL join)
1711	SIMPLE	City	ALL	NULL	NULL	NULL	NULL	4079	Using where; Using join buffer (incremental, BNL join)
172SELECT City.Name, Country.Name, CountryLanguage.Language
173FROM City,Country,CountryLanguage
174WHERE City.Country=Country.Code AND
175CountryLanguage.Country=Country.Code AND
176City.Name LIKE 'L%' AND Country.Population > 3000000 AND
177CountryLanguage.Percentage > 50 AND
178LENGTH(Language) < LENGTH(City.Name) - 2;
179Name	Name	Language
180La Matanza	Argentina	Spanish
181Lagos de Moreno	Mexico	Spanish
182Lalitapur	Nepal	Nepali
183Las Margaritas	Mexico	Spanish
184Las Palmas de Gran Canaria	Spain	Spanish
185Lashio (Lasho)	Myanmar	Burmese
186Lauro de Freitas	Brazil	Portuguese
187Lengshuijiang	China	Chinese
188Leninsk-Kuznetski	Russian Federation	Russian
189Leverkusen	Germany	German
190Lexington-Fayette	United States	English
191Liangcheng	China	Chinese
192Lianyungang	China	Chinese
193Little Rock	United States	English
194Liupanshui	China	Chinese
195Lleida (Lérida)	Spain	Spanish
196Lomas de Zamora	Argentina	Spanish
197Long Beach	United States	English
198Los Angeles	Chile	Spanish
199Los Angeles	United States	English
200Los Teques	Venezuela	Spanish
201Louisville	United States	English
202Lower Hutt	New Zealand	English
203Luchou	Taiwan	Min
204Ludwigshafen am Rhein	Germany	German
205Lungtan	Taiwan	Min
206L´Hospitalet de Llobregat	Spain	Spanish
207Lázaro Cárdenas	Mexico	Spanish
208set join_cache_level=3;
209show variables like 'join_cache_level';
210Variable_name	Value
211join_cache_level	3
212EXPLAIN
213SELECT City.Name, Country.Name FROM City,Country
214WHERE City.Country=Country.Code AND
215Country.Name LIKE 'L%' AND City.Population > 100000;
216id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
2171	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
2181	SIMPLE	City	hash_ALL	NULL	#hash#$hj	3	world.Country.Code	4079	Using where; Using join buffer (flat, BNLH join)
219SELECT City.Name, Country.Name FROM City,Country
220WHERE City.Country=Country.Code AND
221Country.Name LIKE 'L%' AND City.Population > 100000;
222Name	Name
223?iauliai	Lithuania
224Beirut	Lebanon
225Bengasi	Libyan Arab Jamahiriya
226Daugavpils	Latvia
227Kaunas	Lithuania
228Klaipeda	Lithuania
229Maseru	Lesotho
230Misrata	Libyan Arab Jamahiriya
231Monrovia	Liberia
232Panevezys	Lithuania
233Riga	Latvia
234Tripoli	Lebanon
235Tripoli	Libyan Arab Jamahiriya
236Vientiane	Laos
237Vilnius	Lithuania
238EXPLAIN
239SELECT City.Name, Country.Name, CountryLanguage.Language
240FROM City,Country,CountryLanguage
241WHERE City.Country=Country.Code AND
242CountryLanguage.Country=Country.Code AND
243City.Name LIKE 'L%' AND Country.Population > 3000000 AND
244CountryLanguage.Percentage > 50 AND
245LENGTH(Language) < LENGTH(City.Name) - 2;
246id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
2471	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
2481	SIMPLE	CountryLanguage	hash_ALL	NULL	#hash#$hj	3	world.Country.Code	984	Using where; Using join buffer (flat, BNLH join)
2491	SIMPLE	City	hash_ALL	NULL	#hash#$hj	3	world.Country.Code	4079	Using where; Using join buffer (flat, BNLH join)
250SELECT City.Name, Country.Name, CountryLanguage.Language
251FROM City,Country,CountryLanguage
252WHERE City.Country=Country.Code AND
253CountryLanguage.Country=Country.Code AND
254City.Name LIKE 'L%' AND Country.Population > 3000000 AND
255CountryLanguage.Percentage > 50 AND
256LENGTH(Language) < LENGTH(City.Name) - 2;
257Name	Name	Language
258La Matanza	Argentina	Spanish
259Lagos de Moreno	Mexico	Spanish
260Lalitapur	Nepal	Nepali
261Las Margaritas	Mexico	Spanish
262Las Palmas de Gran Canaria	Spain	Spanish
263Lashio (Lasho)	Myanmar	Burmese
264Lauro de Freitas	Brazil	Portuguese
265Lengshuijiang	China	Chinese
266Leninsk-Kuznetski	Russian Federation	Russian
267Leverkusen	Germany	German
268Lexington-Fayette	United States	English
269Liangcheng	China	Chinese
270Lianyungang	China	Chinese
271Little Rock	United States	English
272Liupanshui	China	Chinese
273Lleida (Lérida)	Spain	Spanish
274Lomas de Zamora	Argentina	Spanish
275Long Beach	United States	English
276Los Angeles	Chile	Spanish
277Los Angeles	United States	English
278Los Teques	Venezuela	Spanish
279Louisville	United States	English
280Lower Hutt	New Zealand	English
281Luchou	Taiwan	Min
282Ludwigshafen am Rhein	Germany	German
283Lungtan	Taiwan	Min
284L´Hospitalet de Llobregat	Spain	Spanish
285Lázaro Cárdenas	Mexico	Spanish
286set join_cache_level=4;
287show variables like 'join_cache_level';
288Variable_name	Value
289join_cache_level	4
290EXPLAIN
291SELECT City.Name, Country.Name FROM City,Country
292WHERE City.Country=Country.Code AND
293Country.Name LIKE 'L%' AND City.Population > 100000;
294id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
2951	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
2961	SIMPLE	City	hash_ALL	NULL	#hash#$hj	3	world.Country.Code	4079	Using where; Using join buffer (flat, BNLH join)
297SELECT City.Name, Country.Name FROM City,Country
298WHERE City.Country=Country.Code AND
299Country.Name LIKE 'L%' AND City.Population > 100000;
300Name	Name
301?iauliai	Lithuania
302Beirut	Lebanon
303Bengasi	Libyan Arab Jamahiriya
304Daugavpils	Latvia
305Kaunas	Lithuania
306Klaipeda	Lithuania
307Maseru	Lesotho
308Misrata	Libyan Arab Jamahiriya
309Monrovia	Liberia
310Panevezys	Lithuania
311Riga	Latvia
312Tripoli	Lebanon
313Tripoli	Libyan Arab Jamahiriya
314Vientiane	Laos
315Vilnius	Lithuania
316EXPLAIN
317SELECT City.Name, Country.Name, CountryLanguage.Language
318FROM City,Country,CountryLanguage
319WHERE City.Country=Country.Code AND
320CountryLanguage.Country=Country.Code AND
321City.Name LIKE 'L%' AND Country.Population > 3000000 AND
322CountryLanguage.Percentage > 50 AND
323LENGTH(Language) < LENGTH(City.Name) - 2;
324id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
3251	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
3261	SIMPLE	CountryLanguage	hash_ALL	NULL	#hash#$hj	3	world.Country.Code	984	Using where; Using join buffer (flat, BNLH join)
3271	SIMPLE	City	hash_ALL	NULL	#hash#$hj	3	world.Country.Code	4079	Using where; Using join buffer (incremental, BNLH join)
328SELECT City.Name, Country.Name, CountryLanguage.Language
329FROM City,Country,CountryLanguage
330WHERE City.Country=Country.Code AND
331CountryLanguage.Country=Country.Code AND
332City.Name LIKE 'L%' AND Country.Population > 3000000 AND
333CountryLanguage.Percentage > 50 AND
334LENGTH(Language) < LENGTH(City.Name) - 2;
335Name	Name	Language
336La Matanza	Argentina	Spanish
337Lagos de Moreno	Mexico	Spanish
338Lalitapur	Nepal	Nepali
339Las Margaritas	Mexico	Spanish
340Las Palmas de Gran Canaria	Spain	Spanish
341Lashio (Lasho)	Myanmar	Burmese
342Lauro de Freitas	Brazil	Portuguese
343Lengshuijiang	China	Chinese
344Leninsk-Kuznetski	Russian Federation	Russian
345Leverkusen	Germany	German
346Lexington-Fayette	United States	English
347Liangcheng	China	Chinese
348Lianyungang	China	Chinese
349Little Rock	United States	English
350Liupanshui	China	Chinese
351Lleida (Lérida)	Spain	Spanish
352Lomas de Zamora	Argentina	Spanish
353Long Beach	United States	English
354Los Angeles	Chile	Spanish
355Los Angeles	United States	English
356Los Teques	Venezuela	Spanish
357Louisville	United States	English
358Lower Hutt	New Zealand	English
359Luchou	Taiwan	Min
360Ludwigshafen am Rhein	Germany	German
361Lungtan	Taiwan	Min
362L´Hospitalet de Llobregat	Spain	Spanish
363Lázaro Cárdenas	Mexico	Spanish
364SELECT Country.Name, Country.Population, City.Name, City.Population
365FROM Country LEFT JOIN City
366ON City.Country=Country.Code AND City.Population > 5000000
367WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000;
368Name	Population	Name	Population
369China	1277558000	Shanghai	9696300
370China	1277558000	Peking	7472000
371China	1277558000	Chongqing	6351600
372China	1277558000	Tianjin	5286800
373Colombia	42321000	Santafé de Bogotá	6260862
374Congo, The Democratic Republic of the	51654000	Kinshasa	5064000
375Chile	15211000	NULL	NULL
376Cambodia	11168000	NULL	NULL
377Cameroon	15085000	NULL	NULL
378Canada	31147000	NULL	NULL
379Cuba	11201000	NULL	NULL
380Côte d?Ivoire	14786000	NULL	NULL
381Czech Republic	10278100	NULL	NULL
382SELECT Country.Name, Country.Population, City.Name, City.Population
383FROM Country LEFT JOIN City
384ON City.Country=Country.Code AND
385(City.Population > 5000000 OR City.Name LIKE 'Za%')
386WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000;
387Name	Population	Name	Population
388China	1277558000	Shanghai	9696300
389China	1277558000	Peking	7472000
390China	1277558000	Chongqing	6351600
391China	1277558000	Tianjin	5286800
392China	1277558000	Zaozhuang	380846
393China	1277558000	Zaoyang	162198
394China	1277558000	Zalantun	130031
395Colombia	42321000	Santafé de Bogotá	6260862
396Congo, The Democratic Republic of the	51654000	Kinshasa	5064000
397Chile	15211000	NULL	NULL
398Cambodia	11168000	NULL	NULL
399Cameroon	15085000	NULL	NULL
400Canada	31147000	NULL	NULL
401Cuba	11201000	NULL	NULL
402Côte d?Ivoire	14786000	NULL	NULL
403Czech Republic	10278100	NULL	NULL
404CREATE INDEX City_Population ON City(Population);
405CREATE INDEX City_Name ON City(Name);
406ANALYZE TABLE City;
407EXPLAIN
408SELECT Country.Name, Country.Population, City.Name, City.Population
409FROM Country LEFT JOIN City
410ON City.Country=Country.Code AND City.Population > 5000000
411WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000;
412id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
4131	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
4141	SIMPLE	City	hash_range	City_Population	#hash#$hj:City_Population	3:4	world.Country.Code	24	Using where; Rowid-ordered scan; Using join buffer (flat, BNLH join)
415SELECT Country.Name, Country.Population, City.Name, City.Population
416FROM Country LEFT JOIN City
417ON City.Country=Country.Code AND City.Population > 5000000
418WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000;
419Name	Population	Name	Population
420China	1277558000	Shanghai	9696300
421China	1277558000	Peking	7472000
422China	1277558000	Chongqing	6351600
423China	1277558000	Tianjin	5286800
424Colombia	42321000	Santafé de Bogotá	6260862
425Congo, The Democratic Republic of the	51654000	Kinshasa	5064000
426Chile	15211000	NULL	NULL
427Cambodia	11168000	NULL	NULL
428Cameroon	15085000	NULL	NULL
429Canada	31147000	NULL	NULL
430Cuba	11201000	NULL	NULL
431Côte d?Ivoire	14786000	NULL	NULL
432Czech Republic	10278100	NULL	NULL
433EXPLAIN
434SELECT Country.Name, Country.Population, City.Name, City.Population
435FROM Country LEFT JOIN City
436ON City.Country=Country.Code AND
437(City.Population > 5000000 OR City.Name LIKE 'Za%')
438WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000;
439id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
4401	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
4411	SIMPLE	City	hash_index_merge	City_Population,City_Name	#hash#$hj:City_Population,City_Name	3:4,35	world.Country.Code	96	Using sort_union(City_Population,City_Name); Using where; Using join buffer (flat, BNLH join)
442SELECT Country.Name, Country.Population, City.Name, City.Population
443FROM Country LEFT JOIN City
444ON City.Country=Country.Code AND
445(City.Population > 5000000 OR City.Name LIKE 'Za%')
446WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000;
447Name	Population	Name	Population
448China	1277558000	Shanghai	9696300
449China	1277558000	Peking	7472000
450China	1277558000	Chongqing	6351600
451China	1277558000	Tianjin	5286800
452China	1277558000	Zaozhuang	380846
453China	1277558000	Zaoyang	162198
454China	1277558000	Zalantun	130031
455Colombia	42321000	Santafé de Bogotá	6260862
456Congo, The Democratic Republic of the	51654000	Kinshasa	5064000
457Chile	15211000	NULL	NULL
458Cambodia	11168000	NULL	NULL
459Cameroon	15085000	NULL	NULL
460Canada	31147000	NULL	NULL
461Cuba	11201000	NULL	NULL
462Côte d?Ivoire	14786000	NULL	NULL
463Czech Republic	10278100	NULL	NULL
464DROP INDEX City_Population ON City;
465DROP INDEX City_Name ON City;
466set join_cache_level=1;
467set join_buffer_size=256;
468show variables like 'join_buffer_size';
469Variable_name	Value
470join_buffer_size	256
471show variables like 'join_cache_level';
472Variable_name	Value
473join_cache_level	1
474EXPLAIN
475SELECT City.Name, Country.Name FROM City,Country
476WHERE City.Country=Country.Code AND
477Country.Name LIKE 'L%' AND City.Population > 100000;
478id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
4791	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
4801	SIMPLE	City	ALL	NULL	NULL	NULL	NULL	4079	Using where; Using join buffer (flat, BNL join)
481SELECT City.Name, Country.Name FROM City,Country
482WHERE City.Country=Country.Code AND
483Country.Name LIKE 'L%' AND City.Population > 100000;
484Name	Name
485?iauliai	Lithuania
486Beirut	Lebanon
487Bengasi	Libyan Arab Jamahiriya
488Daugavpils	Latvia
489Kaunas	Lithuania
490Klaipeda	Lithuania
491Maseru	Lesotho
492Misrata	Libyan Arab Jamahiriya
493Monrovia	Liberia
494Panevezys	Lithuania
495Riga	Latvia
496Tripoli	Lebanon
497Tripoli	Libyan Arab Jamahiriya
498Vientiane	Laos
499Vilnius	Lithuania
500EXPLAIN
501SELECT City.Name, Country.Name, CountryLanguage.Language
502FROM City,Country,CountryLanguage
503WHERE City.Country=Country.Code AND
504CountryLanguage.Country=Country.Code AND
505City.Name LIKE 'L%' AND Country.Population > 3000000 AND
506CountryLanguage.Percentage > 50 AND
507LENGTH(Language) < LENGTH(City.Name) - 2;
508id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
5091	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
5101	SIMPLE	CountryLanguage	ALL	NULL	NULL	NULL	NULL	984	Using where; Using join buffer (flat, BNL join)
5111	SIMPLE	City	ALL	NULL	NULL	NULL	NULL	4079	Using where; Using join buffer (flat, BNL join)
512SELECT City.Name, Country.Name, CountryLanguage.Language
513FROM City,Country,CountryLanguage
514WHERE City.Country=Country.Code AND
515CountryLanguage.Country=Country.Code AND
516City.Name LIKE 'L%' AND Country.Population > 3000000 AND
517CountryLanguage.Percentage > 50 AND
518LENGTH(Language) < LENGTH(City.Name) - 2;
519Name	Name	Language
520La Matanza	Argentina	Spanish
521Lagos de Moreno	Mexico	Spanish
522Lalitapur	Nepal	Nepali
523Las Margaritas	Mexico	Spanish
524Las Palmas de Gran Canaria	Spain	Spanish
525Lashio (Lasho)	Myanmar	Burmese
526Lauro de Freitas	Brazil	Portuguese
527Lengshuijiang	China	Chinese
528Leninsk-Kuznetski	Russian Federation	Russian
529Leverkusen	Germany	German
530Lexington-Fayette	United States	English
531Liangcheng	China	Chinese
532Lianyungang	China	Chinese
533Little Rock	United States	English
534Liupanshui	China	Chinese
535Lleida (Lérida)	Spain	Spanish
536Lomas de Zamora	Argentina	Spanish
537Long Beach	United States	English
538Los Angeles	Chile	Spanish
539Los Angeles	United States	English
540Los Teques	Venezuela	Spanish
541Louisville	United States	English
542Lower Hutt	New Zealand	English
543Luchou	Taiwan	Min
544Ludwigshafen am Rhein	Germany	German
545Lungtan	Taiwan	Min
546L´Hospitalet de Llobregat	Spain	Spanish
547Lázaro Cárdenas	Mexico	Spanish
548set join_cache_level=2;
549show variables like 'join_cache_level';
550Variable_name	Value
551join_cache_level	2
552EXPLAIN
553SELECT City.Name, Country.Name FROM City,Country
554WHERE City.Country=Country.Code AND
555Country.Name LIKE 'L%' AND City.Population > 100000;
556id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
5571	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
5581	SIMPLE	City	ALL	NULL	NULL	NULL	NULL	4079	Using where; Using join buffer (flat, BNL join)
559SELECT City.Name, Country.Name FROM City,Country
560WHERE City.Country=Country.Code AND
561Country.Name LIKE 'L%' AND City.Population > 100000;
562Name	Name
563?iauliai	Lithuania
564Beirut	Lebanon
565Bengasi	Libyan Arab Jamahiriya
566Daugavpils	Latvia
567Kaunas	Lithuania
568Klaipeda	Lithuania
569Maseru	Lesotho
570Misrata	Libyan Arab Jamahiriya
571Monrovia	Liberia
572Panevezys	Lithuania
573Riga	Latvia
574Tripoli	Lebanon
575Tripoli	Libyan Arab Jamahiriya
576Vientiane	Laos
577Vilnius	Lithuania
578EXPLAIN
579SELECT City.Name, Country.Name, CountryLanguage.Language
580FROM City,Country,CountryLanguage
581WHERE City.Country=Country.Code AND
582CountryLanguage.Country=Country.Code AND
583City.Name LIKE 'L%' AND Country.Population > 3000000 AND
584CountryLanguage.Percentage > 50 AND
585LENGTH(Language) < LENGTH(City.Name) - 2;
586id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
5871	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
5881	SIMPLE	CountryLanguage	ALL	NULL	NULL	NULL	NULL	984	Using where; Using join buffer (flat, BNL join)
5891	SIMPLE	City	ALL	NULL	NULL	NULL	NULL	4079	Using where; Using join buffer (incremental, BNL join)
590SELECT City.Name, Country.Name, CountryLanguage.Language
591FROM City,Country,CountryLanguage
592WHERE City.Country=Country.Code AND
593CountryLanguage.Country=Country.Code AND
594City.Name LIKE 'L%' AND Country.Population > 3000000 AND
595CountryLanguage.Percentage > 50 AND
596LENGTH(Language) < LENGTH(City.Name) - 2;
597Name	Name	Language
598La Matanza	Argentina	Spanish
599Lagos de Moreno	Mexico	Spanish
600Lalitapur	Nepal	Nepali
601Las Margaritas	Mexico	Spanish
602Las Palmas de Gran Canaria	Spain	Spanish
603Lashio (Lasho)	Myanmar	Burmese
604Lauro de Freitas	Brazil	Portuguese
605Lengshuijiang	China	Chinese
606Leninsk-Kuznetski	Russian Federation	Russian
607Leverkusen	Germany	German
608Lexington-Fayette	United States	English
609Liangcheng	China	Chinese
610Lianyungang	China	Chinese
611Little Rock	United States	English
612Liupanshui	China	Chinese
613Lleida (Lérida)	Spain	Spanish
614Lomas de Zamora	Argentina	Spanish
615Long Beach	United States	English
616Los Angeles	Chile	Spanish
617Los Angeles	United States	English
618Los Teques	Venezuela	Spanish
619Louisville	United States	English
620Lower Hutt	New Zealand	English
621Luchou	Taiwan	Min
622Ludwigshafen am Rhein	Germany	German
623Lungtan	Taiwan	Min
624L´Hospitalet de Llobregat	Spain	Spanish
625Lázaro Cárdenas	Mexico	Spanish
626set join_cache_level=3;
627show variables like 'join_cache_level';
628Variable_name	Value
629join_cache_level	3
630EXPLAIN
631SELECT City.Name, Country.Name FROM City,Country
632WHERE City.Country=Country.Code AND
633Country.Name LIKE 'L%' AND City.Population > 100000;
634id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
6351	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
6361	SIMPLE	City	hash_ALL	NULL	#hash#$hj	3	world.Country.Code	4079	Using where; Using join buffer (flat, BNLH join)
637SELECT City.Name, Country.Name FROM City,Country
638WHERE City.Country=Country.Code AND
639Country.Name LIKE 'L%' AND City.Population > 100000;
640Name	Name
641?iauliai	Lithuania
642Beirut	Lebanon
643Bengasi	Libyan Arab Jamahiriya
644Daugavpils	Latvia
645Kaunas	Lithuania
646Klaipeda	Lithuania
647Maseru	Lesotho
648Misrata	Libyan Arab Jamahiriya
649Monrovia	Liberia
650Panevezys	Lithuania
651Riga	Latvia
652Tripoli	Lebanon
653Tripoli	Libyan Arab Jamahiriya
654Vientiane	Laos
655Vilnius	Lithuania
656EXPLAIN
657SELECT City.Name, Country.Name, CountryLanguage.Language
658FROM City,Country,CountryLanguage
659WHERE City.Country=Country.Code AND
660CountryLanguage.Country=Country.Code AND
661City.Name LIKE 'L%' AND Country.Population > 3000000 AND
662CountryLanguage.Percentage > 50 AND
663LENGTH(Language) < LENGTH(City.Name) - 2;
664id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
6651	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
6661	SIMPLE	CountryLanguage	hash_ALL	NULL	#hash#$hj	3	world.Country.Code	984	Using where; Using join buffer (flat, BNLH join)
6671	SIMPLE	City	hash_ALL	NULL	#hash#$hj	3	world.Country.Code	4079	Using where; Using join buffer (flat, BNLH join)
668SELECT City.Name, Country.Name, CountryLanguage.Language
669FROM City,Country,CountryLanguage
670WHERE City.Country=Country.Code AND
671CountryLanguage.Country=Country.Code AND
672City.Name LIKE 'L%' AND Country.Population > 3000000 AND
673CountryLanguage.Percentage > 50 AND
674LENGTH(Language) < LENGTH(City.Name) - 2;
675Name	Name	Language
676La Matanza	Argentina	Spanish
677Lagos de Moreno	Mexico	Spanish
678Lalitapur	Nepal	Nepali
679Las Margaritas	Mexico	Spanish
680Las Palmas de Gran Canaria	Spain	Spanish
681Lashio (Lasho)	Myanmar	Burmese
682Lauro de Freitas	Brazil	Portuguese
683Lengshuijiang	China	Chinese
684Leninsk-Kuznetski	Russian Federation	Russian
685Leverkusen	Germany	German
686Lexington-Fayette	United States	English
687Liangcheng	China	Chinese
688Lianyungang	China	Chinese
689Little Rock	United States	English
690Liupanshui	China	Chinese
691Lleida (Lérida)	Spain	Spanish
692Lomas de Zamora	Argentina	Spanish
693Long Beach	United States	English
694Los Angeles	Chile	Spanish
695Los Angeles	United States	English
696Los Teques	Venezuela	Spanish
697Louisville	United States	English
698Lower Hutt	New Zealand	English
699Luchou	Taiwan	Min
700Ludwigshafen am Rhein	Germany	German
701Lungtan	Taiwan	Min
702L´Hospitalet de Llobregat	Spain	Spanish
703Lázaro Cárdenas	Mexico	Spanish
704set join_cache_level=4;
705show variables like 'join_cache_level';
706Variable_name	Value
707join_cache_level	4
708EXPLAIN
709SELECT City.Name, Country.Name FROM City,Country
710WHERE City.Country=Country.Code AND
711Country.Name LIKE 'L%' AND City.Population > 100000;
712id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
7131	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
7141	SIMPLE	City	hash_ALL	NULL	#hash#$hj	3	world.Country.Code	4079	Using where; Using join buffer (flat, BNLH join)
715SELECT City.Name, Country.Name FROM City,Country
716WHERE City.Country=Country.Code AND
717Country.Name LIKE 'L%' AND City.Population > 100000;
718Name	Name
719?iauliai	Lithuania
720Beirut	Lebanon
721Bengasi	Libyan Arab Jamahiriya
722Daugavpils	Latvia
723Kaunas	Lithuania
724Klaipeda	Lithuania
725Maseru	Lesotho
726Misrata	Libyan Arab Jamahiriya
727Monrovia	Liberia
728Panevezys	Lithuania
729Riga	Latvia
730Tripoli	Lebanon
731Tripoli	Libyan Arab Jamahiriya
732Vientiane	Laos
733Vilnius	Lithuania
734EXPLAIN
735SELECT City.Name, Country.Name, CountryLanguage.Language
736FROM City,Country,CountryLanguage
737WHERE City.Country=Country.Code AND
738CountryLanguage.Country=Country.Code AND
739City.Name LIKE 'L%' AND Country.Population > 3000000 AND
740CountryLanguage.Percentage > 50 AND
741LENGTH(Language) < LENGTH(City.Name) - 2;
742id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
7431	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
7441	SIMPLE	CountryLanguage	hash_ALL	NULL	#hash#$hj	3	world.Country.Code	984	Using where; Using join buffer (flat, BNLH join)
7451	SIMPLE	City	hash_ALL	NULL	#hash#$hj	3	world.Country.Code	4079	Using where; Using join buffer (incremental, BNLH join)
746SELECT City.Name, Country.Name, CountryLanguage.Language
747FROM City,Country,CountryLanguage
748WHERE City.Country=Country.Code AND
749CountryLanguage.Country=Country.Code AND
750City.Name LIKE 'L%' AND Country.Population > 3000000 AND
751CountryLanguage.Percentage > 50 AND
752LENGTH(Language) < LENGTH(City.Name) - 2;
753Name	Name	Language
754La Matanza	Argentina	Spanish
755Lagos de Moreno	Mexico	Spanish
756Lalitapur	Nepal	Nepali
757Las Margaritas	Mexico	Spanish
758Las Palmas de Gran Canaria	Spain	Spanish
759Lashio (Lasho)	Myanmar	Burmese
760Lauro de Freitas	Brazil	Portuguese
761Lengshuijiang	China	Chinese
762Leninsk-Kuznetski	Russian Federation	Russian
763Leverkusen	Germany	German
764Lexington-Fayette	United States	English
765Liangcheng	China	Chinese
766Lianyungang	China	Chinese
767Little Rock	United States	English
768Liupanshui	China	Chinese
769Lleida (Lérida)	Spain	Spanish
770Lomas de Zamora	Argentina	Spanish
771Long Beach	United States	English
772Los Angeles	Chile	Spanish
773Los Angeles	United States	English
774Los Teques	Venezuela	Spanish
775Louisville	United States	English
776Lower Hutt	New Zealand	English
777Luchou	Taiwan	Min
778Ludwigshafen am Rhein	Germany	German
779Lungtan	Taiwan	Min
780L´Hospitalet de Llobregat	Spain	Spanish
781Lázaro Cárdenas	Mexico	Spanish
782set join_cache_level=@save_join_cache_level;
783set join_buffer_size=@save_join_buffer_size;
784DROP DATABASE world;
785CREATE DATABASE world;
786use world;
787CREATE TABLE Country (
788Code char(3) NOT NULL default '',
789Name char(52) NOT NULL default '',
790SurfaceArea float(10,2) NOT NULL default '0.00',
791Population int(11) NOT NULL default '0',
792Capital int(11) default NULL,
793PRIMARY KEY  (Code),
794UNIQUE INDEX (Name)
795);
796CREATE TABLE City (
797ID int(11) NOT NULL auto_increment,
798Name char(35) NOT NULL default '',
799Country char(3) NOT NULL default '',
800Population int(11) NOT NULL default '0',
801PRIMARY KEY  (ID),
802INDEX (Population),
803INDEX (Country)
804);
805CREATE TABLE CountryLanguage (
806Country char(3) NOT NULL default '',
807Language char(30) NOT NULL default '',
808Percentage float(3,1) NOT NULL default '0.0',
809PRIMARY KEY  (Country, Language),
810INDEX (Percentage)
811);
812show variables like 'join_buffer_size';
813Variable_name	Value
814join_buffer_size	262144
815set join_cache_level=3;
816show variables like 'join_cache_level';
817Variable_name	Value
818join_cache_level	3
819EXPLAIN
820SELECT City.Name, Country.Name FROM City,Country
821WHERE City.Country=Country.Code AND
822Country.Name LIKE 'L%' AND City.Population > 100000;
823id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
8241	SIMPLE	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
8251	SIMPLE	City	hash_ALL	Population,Country	#hash#Country	3	world.Country.Code	4079	Using where; Using join buffer (flat, BNLH join)
826SELECT City.Name, Country.Name FROM City,Country
827WHERE City.Country=Country.Code AND
828Country.Name LIKE 'L%' AND City.Population > 100000;
829Name	Name
830?iauliai	Lithuania
831Beirut	Lebanon
832Bengasi	Libyan Arab Jamahiriya
833Daugavpils	Latvia
834Kaunas	Lithuania
835Klaipeda	Lithuania
836Maseru	Lesotho
837Misrata	Libyan Arab Jamahiriya
838Monrovia	Liberia
839Panevezys	Lithuania
840Riga	Latvia
841Tripoli	Lebanon
842Tripoli	Libyan Arab Jamahiriya
843Vientiane	Laos
844Vilnius	Lithuania
845EXPLAIN
846SELECT City.Name, Country.Name, CountryLanguage.Language
847FROM City,Country,CountryLanguage
848WHERE City.Country=Country.Code AND
849CountryLanguage.Country=Country.Code AND
850City.Name LIKE 'L%' AND Country.Population > 3000000 AND
851CountryLanguage.Percentage > 50 AND
852LENGTH(Language) < LENGTH(City.Name) - 2;
853id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
8541	SIMPLE	City	ALL	Country	NULL	NULL	NULL	4079	Using where
8551	SIMPLE	Country	hash_ALL	PRIMARY	#hash#PRIMARY	3	world.City.Country	239	Using where; Using join buffer (flat, BNLH join)
8561	SIMPLE	CountryLanguage	hash_ALL|filter	PRIMARY,Percentage	#hash#PRIMARY|Percentage	3|4	world.City.Country	984 (19%)	Using where; Using join buffer (flat, BNLH join); Using rowid filter
857SELECT City.Name, Country.Name, CountryLanguage.Language
858FROM City,Country,CountryLanguage
859WHERE City.Country=Country.Code AND
860CountryLanguage.Country=Country.Code AND
861City.Name LIKE 'L%' AND Country.Population > 3000000 AND
862CountryLanguage.Percentage > 50 AND
863LENGTH(Language) < LENGTH(City.Name) - 2;
864Name	Name	Language
865La Matanza	Argentina	Spanish
866Lagos de Moreno	Mexico	Spanish
867Lalitapur	Nepal	Nepali
868Las Margaritas	Mexico	Spanish
869Las Palmas de Gran Canaria	Spain	Spanish
870Lashio (Lasho)	Myanmar	Burmese
871Lauro de Freitas	Brazil	Portuguese
872Lengshuijiang	China	Chinese
873Leninsk-Kuznetski	Russian Federation	Russian
874Leverkusen	Germany	German
875Lexington-Fayette	United States	English
876Liangcheng	China	Chinese
877Lianyungang	China	Chinese
878Little Rock	United States	English
879Liupanshui	China	Chinese
880Lleida (Lérida)	Spain	Spanish
881Lomas de Zamora	Argentina	Spanish
882Long Beach	United States	English
883Los Angeles	Chile	Spanish
884Los Angeles	United States	English
885Los Teques	Venezuela	Spanish
886Louisville	United States	English
887Lower Hutt	New Zealand	English
888Luchou	Taiwan	Min
889Ludwigshafen am Rhein	Germany	German
890Lungtan	Taiwan	Min
891L´Hospitalet de Llobregat	Spain	Spanish
892Lázaro Cárdenas	Mexico	Spanish
893EXPLAIN
894SELECT Name FROM City
895WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
896City.Population > 100000;
897id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
8981	PRIMARY	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
8991	PRIMARY	City	hash_ALL	Population,Country	#hash#Country	3	world.Country.Code	4079	Using where; Using join buffer (flat, BNLH join)
900SELECT Name FROM City
901WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
902City.Population > 100000;
903Name
904Vientiane
905Riga
906Daugavpils
907Maseru
908Beirut
909Tripoli
910Monrovia
911Tripoli
912Bengasi
913Misrata
914Vilnius
915Kaunas
916Klaipeda
917?iauliai
918Panevezys
919EXPLAIN
920SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
921FROM Country LEFT JOIN CountryLanguage ON
922(CountryLanguage.Country=Country.Code AND Language='English')
923WHERE
924Country.Population > 10000000;
925id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
9261	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
9271	SIMPLE	CountryLanguage	hash_ALL	PRIMARY	#hash#PRIMARY	33	world.Country.Code,const	984	Using where; Using join buffer (flat, BNLH join)
928SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
929FROM Country LEFT JOIN CountryLanguage ON
930(CountryLanguage.Country=Country.Code AND Language='English')
931WHERE
932Country.Population > 10000000;
933Name	IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
934Australia	81.2
935United Kingdom	97.3
936Canada	60.4
937United States	86.2
938Zimbabwe	2.2
939Japan	0.1
940South Africa	8.5
941Malaysia	1.6
942Afghanistan	NULL
943Netherlands	NULL
944Algeria	NULL
945Angola	NULL
946Argentina	NULL
947Bangladesh	NULL
948Belgium	NULL
949Brazil	NULL
950Burkina Faso	NULL
951Chile	NULL
952Ecuador	NULL
953Egypt	NULL
954Spain	NULL
955Ethiopia	NULL
956Philippines	NULL
957Ghana	NULL
958Guatemala	NULL
959Indonesia	NULL
960India	NULL
961Iraq	NULL
962Iran	NULL
963Italy	NULL
964Yemen	NULL
965Yugoslavia	NULL
966Cambodia	NULL
967Cameroon	NULL
968Kazakstan	NULL
969Kenya	NULL
970China	NULL
971Colombia	NULL
972Congo, The Democratic Republic of the	NULL
973North Korea	NULL
974South Korea	NULL
975Greece	NULL
976Cuba	NULL
977Madagascar	NULL
978Malawi	NULL
979Mali	NULL
980Morocco	NULL
981Mexico	NULL
982Mozambique	NULL
983Myanmar	NULL
984Nepal	NULL
985Niger	NULL
986Nigeria	NULL
987Côte d?Ivoire	NULL
988Pakistan	NULL
989Peru	NULL
990Poland	NULL
991France	NULL
992Romania	NULL
993Germany	NULL
994Saudi Arabia	NULL
995Somalia	NULL
996Sri Lanka	NULL
997Sudan	NULL
998Syria	NULL
999Taiwan	NULL
1000Tanzania	NULL
1001Thailand	NULL
1002Czech Republic	NULL
1003Turkey	NULL
1004Uganda	NULL
1005Ukraine	NULL
1006Hungary	NULL
1007Uzbekistan	NULL
1008Belarus	NULL
1009Venezuela	NULL
1010Russian Federation	NULL
1011Vietnam	NULL
1012show variables like 'join_buffer_size';
1013Variable_name	Value
1014join_buffer_size	262144
1015set join_cache_level=4;
1016show variables like 'join_cache_level';
1017Variable_name	Value
1018join_cache_level	4
1019EXPLAIN
1020SELECT City.Name, Country.Name FROM City,Country
1021WHERE City.Country=Country.Code AND
1022Country.Name LIKE 'L%' AND City.Population > 100000;
1023id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
10241	SIMPLE	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
10251	SIMPLE	City	hash_ALL	Population,Country	#hash#Country	3	world.Country.Code	4079	Using where; Using join buffer (flat, BNLH join)
1026SELECT City.Name, Country.Name FROM City,Country
1027WHERE City.Country=Country.Code AND
1028Country.Name LIKE 'L%' AND City.Population > 100000;
1029Name	Name
1030?iauliai	Lithuania
1031Beirut	Lebanon
1032Bengasi	Libyan Arab Jamahiriya
1033Daugavpils	Latvia
1034Kaunas	Lithuania
1035Klaipeda	Lithuania
1036Maseru	Lesotho
1037Misrata	Libyan Arab Jamahiriya
1038Monrovia	Liberia
1039Panevezys	Lithuania
1040Riga	Latvia
1041Tripoli	Lebanon
1042Tripoli	Libyan Arab Jamahiriya
1043Vientiane	Laos
1044Vilnius	Lithuania
1045EXPLAIN
1046SELECT City.Name, Country.Name, CountryLanguage.Language
1047FROM City,Country,CountryLanguage
1048WHERE City.Country=Country.Code AND
1049CountryLanguage.Country=Country.Code AND
1050City.Name LIKE 'L%' AND Country.Population > 3000000 AND
1051CountryLanguage.Percentage > 50 AND
1052LENGTH(Language) < LENGTH(City.Name) - 2;
1053id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
10541	SIMPLE	City	ALL	Country	NULL	NULL	NULL	4079	Using where
10551	SIMPLE	Country	hash_ALL	PRIMARY	#hash#PRIMARY	3	world.City.Country	239	Using where; Using join buffer (flat, BNLH join)
10561	SIMPLE	CountryLanguage	hash_ALL|filter	PRIMARY,Percentage	#hash#PRIMARY|Percentage	3|4	world.City.Country	984 (19%)	Using where; Using join buffer (incremental, BNLH join); Using rowid filter
1057SELECT City.Name, Country.Name, CountryLanguage.Language
1058FROM City,Country,CountryLanguage
1059WHERE City.Country=Country.Code AND
1060CountryLanguage.Country=Country.Code AND
1061City.Name LIKE 'L%' AND Country.Population > 3000000 AND
1062CountryLanguage.Percentage > 50 AND
1063LENGTH(Language) < LENGTH(City.Name) - 2;
1064Name	Name	Language
1065La Matanza	Argentina	Spanish
1066Lagos de Moreno	Mexico	Spanish
1067Lalitapur	Nepal	Nepali
1068Las Margaritas	Mexico	Spanish
1069Las Palmas de Gran Canaria	Spain	Spanish
1070Lashio (Lasho)	Myanmar	Burmese
1071Lauro de Freitas	Brazil	Portuguese
1072Lengshuijiang	China	Chinese
1073Leninsk-Kuznetski	Russian Federation	Russian
1074Leverkusen	Germany	German
1075Lexington-Fayette	United States	English
1076Liangcheng	China	Chinese
1077Lianyungang	China	Chinese
1078Little Rock	United States	English
1079Liupanshui	China	Chinese
1080Lleida (Lérida)	Spain	Spanish
1081Lomas de Zamora	Argentina	Spanish
1082Long Beach	United States	English
1083Los Angeles	Chile	Spanish
1084Los Angeles	United States	English
1085Los Teques	Venezuela	Spanish
1086Louisville	United States	English
1087Lower Hutt	New Zealand	English
1088Luchou	Taiwan	Min
1089Ludwigshafen am Rhein	Germany	German
1090Lungtan	Taiwan	Min
1091L´Hospitalet de Llobregat	Spain	Spanish
1092Lázaro Cárdenas	Mexico	Spanish
1093EXPLAIN
1094SELECT Name FROM City
1095WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
1096City.Population > 100000;
1097id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
10981	PRIMARY	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
10991	PRIMARY	City	hash_ALL	Population,Country	#hash#Country	3	world.Country.Code	4079	Using where; Using join buffer (flat, BNLH join)
1100SELECT Name FROM City
1101WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
1102City.Population > 100000;
1103Name
1104Vientiane
1105Riga
1106Daugavpils
1107Maseru
1108Beirut
1109Tripoli
1110Monrovia
1111Tripoli
1112Bengasi
1113Misrata
1114Vilnius
1115Kaunas
1116Klaipeda
1117?iauliai
1118Panevezys
1119EXPLAIN
1120SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
1121FROM Country LEFT JOIN CountryLanguage ON
1122(CountryLanguage.Country=Country.Code AND Language='English')
1123WHERE
1124Country.Population > 10000000;
1125id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
11261	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
11271	SIMPLE	CountryLanguage	hash_ALL	PRIMARY	#hash#PRIMARY	33	world.Country.Code,const	984	Using where; Using join buffer (flat, BNLH join)
1128SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
1129FROM Country LEFT JOIN CountryLanguage ON
1130(CountryLanguage.Country=Country.Code AND Language='English')
1131WHERE
1132Country.Population > 10000000;
1133Name	IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
1134Australia	81.2
1135United Kingdom	97.3
1136Canada	60.4
1137United States	86.2
1138Zimbabwe	2.2
1139Japan	0.1
1140South Africa	8.5
1141Malaysia	1.6
1142Afghanistan	NULL
1143Netherlands	NULL
1144Algeria	NULL
1145Angola	NULL
1146Argentina	NULL
1147Bangladesh	NULL
1148Belgium	NULL
1149Brazil	NULL
1150Burkina Faso	NULL
1151Chile	NULL
1152Ecuador	NULL
1153Egypt	NULL
1154Spain	NULL
1155Ethiopia	NULL
1156Philippines	NULL
1157Ghana	NULL
1158Guatemala	NULL
1159Indonesia	NULL
1160India	NULL
1161Iraq	NULL
1162Iran	NULL
1163Italy	NULL
1164Yemen	NULL
1165Yugoslavia	NULL
1166Cambodia	NULL
1167Cameroon	NULL
1168Kazakstan	NULL
1169Kenya	NULL
1170China	NULL
1171Colombia	NULL
1172Congo, The Democratic Republic of the	NULL
1173North Korea	NULL
1174South Korea	NULL
1175Greece	NULL
1176Cuba	NULL
1177Madagascar	NULL
1178Malawi	NULL
1179Mali	NULL
1180Morocco	NULL
1181Mexico	NULL
1182Mozambique	NULL
1183Myanmar	NULL
1184Nepal	NULL
1185Niger	NULL
1186Nigeria	NULL
1187Côte d?Ivoire	NULL
1188Pakistan	NULL
1189Peru	NULL
1190Poland	NULL
1191France	NULL
1192Romania	NULL
1193Germany	NULL
1194Saudi Arabia	NULL
1195Somalia	NULL
1196Sri Lanka	NULL
1197Sudan	NULL
1198Syria	NULL
1199Taiwan	NULL
1200Tanzania	NULL
1201Thailand	NULL
1202Czech Republic	NULL
1203Turkey	NULL
1204Uganda	NULL
1205Ukraine	NULL
1206Hungary	NULL
1207Uzbekistan	NULL
1208Belarus	NULL
1209Venezuela	NULL
1210Russian Federation	NULL
1211Vietnam	NULL
1212EXPLAIN
1213SELECT Country.Name, Country.Population, City.Name, City.Population
1214FROM Country LEFT JOIN City
1215ON City.Country=Country.Code AND City.Population > 5000000
1216WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000;
1217id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
12181	SIMPLE	Country	range	Name	Name	52	NULL	#	Using index condition; Using where; Rowid-ordered scan
12191	SIMPLE	City	hash_range	Population,Country	#hash#Country:Population	3:4	world.Country.Code	#	Using where; Rowid-ordered scan; Using join buffer (flat, BNLH join)
1220SELECT Country.Name, Country.Population, City.Name, City.Population
1221FROM Country LEFT JOIN City
1222ON City.Country=Country.Code AND City.Population > 5000000
1223WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000;
1224Name	Population	Name	Population
1225China	1277558000	Shanghai	9696300
1226China	1277558000	Peking	7472000
1227China	1277558000	Chongqing	6351600
1228China	1277558000	Tianjin	5286800
1229Colombia	42321000	Santafé de Bogotá	6260862
1230Congo, The Democratic Republic of the	51654000	Kinshasa	5064000
1231Chile	15211000	NULL	NULL
1232Cambodia	11168000	NULL	NULL
1233Cameroon	15085000	NULL	NULL
1234Canada	31147000	NULL	NULL
1235Cuba	11201000	NULL	NULL
1236Côte d?Ivoire	14786000	NULL	NULL
1237Czech Republic	10278100	NULL	NULL
1238CREATE INDEX City_Name ON City(Name);
1239EXPLAIN
1240SELECT Country.Name, Country.Population, City.Name, City.Population
1241FROM Country LEFT JOIN City
1242ON City.Country=Country.Code AND
1243(City.Population > 5000000 OR City.Name LIKE 'Za%')
1244WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000;
1245id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
12461	SIMPLE	Country	range	Name	Name	52	NULL	17	Using index condition; Using where; Rowid-ordered scan
12471	SIMPLE	City	hash_index_merge	Population,Country,City_Name	#hash#Country:Population,City_Name	3:4,35	world.Country.Code	96	Using sort_union(Population,City_Name); Using where; Using join buffer (flat, BNLH join)
1248SELECT Country.Name, Country.Population, City.Name, City.Population
1249FROM Country LEFT JOIN City
1250ON City.Country=Country.Code AND
1251(City.Population > 5000000 OR City.Name LIKE 'Za%')
1252WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000;
1253Name	Population	Name	Population
1254China	1277558000	Shanghai	9696300
1255China	1277558000	Peking	7472000
1256China	1277558000	Chongqing	6351600
1257China	1277558000	Tianjin	5286800
1258China	1277558000	Zaozhuang	380846
1259China	1277558000	Zaoyang	162198
1260China	1277558000	Zalantun	130031
1261Colombia	42321000	Santafé de Bogotá	6260862
1262Congo, The Democratic Republic of the	51654000	Kinshasa	5064000
1263Chile	15211000	NULL	NULL
1264Cambodia	11168000	NULL	NULL
1265Cameroon	15085000	NULL	NULL
1266Canada	31147000	NULL	NULL
1267Cuba	11201000	NULL	NULL
1268Côte d?Ivoire	14786000	NULL	NULL
1269Czech Republic	10278100	NULL	NULL
1270DROP INDEX City_Name ON City;
1271show variables like 'join_buffer_size';
1272Variable_name	Value
1273join_buffer_size	262144
1274set join_cache_level=5;
1275show variables like 'join_cache_level';
1276Variable_name	Value
1277join_cache_level	5
1278EXPLAIN
1279SELECT City.Name, Country.Name FROM City,Country
1280WHERE City.Country=Country.Code AND
1281Country.Name LIKE 'L%' AND City.Population > 100000;
1282id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
12831	SIMPLE	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
12841	SIMPLE	City	ref	Population,Country	Country	3	world.Country.Code	17	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
1285SELECT City.Name, Country.Name FROM City,Country
1286WHERE City.Country=Country.Code AND
1287Country.Name LIKE 'L%' AND City.Population > 100000;
1288Name	Name
1289?iauliai	Lithuania
1290Beirut	Lebanon
1291Bengasi	Libyan Arab Jamahiriya
1292Daugavpils	Latvia
1293Kaunas	Lithuania
1294Klaipeda	Lithuania
1295Maseru	Lesotho
1296Misrata	Libyan Arab Jamahiriya
1297Monrovia	Liberia
1298Panevezys	Lithuania
1299Riga	Latvia
1300Tripoli	Lebanon
1301Tripoli	Libyan Arab Jamahiriya
1302Vientiane	Laos
1303Vilnius	Lithuania
1304EXPLAIN
1305SELECT City.Name, Country.Name, CountryLanguage.Language
1306FROM City,Country,CountryLanguage
1307WHERE City.Country=Country.Code AND
1308CountryLanguage.Country=Country.Code AND
1309City.Name LIKE 'L%' AND Country.Population > 3000000 AND
1310CountryLanguage.Percentage > 50 AND
1311LENGTH(Language) < LENGTH(City.Name) - 2;
1312id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
13131	SIMPLE	City	ALL	Country	NULL	NULL	NULL	4079	Using where
13141	SIMPLE	Country	eq_ref	PRIMARY	PRIMARY	3	world.City.Country	1	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
13151	SIMPLE	CountryLanguage	ref|filter	PRIMARY,Percentage	PRIMARY|Percentage	3|4	world.City.Country	4 (19%)	Using index condition(BKA); Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter
1316SELECT City.Name, Country.Name, CountryLanguage.Language
1317FROM City,Country,CountryLanguage
1318WHERE City.Country=Country.Code AND
1319CountryLanguage.Country=Country.Code AND
1320City.Name LIKE 'L%' AND Country.Population > 3000000 AND
1321CountryLanguage.Percentage > 50 AND
1322LENGTH(Language) < LENGTH(City.Name) - 2;
1323Name	Name	Language
1324La Matanza	Argentina	Spanish
1325Lagos de Moreno	Mexico	Spanish
1326Lalitapur	Nepal	Nepali
1327Las Margaritas	Mexico	Spanish
1328Las Palmas de Gran Canaria	Spain	Spanish
1329Lashio (Lasho)	Myanmar	Burmese
1330Lauro de Freitas	Brazil	Portuguese
1331Lengshuijiang	China	Chinese
1332Leninsk-Kuznetski	Russian Federation	Russian
1333Leverkusen	Germany	German
1334Lexington-Fayette	United States	English
1335Liangcheng	China	Chinese
1336Lianyungang	China	Chinese
1337Little Rock	United States	English
1338Liupanshui	China	Chinese
1339Lleida (Lérida)	Spain	Spanish
1340Lomas de Zamora	Argentina	Spanish
1341Long Beach	United States	English
1342Los Angeles	Chile	Spanish
1343Los Angeles	United States	English
1344Los Teques	Venezuela	Spanish
1345Louisville	United States	English
1346Lower Hutt	New Zealand	English
1347Luchou	Taiwan	Min
1348Ludwigshafen am Rhein	Germany	German
1349Lungtan	Taiwan	Min
1350L´Hospitalet de Llobregat	Spain	Spanish
1351Lázaro Cárdenas	Mexico	Spanish
1352EXPLAIN
1353SELECT Name FROM City
1354WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
1355City.Population > 100000;
1356id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
13571	PRIMARY	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
13581	PRIMARY	City	ref	Population,Country	Country	3	world.Country.Code	17	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
1359SELECT Name FROM City
1360WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
1361City.Population > 100000;
1362Name
1363Vientiane
1364Riga
1365Daugavpils
1366Maseru
1367Beirut
1368Tripoli
1369Monrovia
1370Tripoli
1371Bengasi
1372Misrata
1373Vilnius
1374Kaunas
1375Klaipeda
1376?iauliai
1377Panevezys
1378EXPLAIN
1379SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
1380FROM Country LEFT JOIN CountryLanguage ON
1381(CountryLanguage.Country=Country.Code AND Language='English')
1382WHERE
1383Country.Population > 10000000;
1384id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
13851	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
13861	SIMPLE	CountryLanguage	eq_ref	PRIMARY	PRIMARY	33	world.Country.Code,const	1	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
1387SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
1388FROM Country LEFT JOIN CountryLanguage ON
1389(CountryLanguage.Country=Country.Code AND Language='English')
1390WHERE
1391Country.Population > 10000000;
1392Name	IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
1393Australia	81.2
1394United Kingdom	97.3
1395Canada	60.4
1396United States	86.2
1397Zimbabwe	2.2
1398Japan	0.1
1399South Africa	8.5
1400Malaysia	1.6
1401Afghanistan	NULL
1402Netherlands	NULL
1403Algeria	NULL
1404Angola	NULL
1405Argentina	NULL
1406Bangladesh	NULL
1407Belgium	NULL
1408Brazil	NULL
1409Burkina Faso	NULL
1410Chile	NULL
1411Ecuador	NULL
1412Egypt	NULL
1413Spain	NULL
1414Ethiopia	NULL
1415Philippines	NULL
1416Ghana	NULL
1417Guatemala	NULL
1418Indonesia	NULL
1419India	NULL
1420Iraq	NULL
1421Iran	NULL
1422Italy	NULL
1423Yemen	NULL
1424Yugoslavia	NULL
1425Cambodia	NULL
1426Cameroon	NULL
1427Kazakstan	NULL
1428Kenya	NULL
1429China	NULL
1430Colombia	NULL
1431Congo, The Democratic Republic of the	NULL
1432North Korea	NULL
1433South Korea	NULL
1434Greece	NULL
1435Cuba	NULL
1436Madagascar	NULL
1437Malawi	NULL
1438Mali	NULL
1439Morocco	NULL
1440Mexico	NULL
1441Mozambique	NULL
1442Myanmar	NULL
1443Nepal	NULL
1444Niger	NULL
1445Nigeria	NULL
1446Côte d?Ivoire	NULL
1447Pakistan	NULL
1448Peru	NULL
1449Poland	NULL
1450France	NULL
1451Romania	NULL
1452Germany	NULL
1453Saudi Arabia	NULL
1454Somalia	NULL
1455Sri Lanka	NULL
1456Sudan	NULL
1457Syria	NULL
1458Taiwan	NULL
1459Tanzania	NULL
1460Thailand	NULL
1461Czech Republic	NULL
1462Turkey	NULL
1463Uganda	NULL
1464Ukraine	NULL
1465Hungary	NULL
1466Uzbekistan	NULL
1467Belarus	NULL
1468Venezuela	NULL
1469Russian Federation	NULL
1470Vietnam	NULL
1471set join_cache_level=6;
1472show variables like 'join_cache_level';
1473Variable_name	Value
1474join_cache_level	6
1475EXPLAIN
1476SELECT City.Name, Country.Name FROM City,Country
1477WHERE City.Country=Country.Code AND
1478Country.Name LIKE 'L%' AND City.Population > 100000;
1479id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
14801	SIMPLE	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
14811	SIMPLE	City	ref	Population,Country	Country	3	world.Country.Code	17	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
1482SELECT City.Name, Country.Name FROM City,Country
1483WHERE City.Country=Country.Code AND
1484Country.Name LIKE 'L%' AND City.Population > 100000;
1485Name	Name
1486?iauliai	Lithuania
1487Beirut	Lebanon
1488Bengasi	Libyan Arab Jamahiriya
1489Daugavpils	Latvia
1490Kaunas	Lithuania
1491Klaipeda	Lithuania
1492Maseru	Lesotho
1493Misrata	Libyan Arab Jamahiriya
1494Monrovia	Liberia
1495Panevezys	Lithuania
1496Riga	Latvia
1497Tripoli	Lebanon
1498Tripoli	Libyan Arab Jamahiriya
1499Vientiane	Laos
1500Vilnius	Lithuania
1501EXPLAIN
1502SELECT City.Name, Country.Name, CountryLanguage.Language
1503FROM City,Country,CountryLanguage
1504WHERE City.Country=Country.Code AND
1505CountryLanguage.Country=Country.Code AND
1506City.Name LIKE 'L%' AND Country.Population > 3000000 AND
1507CountryLanguage.Percentage > 50 AND
1508LENGTH(Language) < LENGTH(City.Name) - 2;
1509id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
15101	SIMPLE	City	ALL	Country	NULL	NULL	NULL	4079	Using where
15111	SIMPLE	Country	eq_ref	PRIMARY	PRIMARY	3	world.City.Country	1	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
15121	SIMPLE	CountryLanguage	ref|filter	PRIMARY,Percentage	PRIMARY|Percentage	3|4	world.City.Country	4 (19%)	Using index condition(BKA); Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter
1513SELECT City.Name, Country.Name, CountryLanguage.Language
1514FROM City,Country,CountryLanguage
1515WHERE City.Country=Country.Code AND
1516CountryLanguage.Country=Country.Code AND
1517City.Name LIKE 'L%' AND Country.Population > 3000000 AND
1518CountryLanguage.Percentage > 50 AND
1519LENGTH(Language) < LENGTH(City.Name) - 2;
1520Name	Name	Language
1521La Matanza	Argentina	Spanish
1522Lagos de Moreno	Mexico	Spanish
1523Lalitapur	Nepal	Nepali
1524Las Margaritas	Mexico	Spanish
1525Las Palmas de Gran Canaria	Spain	Spanish
1526Lashio (Lasho)	Myanmar	Burmese
1527Lauro de Freitas	Brazil	Portuguese
1528Lengshuijiang	China	Chinese
1529Leninsk-Kuznetski	Russian Federation	Russian
1530Leverkusen	Germany	German
1531Lexington-Fayette	United States	English
1532Liangcheng	China	Chinese
1533Lianyungang	China	Chinese
1534Little Rock	United States	English
1535Liupanshui	China	Chinese
1536Lleida (Lérida)	Spain	Spanish
1537Lomas de Zamora	Argentina	Spanish
1538Long Beach	United States	English
1539Los Angeles	Chile	Spanish
1540Los Angeles	United States	English
1541Los Teques	Venezuela	Spanish
1542Louisville	United States	English
1543Lower Hutt	New Zealand	English
1544Luchou	Taiwan	Min
1545Ludwigshafen am Rhein	Germany	German
1546Lungtan	Taiwan	Min
1547L´Hospitalet de Llobregat	Spain	Spanish
1548Lázaro Cárdenas	Mexico	Spanish
1549EXPLAIN
1550SELECT Name FROM City
1551WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
1552City.Population > 100000;
1553id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
15541	PRIMARY	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
15551	PRIMARY	City	ref	Population,Country	Country	3	world.Country.Code	17	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
1556SELECT Name FROM City
1557WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
1558City.Population > 100000;
1559Name
1560Vientiane
1561Riga
1562Daugavpils
1563Maseru
1564Beirut
1565Tripoli
1566Monrovia
1567Tripoli
1568Bengasi
1569Misrata
1570Vilnius
1571Kaunas
1572Klaipeda
1573?iauliai
1574Panevezys
1575EXPLAIN
1576SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
1577FROM Country LEFT JOIN CountryLanguage ON
1578(CountryLanguage.Country=Country.Code AND Language='English')
1579WHERE
1580Country.Population > 10000000;
1581id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
15821	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
15831	SIMPLE	CountryLanguage	eq_ref	PRIMARY	PRIMARY	33	world.Country.Code,const	1	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
1584SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
1585FROM Country LEFT JOIN CountryLanguage ON
1586(CountryLanguage.Country=Country.Code AND Language='English')
1587WHERE
1588Country.Population > 10000000;
1589Name	IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
1590Australia	81.2
1591United Kingdom	97.3
1592Canada	60.4
1593United States	86.2
1594Zimbabwe	2.2
1595Japan	0.1
1596South Africa	8.5
1597Malaysia	1.6
1598Afghanistan	NULL
1599Netherlands	NULL
1600Algeria	NULL
1601Angola	NULL
1602Argentina	NULL
1603Bangladesh	NULL
1604Belgium	NULL
1605Brazil	NULL
1606Burkina Faso	NULL
1607Chile	NULL
1608Ecuador	NULL
1609Egypt	NULL
1610Spain	NULL
1611Ethiopia	NULL
1612Philippines	NULL
1613Ghana	NULL
1614Guatemala	NULL
1615Indonesia	NULL
1616India	NULL
1617Iraq	NULL
1618Iran	NULL
1619Italy	NULL
1620Yemen	NULL
1621Yugoslavia	NULL
1622Cambodia	NULL
1623Cameroon	NULL
1624Kazakstan	NULL
1625Kenya	NULL
1626China	NULL
1627Colombia	NULL
1628Congo, The Democratic Republic of the	NULL
1629North Korea	NULL
1630South Korea	NULL
1631Greece	NULL
1632Cuba	NULL
1633Madagascar	NULL
1634Malawi	NULL
1635Mali	NULL
1636Morocco	NULL
1637Mexico	NULL
1638Mozambique	NULL
1639Myanmar	NULL
1640Nepal	NULL
1641Niger	NULL
1642Nigeria	NULL
1643Côte d?Ivoire	NULL
1644Pakistan	NULL
1645Peru	NULL
1646Poland	NULL
1647France	NULL
1648Romania	NULL
1649Germany	NULL
1650Saudi Arabia	NULL
1651Somalia	NULL
1652Sri Lanka	NULL
1653Sudan	NULL
1654Syria	NULL
1655Taiwan	NULL
1656Tanzania	NULL
1657Thailand	NULL
1658Czech Republic	NULL
1659Turkey	NULL
1660Uganda	NULL
1661Ukraine	NULL
1662Hungary	NULL
1663Uzbekistan	NULL
1664Belarus	NULL
1665Venezuela	NULL
1666Russian Federation	NULL
1667Vietnam	NULL
1668set join_cache_level=7;
1669show variables like 'join_cache_level';
1670Variable_name	Value
1671join_cache_level	7
1672EXPLAIN
1673SELECT City.Name, Country.Name FROM City,Country
1674WHERE City.Country=Country.Code AND
1675Country.Name LIKE 'L%' AND City.Population > 100000;
1676id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
16771	SIMPLE	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
16781	SIMPLE	City	ref	Population,Country	Country	3	world.Country.Code	17	Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
1679SELECT City.Name, Country.Name FROM City,Country
1680WHERE City.Country=Country.Code AND
1681Country.Name LIKE 'L%' AND City.Population > 100000;
1682Name	Name
1683?iauliai	Lithuania
1684Beirut	Lebanon
1685Bengasi	Libyan Arab Jamahiriya
1686Daugavpils	Latvia
1687Kaunas	Lithuania
1688Klaipeda	Lithuania
1689Maseru	Lesotho
1690Misrata	Libyan Arab Jamahiriya
1691Monrovia	Liberia
1692Panevezys	Lithuania
1693Riga	Latvia
1694Tripoli	Lebanon
1695Tripoli	Libyan Arab Jamahiriya
1696Vientiane	Laos
1697Vilnius	Lithuania
1698EXPLAIN
1699SELECT City.Name, Country.Name, CountryLanguage.Language
1700FROM City,Country,CountryLanguage
1701WHERE City.Country=Country.Code AND
1702CountryLanguage.Country=Country.Code AND
1703City.Name LIKE 'L%' AND Country.Population > 3000000 AND
1704CountryLanguage.Percentage > 50 AND
1705LENGTH(Language) < LENGTH(City.Name) - 2;
1706id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
17071	SIMPLE	City	ALL	Country	NULL	NULL	NULL	4079	Using where
17081	SIMPLE	Country	eq_ref	PRIMARY	PRIMARY	3	world.City.Country	1	Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
17091	SIMPLE	CountryLanguage	ref|filter	PRIMARY,Percentage	PRIMARY|Percentage	3|4	world.City.Country	4 (19%)	Using index condition(BKA); Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan; Using rowid filter
1710SELECT City.Name, Country.Name, CountryLanguage.Language
1711FROM City,Country,CountryLanguage
1712WHERE City.Country=Country.Code AND
1713CountryLanguage.Country=Country.Code AND
1714City.Name LIKE 'L%' AND Country.Population > 3000000 AND
1715CountryLanguage.Percentage > 50 AND
1716LENGTH(Language) < LENGTH(City.Name) - 2;
1717Name	Name	Language
1718La Matanza	Argentina	Spanish
1719Lagos de Moreno	Mexico	Spanish
1720Lalitapur	Nepal	Nepali
1721Las Margaritas	Mexico	Spanish
1722Las Palmas de Gran Canaria	Spain	Spanish
1723Lashio (Lasho)	Myanmar	Burmese
1724Lauro de Freitas	Brazil	Portuguese
1725Lengshuijiang	China	Chinese
1726Leninsk-Kuznetski	Russian Federation	Russian
1727Leverkusen	Germany	German
1728Lexington-Fayette	United States	English
1729Liangcheng	China	Chinese
1730Lianyungang	China	Chinese
1731Little Rock	United States	English
1732Liupanshui	China	Chinese
1733Lleida (Lérida)	Spain	Spanish
1734Lomas de Zamora	Argentina	Spanish
1735Long Beach	United States	English
1736Los Angeles	Chile	Spanish
1737Los Angeles	United States	English
1738Los Teques	Venezuela	Spanish
1739Louisville	United States	English
1740Lower Hutt	New Zealand	English
1741Luchou	Taiwan	Min
1742Ludwigshafen am Rhein	Germany	German
1743Lungtan	Taiwan	Min
1744L´Hospitalet de Llobregat	Spain	Spanish
1745Lázaro Cárdenas	Mexico	Spanish
1746EXPLAIN
1747SELECT Name FROM City
1748WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
1749City.Population > 100000;
1750id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
17511	PRIMARY	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
17521	PRIMARY	City	ref	Population,Country	Country	3	world.Country.Code	17	Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
1753SELECT Name FROM City
1754WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
1755City.Population > 100000;
1756Name
1757Vientiane
1758Riga
1759Daugavpils
1760Maseru
1761Beirut
1762Tripoli
1763Monrovia
1764Tripoli
1765Bengasi
1766Misrata
1767Vilnius
1768Kaunas
1769Klaipeda
1770?iauliai
1771Panevezys
1772EXPLAIN
1773SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
1774FROM Country LEFT JOIN CountryLanguage ON
1775(CountryLanguage.Country=Country.Code AND Language='English')
1776WHERE
1777Country.Population > 10000000;
1778id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
17791	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
17801	SIMPLE	CountryLanguage	eq_ref	PRIMARY	PRIMARY	33	world.Country.Code,const	1	Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
1781SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
1782FROM Country LEFT JOIN CountryLanguage ON
1783(CountryLanguage.Country=Country.Code AND Language='English')
1784WHERE
1785Country.Population > 10000000;
1786Name	IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
1787Australia	81.2
1788United Kingdom	97.3
1789Canada	60.4
1790United States	86.2
1791Zimbabwe	2.2
1792Japan	0.1
1793South Africa	8.5
1794Malaysia	1.6
1795Afghanistan	NULL
1796Netherlands	NULL
1797Algeria	NULL
1798Angola	NULL
1799Argentina	NULL
1800Bangladesh	NULL
1801Belgium	NULL
1802Brazil	NULL
1803Burkina Faso	NULL
1804Chile	NULL
1805Ecuador	NULL
1806Egypt	NULL
1807Spain	NULL
1808Ethiopia	NULL
1809Philippines	NULL
1810Ghana	NULL
1811Guatemala	NULL
1812Indonesia	NULL
1813India	NULL
1814Iraq	NULL
1815Iran	NULL
1816Italy	NULL
1817Yemen	NULL
1818Yugoslavia	NULL
1819Cambodia	NULL
1820Cameroon	NULL
1821Kazakstan	NULL
1822Kenya	NULL
1823China	NULL
1824Colombia	NULL
1825Congo, The Democratic Republic of the	NULL
1826North Korea	NULL
1827South Korea	NULL
1828Greece	NULL
1829Cuba	NULL
1830Madagascar	NULL
1831Malawi	NULL
1832Mali	NULL
1833Morocco	NULL
1834Mexico	NULL
1835Mozambique	NULL
1836Myanmar	NULL
1837Nepal	NULL
1838Niger	NULL
1839Nigeria	NULL
1840Côte d?Ivoire	NULL
1841Pakistan	NULL
1842Peru	NULL
1843Poland	NULL
1844France	NULL
1845Romania	NULL
1846Germany	NULL
1847Saudi Arabia	NULL
1848Somalia	NULL
1849Sri Lanka	NULL
1850Sudan	NULL
1851Syria	NULL
1852Taiwan	NULL
1853Tanzania	NULL
1854Thailand	NULL
1855Czech Republic	NULL
1856Turkey	NULL
1857Uganda	NULL
1858Ukraine	NULL
1859Hungary	NULL
1860Uzbekistan	NULL
1861Belarus	NULL
1862Venezuela	NULL
1863Russian Federation	NULL
1864Vietnam	NULL
1865set join_cache_level=8;
1866show variables like 'join_cache_level';
1867Variable_name	Value
1868join_cache_level	8
1869EXPLAIN
1870SELECT City.Name, Country.Name FROM City,Country
1871WHERE City.Country=Country.Code AND
1872Country.Name LIKE 'L%' AND City.Population > 100000;
1873id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
18741	SIMPLE	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
18751	SIMPLE	City	ref	Population,Country	Country	3	world.Country.Code	17	Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
1876SELECT City.Name, Country.Name FROM City,Country
1877WHERE City.Country=Country.Code AND
1878Country.Name LIKE 'L%' AND City.Population > 100000;
1879Name	Name
1880?iauliai	Lithuania
1881Beirut	Lebanon
1882Bengasi	Libyan Arab Jamahiriya
1883Daugavpils	Latvia
1884Kaunas	Lithuania
1885Klaipeda	Lithuania
1886Maseru	Lesotho
1887Misrata	Libyan Arab Jamahiriya
1888Monrovia	Liberia
1889Panevezys	Lithuania
1890Riga	Latvia
1891Tripoli	Lebanon
1892Tripoli	Libyan Arab Jamahiriya
1893Vientiane	Laos
1894Vilnius	Lithuania
1895EXPLAIN
1896SELECT City.Name, Country.Name, CountryLanguage.Language
1897FROM City,Country,CountryLanguage
1898WHERE City.Country=Country.Code AND
1899CountryLanguage.Country=Country.Code AND
1900City.Name LIKE 'L%' AND Country.Population > 3000000 AND
1901CountryLanguage.Percentage > 50 AND
1902LENGTH(Language) < LENGTH(City.Name) - 2;
1903id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
19041	SIMPLE	City	ALL	Country	NULL	NULL	NULL	4079	Using where
19051	SIMPLE	Country	eq_ref	PRIMARY	PRIMARY	3	world.City.Country	1	Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
19061	SIMPLE	CountryLanguage	ref|filter	PRIMARY,Percentage	PRIMARY|Percentage	3|4	world.City.Country	4 (19%)	Using index condition(BKA); Using where; Using join buffer (incremental, BKAH join); Key-ordered Rowid-ordered scan; Using rowid filter
1907SELECT City.Name, Country.Name, CountryLanguage.Language
1908FROM City,Country,CountryLanguage
1909WHERE City.Country=Country.Code AND
1910CountryLanguage.Country=Country.Code AND
1911City.Name LIKE 'L%' AND Country.Population > 3000000 AND
1912CountryLanguage.Percentage > 50 AND
1913LENGTH(Language) < LENGTH(City.Name) - 2;
1914Name	Name	Language
1915La Matanza	Argentina	Spanish
1916Lagos de Moreno	Mexico	Spanish
1917Lalitapur	Nepal	Nepali
1918Las Margaritas	Mexico	Spanish
1919Las Palmas de Gran Canaria	Spain	Spanish
1920Lashio (Lasho)	Myanmar	Burmese
1921Lauro de Freitas	Brazil	Portuguese
1922Lengshuijiang	China	Chinese
1923Leninsk-Kuznetski	Russian Federation	Russian
1924Leverkusen	Germany	German
1925Lexington-Fayette	United States	English
1926Liangcheng	China	Chinese
1927Lianyungang	China	Chinese
1928Little Rock	United States	English
1929Liupanshui	China	Chinese
1930Lleida (Lérida)	Spain	Spanish
1931Lomas de Zamora	Argentina	Spanish
1932Long Beach	United States	English
1933Los Angeles	Chile	Spanish
1934Los Angeles	United States	English
1935Los Teques	Venezuela	Spanish
1936Louisville	United States	English
1937Lower Hutt	New Zealand	English
1938Luchou	Taiwan	Min
1939Ludwigshafen am Rhein	Germany	German
1940Lungtan	Taiwan	Min
1941L´Hospitalet de Llobregat	Spain	Spanish
1942Lázaro Cárdenas	Mexico	Spanish
1943EXPLAIN
1944SELECT Name FROM City
1945WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
1946City.Population > 100000;
1947id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
19481	PRIMARY	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
19491	PRIMARY	City	ref	Population,Country	Country	3	world.Country.Code	17	Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
1950SELECT Name FROM City
1951WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
1952City.Population > 100000;
1953Name
1954Vientiane
1955Riga
1956Daugavpils
1957Maseru
1958Beirut
1959Tripoli
1960Monrovia
1961Tripoli
1962Bengasi
1963Misrata
1964Vilnius
1965Kaunas
1966Klaipeda
1967?iauliai
1968Panevezys
1969EXPLAIN
1970SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
1971FROM Country LEFT JOIN CountryLanguage ON
1972(CountryLanguage.Country=Country.Code AND Language='English')
1973WHERE
1974Country.Population > 10000000;
1975id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
19761	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
19771	SIMPLE	CountryLanguage	eq_ref	PRIMARY	PRIMARY	33	world.Country.Code,const	1	Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
1978SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
1979FROM Country LEFT JOIN CountryLanguage ON
1980(CountryLanguage.Country=Country.Code AND Language='English')
1981WHERE
1982Country.Population > 10000000;
1983Name	IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
1984Australia	81.2
1985United Kingdom	97.3
1986Canada	60.4
1987United States	86.2
1988Zimbabwe	2.2
1989Japan	0.1
1990South Africa	8.5
1991Malaysia	1.6
1992Afghanistan	NULL
1993Netherlands	NULL
1994Algeria	NULL
1995Angola	NULL
1996Argentina	NULL
1997Bangladesh	NULL
1998Belgium	NULL
1999Brazil	NULL
2000Burkina Faso	NULL
2001Chile	NULL
2002Ecuador	NULL
2003Egypt	NULL
2004Spain	NULL
2005Ethiopia	NULL
2006Philippines	NULL
2007Ghana	NULL
2008Guatemala	NULL
2009Indonesia	NULL
2010India	NULL
2011Iraq	NULL
2012Iran	NULL
2013Italy	NULL
2014Yemen	NULL
2015Yugoslavia	NULL
2016Cambodia	NULL
2017Cameroon	NULL
2018Kazakstan	NULL
2019Kenya	NULL
2020China	NULL
2021Colombia	NULL
2022Congo, The Democratic Republic of the	NULL
2023North Korea	NULL
2024South Korea	NULL
2025Greece	NULL
2026Cuba	NULL
2027Madagascar	NULL
2028Malawi	NULL
2029Mali	NULL
2030Morocco	NULL
2031Mexico	NULL
2032Mozambique	NULL
2033Myanmar	NULL
2034Nepal	NULL
2035Niger	NULL
2036Nigeria	NULL
2037Côte d?Ivoire	NULL
2038Pakistan	NULL
2039Peru	NULL
2040Poland	NULL
2041France	NULL
2042Romania	NULL
2043Germany	NULL
2044Saudi Arabia	NULL
2045Somalia	NULL
2046Sri Lanka	NULL
2047Sudan	NULL
2048Syria	NULL
2049Taiwan	NULL
2050Tanzania	NULL
2051Thailand	NULL
2052Czech Republic	NULL
2053Turkey	NULL
2054Uganda	NULL
2055Ukraine	NULL
2056Hungary	NULL
2057Uzbekistan	NULL
2058Belarus	NULL
2059Venezuela	NULL
2060Russian Federation	NULL
2061Vietnam	NULL
2062set join_buffer_size=256;
2063show variables like 'join_buffer_size';
2064Variable_name	Value
2065join_buffer_size	256
2066set join_cache_level=3;
2067show variables like 'join_cache_level';
2068Variable_name	Value
2069join_cache_level	3
2070EXPLAIN
2071SELECT City.Name, Country.Name FROM City,Country
2072WHERE City.Country=Country.Code AND
2073Country.Name LIKE 'L%' AND City.Population > 100000;
2074id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
20751	SIMPLE	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
20761	SIMPLE	City	hash_ALL	Population,Country	#hash#Country	3	world.Country.Code	4079	Using where; Using join buffer (flat, BNLH join)
2077SELECT City.Name, Country.Name FROM City,Country
2078WHERE City.Country=Country.Code AND
2079Country.Name LIKE 'L%' AND City.Population > 100000;
2080Name	Name
2081?iauliai	Lithuania
2082Beirut	Lebanon
2083Bengasi	Libyan Arab Jamahiriya
2084Daugavpils	Latvia
2085Kaunas	Lithuania
2086Klaipeda	Lithuania
2087Maseru	Lesotho
2088Misrata	Libyan Arab Jamahiriya
2089Monrovia	Liberia
2090Panevezys	Lithuania
2091Riga	Latvia
2092Tripoli	Lebanon
2093Tripoli	Libyan Arab Jamahiriya
2094Vientiane	Laos
2095Vilnius	Lithuania
2096EXPLAIN
2097SELECT City.Name, Country.Name, CountryLanguage.Language
2098FROM City,Country,CountryLanguage
2099WHERE City.Country=Country.Code AND
2100CountryLanguage.Country=Country.Code AND
2101City.Name LIKE 'L%' AND Country.Population > 3000000 AND
2102CountryLanguage.Percentage > 50 AND
2103LENGTH(Language) < LENGTH(City.Name) - 2;
2104id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
21051	SIMPLE	City	ALL	Country	NULL	NULL	NULL	4079	Using where
21061	SIMPLE	Country	hash_ALL	PRIMARY	#hash#PRIMARY	3	world.City.Country	239	Using where; Using join buffer (flat, BNLH join)
21071	SIMPLE	CountryLanguage	hash_ALL|filter	PRIMARY,Percentage	#hash#PRIMARY|Percentage	3|4	world.City.Country	984 (19%)	Using where; Using join buffer (flat, BNLH join); Using rowid filter
2108SELECT City.Name, Country.Name, CountryLanguage.Language
2109FROM City,Country,CountryLanguage
2110WHERE City.Country=Country.Code AND
2111CountryLanguage.Country=Country.Code AND
2112City.Name LIKE 'L%' AND Country.Population > 3000000 AND
2113CountryLanguage.Percentage > 50 AND
2114LENGTH(Language) < LENGTH(City.Name) - 2;
2115Name	Name	Language
2116La Matanza	Argentina	Spanish
2117Lagos de Moreno	Mexico	Spanish
2118Lalitapur	Nepal	Nepali
2119Las Margaritas	Mexico	Spanish
2120Las Palmas de Gran Canaria	Spain	Spanish
2121Lashio (Lasho)	Myanmar	Burmese
2122Lauro de Freitas	Brazil	Portuguese
2123Lengshuijiang	China	Chinese
2124Leninsk-Kuznetski	Russian Federation	Russian
2125Leverkusen	Germany	German
2126Lexington-Fayette	United States	English
2127Liangcheng	China	Chinese
2128Lianyungang	China	Chinese
2129Little Rock	United States	English
2130Liupanshui	China	Chinese
2131Lleida (Lérida)	Spain	Spanish
2132Lomas de Zamora	Argentina	Spanish
2133Long Beach	United States	English
2134Los Angeles	Chile	Spanish
2135Los Angeles	United States	English
2136Los Teques	Venezuela	Spanish
2137Louisville	United States	English
2138Lower Hutt	New Zealand	English
2139Luchou	Taiwan	Min
2140Ludwigshafen am Rhein	Germany	German
2141Lungtan	Taiwan	Min
2142L´Hospitalet de Llobregat	Spain	Spanish
2143Lázaro Cárdenas	Mexico	Spanish
2144EXPLAIN
2145SELECT Name FROM City
2146WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
2147City.Population > 100000;
2148id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
21491	PRIMARY	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
21501	PRIMARY	City	hash_ALL	Population,Country	#hash#Country	3	world.Country.Code	4079	Using where; Using join buffer (flat, BNLH join)
2151SELECT Name FROM City
2152WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
2153City.Population > 100000;
2154Name
2155Vientiane
2156Riga
2157Daugavpils
2158Maseru
2159Beirut
2160Tripoli
2161Monrovia
2162Tripoli
2163Bengasi
2164Misrata
2165Vilnius
2166Kaunas
2167Klaipeda
2168?iauliai
2169Panevezys
2170set join_cache_level=4;
2171show variables like 'join_cache_level';
2172Variable_name	Value
2173join_cache_level	4
2174EXPLAIN
2175SELECT City.Name, Country.Name FROM City,Country
2176WHERE City.Country=Country.Code AND
2177Country.Name LIKE 'L%' AND City.Population > 100000;
2178id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
21791	SIMPLE	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
21801	SIMPLE	City	hash_ALL	Population,Country	#hash#Country	3	world.Country.Code	4079	Using where; Using join buffer (flat, BNLH join)
2181SELECT City.Name, Country.Name FROM City,Country
2182WHERE City.Country=Country.Code AND
2183Country.Name LIKE 'L%' AND City.Population > 100000;
2184Name	Name
2185?iauliai	Lithuania
2186Beirut	Lebanon
2187Bengasi	Libyan Arab Jamahiriya
2188Daugavpils	Latvia
2189Kaunas	Lithuania
2190Klaipeda	Lithuania
2191Maseru	Lesotho
2192Misrata	Libyan Arab Jamahiriya
2193Monrovia	Liberia
2194Panevezys	Lithuania
2195Riga	Latvia
2196Tripoli	Lebanon
2197Tripoli	Libyan Arab Jamahiriya
2198Vientiane	Laos
2199Vilnius	Lithuania
2200EXPLAIN
2201SELECT City.Name, Country.Name, CountryLanguage.Language
2202FROM City,Country,CountryLanguage
2203WHERE City.Country=Country.Code AND
2204CountryLanguage.Country=Country.Code AND
2205City.Name LIKE 'L%' AND Country.Population > 3000000 AND
2206CountryLanguage.Percentage > 50 AND
2207LENGTH(Language) < LENGTH(City.Name) - 2;
2208id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
22091	SIMPLE	City	ALL	Country	NULL	NULL	NULL	4079	Using where
22101	SIMPLE	Country	hash_ALL	PRIMARY	#hash#PRIMARY	3	world.City.Country	239	Using where; Using join buffer (flat, BNLH join)
22111	SIMPLE	CountryLanguage	hash_ALL|filter	PRIMARY,Percentage	#hash#PRIMARY|Percentage	3|4	world.City.Country	984 (19%)	Using where; Using join buffer (incremental, BNLH join); Using rowid filter
2212SELECT City.Name, Country.Name, CountryLanguage.Language
2213FROM City,Country,CountryLanguage
2214WHERE City.Country=Country.Code AND
2215CountryLanguage.Country=Country.Code AND
2216City.Name LIKE 'L%' AND Country.Population > 3000000 AND
2217CountryLanguage.Percentage > 50 AND
2218LENGTH(Language) < LENGTH(City.Name) - 2;
2219Name	Name	Language
2220La Matanza	Argentina	Spanish
2221Lagos de Moreno	Mexico	Spanish
2222Lalitapur	Nepal	Nepali
2223Las Margaritas	Mexico	Spanish
2224Las Palmas de Gran Canaria	Spain	Spanish
2225Lashio (Lasho)	Myanmar	Burmese
2226Lauro de Freitas	Brazil	Portuguese
2227Lengshuijiang	China	Chinese
2228Leninsk-Kuznetski	Russian Federation	Russian
2229Leverkusen	Germany	German
2230Lexington-Fayette	United States	English
2231Liangcheng	China	Chinese
2232Lianyungang	China	Chinese
2233Little Rock	United States	English
2234Liupanshui	China	Chinese
2235Lleida (Lérida)	Spain	Spanish
2236Lomas de Zamora	Argentina	Spanish
2237Long Beach	United States	English
2238Los Angeles	Chile	Spanish
2239Los Angeles	United States	English
2240Los Teques	Venezuela	Spanish
2241Louisville	United States	English
2242Lower Hutt	New Zealand	English
2243Luchou	Taiwan	Min
2244Ludwigshafen am Rhein	Germany	German
2245Lungtan	Taiwan	Min
2246L´Hospitalet de Llobregat	Spain	Spanish
2247Lázaro Cárdenas	Mexico	Spanish
2248EXPLAIN
2249SELECT Name FROM City
2250WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
2251City.Population > 100000;
2252id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
22531	PRIMARY	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
22541	PRIMARY	City	hash_ALL	Population,Country	#hash#Country	3	world.Country.Code	4079	Using where; Using join buffer (flat, BNLH join)
2255SELECT Name FROM City
2256WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
2257City.Population > 100000;
2258Name
2259Vientiane
2260Riga
2261Daugavpils
2262Maseru
2263Beirut
2264Tripoli
2265Monrovia
2266Tripoli
2267Bengasi
2268Misrata
2269Vilnius
2270Kaunas
2271Klaipeda
2272?iauliai
2273Panevezys
2274set join_cache_level=5;
2275show variables like 'join_cache_level';
2276Variable_name	Value
2277join_cache_level	5
2278EXPLAIN
2279SELECT City.Name, Country.Name FROM City,Country
2280WHERE City.Country=Country.Code AND
2281Country.Name LIKE 'L%' AND City.Population > 100000;
2282id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
22831	SIMPLE	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
22841	SIMPLE	City	ref	Population,Country	Country	3	world.Country.Code	17	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
2285SELECT City.Name, Country.Name FROM City,Country
2286WHERE City.Country=Country.Code AND
2287Country.Name LIKE 'L%' AND City.Population > 100000;
2288Name	Name
2289?iauliai	Lithuania
2290Beirut	Lebanon
2291Bengasi	Libyan Arab Jamahiriya
2292Daugavpils	Latvia
2293Kaunas	Lithuania
2294Klaipeda	Lithuania
2295Maseru	Lesotho
2296Misrata	Libyan Arab Jamahiriya
2297Monrovia	Liberia
2298Panevezys	Lithuania
2299Riga	Latvia
2300Tripoli	Lebanon
2301Tripoli	Libyan Arab Jamahiriya
2302Vientiane	Laos
2303Vilnius	Lithuania
2304EXPLAIN
2305SELECT City.Name, Country.Name, CountryLanguage.Language
2306FROM City,Country,CountryLanguage
2307WHERE City.Country=Country.Code AND
2308CountryLanguage.Country=Country.Code AND
2309City.Name LIKE 'L%' AND Country.Population > 3000000 AND
2310CountryLanguage.Percentage > 50 AND
2311LENGTH(Language) < LENGTH(City.Name) - 2;
2312id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
23131	SIMPLE	City	ALL	Country	NULL	NULL	NULL	4079	Using where
23141	SIMPLE	Country	eq_ref	PRIMARY	PRIMARY	3	world.City.Country	1	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
23151	SIMPLE	CountryLanguage	ref|filter	PRIMARY,Percentage	PRIMARY|Percentage	3|4	world.City.Country	4 (19%)	Using index condition(BKA); Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter
2316SELECT City.Name, Country.Name, CountryLanguage.Language
2317FROM City,Country,CountryLanguage
2318WHERE City.Country=Country.Code AND
2319CountryLanguage.Country=Country.Code AND
2320City.Name LIKE 'L%' AND Country.Population > 3000000 AND
2321CountryLanguage.Percentage > 50 AND
2322LENGTH(Language) < LENGTH(City.Name) - 2;
2323Name	Name	Language
2324La Matanza	Argentina	Spanish
2325Lagos de Moreno	Mexico	Spanish
2326Lalitapur	Nepal	Nepali
2327Las Margaritas	Mexico	Spanish
2328Las Palmas de Gran Canaria	Spain	Spanish
2329Lashio (Lasho)	Myanmar	Burmese
2330Lauro de Freitas	Brazil	Portuguese
2331Lengshuijiang	China	Chinese
2332Leninsk-Kuznetski	Russian Federation	Russian
2333Leverkusen	Germany	German
2334Lexington-Fayette	United States	English
2335Liangcheng	China	Chinese
2336Lianyungang	China	Chinese
2337Little Rock	United States	English
2338Liupanshui	China	Chinese
2339Lleida (Lérida)	Spain	Spanish
2340Lomas de Zamora	Argentina	Spanish
2341Long Beach	United States	English
2342Los Angeles	Chile	Spanish
2343Los Angeles	United States	English
2344Los Teques	Venezuela	Spanish
2345Louisville	United States	English
2346Lower Hutt	New Zealand	English
2347Luchou	Taiwan	Min
2348Ludwigshafen am Rhein	Germany	German
2349Lungtan	Taiwan	Min
2350L´Hospitalet de Llobregat	Spain	Spanish
2351Lázaro Cárdenas	Mexico	Spanish
2352EXPLAIN
2353SELECT Name FROM City
2354WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
2355City.Population > 100000;
2356id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
23571	PRIMARY	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
23581	PRIMARY	City	ref	Population,Country	Country	3	world.Country.Code	17	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
2359SELECT Name FROM City
2360WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
2361City.Population > 100000;
2362Name
2363Vientiane
2364Riga
2365Daugavpils
2366Maseru
2367Beirut
2368Tripoli
2369Monrovia
2370Tripoli
2371Bengasi
2372Misrata
2373Vilnius
2374Kaunas
2375Klaipeda
2376?iauliai
2377Panevezys
2378set join_cache_level=6;
2379show variables like 'join_cache_level';
2380Variable_name	Value
2381join_cache_level	6
2382EXPLAIN
2383SELECT City.Name, Country.Name FROM City,Country
2384WHERE City.Country=Country.Code AND
2385Country.Name LIKE 'L%' AND City.Population > 100000;
2386id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
23871	SIMPLE	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
23881	SIMPLE	City	ref	Population,Country	Country	3	world.Country.Code	17	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
2389SELECT City.Name, Country.Name FROM City,Country
2390WHERE City.Country=Country.Code AND
2391Country.Name LIKE 'L%' AND City.Population > 100000;
2392Name	Name
2393?iauliai	Lithuania
2394Beirut	Lebanon
2395Bengasi	Libyan Arab Jamahiriya
2396Daugavpils	Latvia
2397Kaunas	Lithuania
2398Klaipeda	Lithuania
2399Maseru	Lesotho
2400Misrata	Libyan Arab Jamahiriya
2401Monrovia	Liberia
2402Panevezys	Lithuania
2403Riga	Latvia
2404Tripoli	Lebanon
2405Tripoli	Libyan Arab Jamahiriya
2406Vientiane	Laos
2407Vilnius	Lithuania
2408EXPLAIN
2409SELECT City.Name, Country.Name, CountryLanguage.Language
2410FROM City,Country,CountryLanguage
2411WHERE City.Country=Country.Code AND
2412CountryLanguage.Country=Country.Code AND
2413City.Name LIKE 'L%' AND Country.Population > 3000000 AND
2414CountryLanguage.Percentage > 50 AND
2415LENGTH(Language) < LENGTH(City.Name) - 2;
2416id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
24171	SIMPLE	City	ALL	Country	NULL	NULL	NULL	4079	Using where
24181	SIMPLE	Country	eq_ref	PRIMARY	PRIMARY	3	world.City.Country	1	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
24191	SIMPLE	CountryLanguage	ref|filter	PRIMARY,Percentage	PRIMARY|Percentage	3|4	world.City.Country	4 (19%)	Using index condition(BKA); Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter
2420SELECT City.Name, Country.Name, CountryLanguage.Language
2421FROM City,Country,CountryLanguage
2422WHERE City.Country=Country.Code AND
2423CountryLanguage.Country=Country.Code AND
2424City.Name LIKE 'L%' AND Country.Population > 3000000 AND
2425CountryLanguage.Percentage > 50 AND
2426LENGTH(Language) < LENGTH(City.Name) - 2;
2427Name	Name	Language
2428La Matanza	Argentina	Spanish
2429Lagos de Moreno	Mexico	Spanish
2430Lalitapur	Nepal	Nepali
2431Las Margaritas	Mexico	Spanish
2432Las Palmas de Gran Canaria	Spain	Spanish
2433Lashio (Lasho)	Myanmar	Burmese
2434Lauro de Freitas	Brazil	Portuguese
2435Lengshuijiang	China	Chinese
2436Leninsk-Kuznetski	Russian Federation	Russian
2437Leverkusen	Germany	German
2438Lexington-Fayette	United States	English
2439Liangcheng	China	Chinese
2440Lianyungang	China	Chinese
2441Little Rock	United States	English
2442Liupanshui	China	Chinese
2443Lleida (Lérida)	Spain	Spanish
2444Lomas de Zamora	Argentina	Spanish
2445Long Beach	United States	English
2446Los Angeles	Chile	Spanish
2447Los Angeles	United States	English
2448Los Teques	Venezuela	Spanish
2449Louisville	United States	English
2450Lower Hutt	New Zealand	English
2451Luchou	Taiwan	Min
2452Ludwigshafen am Rhein	Germany	German
2453Lungtan	Taiwan	Min
2454L´Hospitalet de Llobregat	Spain	Spanish
2455Lázaro Cárdenas	Mexico	Spanish
2456EXPLAIN
2457SELECT Name FROM City
2458WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
2459City.Population > 100000;
2460id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
24611	PRIMARY	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
24621	PRIMARY	City	ref	Population,Country	Country	3	world.Country.Code	17	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
2463SELECT Name FROM City
2464WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
2465City.Population > 100000;
2466Name
2467Vientiane
2468Riga
2469Daugavpils
2470Maseru
2471Beirut
2472Tripoli
2473Monrovia
2474Tripoli
2475Bengasi
2476Misrata
2477Vilnius
2478Kaunas
2479Klaipeda
2480?iauliai
2481Panevezys
2482set join_cache_level=7;
2483show variables like 'join_cache_level';
2484Variable_name	Value
2485join_cache_level	7
2486EXPLAIN
2487SELECT City.Name, Country.Name FROM City,Country
2488WHERE City.Country=Country.Code AND
2489Country.Name LIKE 'L%' AND City.Population > 100000;
2490id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
24911	SIMPLE	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
24921	SIMPLE	City	ref	Population,Country	Country	3	world.Country.Code	17	Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
2493SELECT City.Name, Country.Name FROM City,Country
2494WHERE City.Country=Country.Code AND
2495Country.Name LIKE 'L%' AND City.Population > 100000;
2496Name	Name
2497?iauliai	Lithuania
2498Beirut	Lebanon
2499Bengasi	Libyan Arab Jamahiriya
2500Daugavpils	Latvia
2501Kaunas	Lithuania
2502Klaipeda	Lithuania
2503Maseru	Lesotho
2504Misrata	Libyan Arab Jamahiriya
2505Monrovia	Liberia
2506Panevezys	Lithuania
2507Riga	Latvia
2508Tripoli	Lebanon
2509Tripoli	Libyan Arab Jamahiriya
2510Vientiane	Laos
2511Vilnius	Lithuania
2512EXPLAIN
2513SELECT City.Name, Country.Name, CountryLanguage.Language
2514FROM City,Country,CountryLanguage
2515WHERE City.Country=Country.Code AND
2516CountryLanguage.Country=Country.Code AND
2517City.Name LIKE 'L%' AND Country.Population > 3000000 AND
2518CountryLanguage.Percentage > 50 AND
2519LENGTH(Language) < LENGTH(City.Name) - 2;
2520id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
25211	SIMPLE	City	ALL	Country	NULL	NULL	NULL	4079	Using where
25221	SIMPLE	Country	eq_ref	PRIMARY	PRIMARY	3	world.City.Country	1	Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
25231	SIMPLE	CountryLanguage	ref|filter	PRIMARY,Percentage	PRIMARY|Percentage	3|4	world.City.Country	4 (19%)	Using index condition(BKA); Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan; Using rowid filter
2524SELECT City.Name, Country.Name, CountryLanguage.Language
2525FROM City,Country,CountryLanguage
2526WHERE City.Country=Country.Code AND
2527CountryLanguage.Country=Country.Code AND
2528City.Name LIKE 'L%' AND Country.Population > 3000000 AND
2529CountryLanguage.Percentage > 50 AND
2530LENGTH(Language) < LENGTH(City.Name) - 2;
2531Name	Name	Language
2532La Matanza	Argentina	Spanish
2533Lagos de Moreno	Mexico	Spanish
2534Lalitapur	Nepal	Nepali
2535Las Margaritas	Mexico	Spanish
2536Las Palmas de Gran Canaria	Spain	Spanish
2537Lashio (Lasho)	Myanmar	Burmese
2538Lauro de Freitas	Brazil	Portuguese
2539Lengshuijiang	China	Chinese
2540Leninsk-Kuznetski	Russian Federation	Russian
2541Leverkusen	Germany	German
2542Lexington-Fayette	United States	English
2543Liangcheng	China	Chinese
2544Lianyungang	China	Chinese
2545Little Rock	United States	English
2546Liupanshui	China	Chinese
2547Lleida (Lérida)	Spain	Spanish
2548Lomas de Zamora	Argentina	Spanish
2549Long Beach	United States	English
2550Los Angeles	Chile	Spanish
2551Los Angeles	United States	English
2552Los Teques	Venezuela	Spanish
2553Louisville	United States	English
2554Lower Hutt	New Zealand	English
2555Luchou	Taiwan	Min
2556Ludwigshafen am Rhein	Germany	German
2557Lungtan	Taiwan	Min
2558L´Hospitalet de Llobregat	Spain	Spanish
2559Lázaro Cárdenas	Mexico	Spanish
2560EXPLAIN
2561SELECT Name FROM City
2562WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
2563City.Population > 100000;
2564id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
25651	PRIMARY	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
25661	PRIMARY	City	ref	Population,Country	Country	3	world.Country.Code	17	Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
2567SELECT Name FROM City
2568WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
2569City.Population > 100000;
2570Name
2571Vientiane
2572Riga
2573Daugavpils
2574Maseru
2575Beirut
2576Tripoli
2577Monrovia
2578Tripoli
2579Bengasi
2580Misrata
2581Vilnius
2582Kaunas
2583Klaipeda
2584?iauliai
2585Panevezys
2586set join_cache_level=8;
2587show variables like 'join_cache_level';
2588Variable_name	Value
2589join_cache_level	8
2590EXPLAIN
2591SELECT City.Name, Country.Name FROM City,Country
2592WHERE City.Country=Country.Code AND
2593Country.Name LIKE 'L%' AND City.Population > 100000;
2594id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
25951	SIMPLE	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
25961	SIMPLE	City	ref	Population,Country	Country	3	world.Country.Code	17	Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
2597SELECT City.Name, Country.Name FROM City,Country
2598WHERE City.Country=Country.Code AND
2599Country.Name LIKE 'L%' AND City.Population > 100000;
2600Name	Name
2601?iauliai	Lithuania
2602Beirut	Lebanon
2603Bengasi	Libyan Arab Jamahiriya
2604Daugavpils	Latvia
2605Kaunas	Lithuania
2606Klaipeda	Lithuania
2607Maseru	Lesotho
2608Misrata	Libyan Arab Jamahiriya
2609Monrovia	Liberia
2610Panevezys	Lithuania
2611Riga	Latvia
2612Tripoli	Lebanon
2613Tripoli	Libyan Arab Jamahiriya
2614Vientiane	Laos
2615Vilnius	Lithuania
2616EXPLAIN
2617SELECT City.Name, Country.Name, CountryLanguage.Language
2618FROM City,Country,CountryLanguage
2619WHERE City.Country=Country.Code AND
2620CountryLanguage.Country=Country.Code AND
2621City.Name LIKE 'L%' AND Country.Population > 3000000 AND
2622CountryLanguage.Percentage > 50 AND
2623LENGTH(Language) < LENGTH(City.Name) - 2;
2624id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
26251	SIMPLE	City	ALL	Country	NULL	NULL	NULL	4079	Using where
26261	SIMPLE	Country	eq_ref	PRIMARY	PRIMARY	3	world.City.Country	1	Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
26271	SIMPLE	CountryLanguage	ref|filter	PRIMARY,Percentage	PRIMARY|Percentage	3|4	world.City.Country	4 (19%)	Using index condition(BKA); Using where; Using join buffer (incremental, BKAH join); Key-ordered Rowid-ordered scan; Using rowid filter
2628SELECT City.Name, Country.Name, CountryLanguage.Language
2629FROM City,Country,CountryLanguage
2630WHERE City.Country=Country.Code AND
2631CountryLanguage.Country=Country.Code AND
2632City.Name LIKE 'L%' AND Country.Population > 3000000 AND
2633CountryLanguage.Percentage > 50 AND
2634LENGTH(Language) < LENGTH(City.Name) - 2;
2635Name	Name	Language
2636La Matanza	Argentina	Spanish
2637Lagos de Moreno	Mexico	Spanish
2638Lalitapur	Nepal	Nepali
2639Las Margaritas	Mexico	Spanish
2640Las Palmas de Gran Canaria	Spain	Spanish
2641Lashio (Lasho)	Myanmar	Burmese
2642Lauro de Freitas	Brazil	Portuguese
2643Lengshuijiang	China	Chinese
2644Leninsk-Kuznetski	Russian Federation	Russian
2645Leverkusen	Germany	German
2646Lexington-Fayette	United States	English
2647Liangcheng	China	Chinese
2648Lianyungang	China	Chinese
2649Little Rock	United States	English
2650Liupanshui	China	Chinese
2651Lleida (Lérida)	Spain	Spanish
2652Lomas de Zamora	Argentina	Spanish
2653Long Beach	United States	English
2654Los Angeles	Chile	Spanish
2655Los Angeles	United States	English
2656Los Teques	Venezuela	Spanish
2657Louisville	United States	English
2658Lower Hutt	New Zealand	English
2659Luchou	Taiwan	Min
2660Ludwigshafen am Rhein	Germany	German
2661Lungtan	Taiwan	Min
2662L´Hospitalet de Llobregat	Spain	Spanish
2663Lázaro Cárdenas	Mexico	Spanish
2664EXPLAIN
2665SELECT Name FROM City
2666WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
2667City.Population > 100000;
2668id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
26691	PRIMARY	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Rowid-ordered scan
26701	PRIMARY	City	ref	Population,Country	Country	3	world.Country.Code	17	Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
2671SELECT Name FROM City
2672WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
2673City.Population > 100000;
2674Name
2675Vientiane
2676Riga
2677Daugavpils
2678Maseru
2679Beirut
2680Tripoli
2681Monrovia
2682Tripoli
2683Bengasi
2684Misrata
2685Vilnius
2686Kaunas
2687Klaipeda
2688?iauliai
2689Panevezys
2690set join_cache_level=@save_join_cache_level;
2691set join_buffer_size=@save_join_buffer_size;
2692set join_cache_level=1;
2693SELECT City.Name, Country.Name FROM City,Country
2694WHERE City.Country=Country.Code AND City.Population > 3000000;
2695Name	Name
2696Alexandria	Egypt
2697Ankara	Turkey
2698Baghdad	Iraq
2699Bangkok	Thailand
2700Berlin	Germany
2701Cairo	Egypt
2702Calcutta [Kolkata]	India
2703Chengdu	China
2704Chennai (Madras)	India
2705Chongqing	China
2706Ciudad de México	Mexico
2707Delhi	India
2708Dhaka	Bangladesh
2709Harbin	China
2710Ho Chi Minh City	Vietnam
2711Istanbul	Turkey
2712Jakarta	Indonesia
2713Jokohama [Yokohama]	Japan
2714Kanton [Guangzhou]	China
2715Karachi	Pakistan
2716Kinshasa	Congo, The Democratic Republic of the
2717Lahore	Pakistan
2718Lima	Peru
2719London	United Kingdom
2720Los Angeles	United States
2721Moscow	Russian Federation
2722Mumbai (Bombay)	India
2723New York	United States
2724Peking	China
2725Pusan	South Korea
2726Rangoon (Yangon)	Myanmar
2727Rio de Janeiro	Brazil
2728Riyadh	Saudi Arabia
2729Santafé de Bogotá	Colombia
2730Santiago de Chile	Chile
2731Seoul	South Korea
2732Shanghai	China
2733Shenyang	China
2734Singapore	Singapore
2735St Petersburg	Russian Federation
2736Sydney	Australia
2737São Paulo	Brazil
2738Teheran	Iran
2739Tianjin	China
2740Tokyo	Japan
2741Wuhan	China
2742set join_cache_level=8;
2743set join_buffer_size=384;
2744EXPLAIN
2745SELECT City.Name, Country.Name FROM City,Country
2746WHERE City.Country=Country.Code AND City.Population > 3000000;
2747id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
27481	SIMPLE	City	range	Population,Country	Population	4	NULL	#	Using index condition; Rowid-ordered scan
27491	SIMPLE	Country	eq_ref	PRIMARY	PRIMARY	3	world.City.Country	#	Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
2750SELECT City.Name, Country.Name FROM City,Country
2751WHERE City.Country=Country.Code AND City.Population > 3000000;
2752Name	Name
2753Alexandria	Egypt
2754Ankara	Turkey
2755Baghdad	Iraq
2756Bangkok	Thailand
2757Berlin	Germany
2758Cairo	Egypt
2759Calcutta [Kolkata]	India
2760Chengdu	China
2761Chennai (Madras)	India
2762Chongqing	China
2763Ciudad de México	Mexico
2764Delhi	India
2765Dhaka	Bangladesh
2766Harbin	China
2767Ho Chi Minh City	Vietnam
2768Istanbul	Turkey
2769Jakarta	Indonesia
2770Jokohama [Yokohama]	Japan
2771Kanton [Guangzhou]	China
2772Karachi	Pakistan
2773Kinshasa	Congo, The Democratic Republic of the
2774Lahore	Pakistan
2775Lima	Peru
2776London	United Kingdom
2777Los Angeles	United States
2778Moscow	Russian Federation
2779Mumbai (Bombay)	India
2780New York	United States
2781Peking	China
2782Pusan	South Korea
2783Rangoon (Yangon)	Myanmar
2784Rio de Janeiro	Brazil
2785Riyadh	Saudi Arabia
2786Santafé de Bogotá	Colombia
2787Santiago de Chile	Chile
2788Seoul	South Korea
2789Shanghai	China
2790Shenyang	China
2791Singapore	Singapore
2792St Petersburg	Russian Federation
2793Sydney	Australia
2794São Paulo	Brazil
2795Teheran	Iran
2796Tianjin	China
2797Tokyo	Japan
2798Wuhan	China
2799set join_buffer_size=@save_join_buffer_size;
2800set join_cache_level=6;
2801ALTER TABLE Country MODIFY Name varchar(52) NOT NULL default '';
2802SELECT City.Name, Country.Name FROM City,Country
2803WHERE City.Country=Country.Code AND
2804Country.Name LIKE 'L%' AND City.Population > 100000;
2805Name	Name
2806?iauliai	Lithuania
2807Beirut	Lebanon
2808Bengasi	Libyan Arab Jamahiriya
2809Daugavpils	Latvia
2810Kaunas	Lithuania
2811Klaipeda	Lithuania
2812Maseru	Lesotho
2813Misrata	Libyan Arab Jamahiriya
2814Monrovia	Liberia
2815Panevezys	Lithuania
2816Riga	Latvia
2817Tripoli	Lebanon
2818Tripoli	Libyan Arab Jamahiriya
2819Vientiane	Laos
2820Vilnius	Lithuania
2821ALTER TABLE Country MODIFY Name varchar(300) NOT NULL default '';
2822SELECT City.Name, Country.Name FROM City,Country
2823WHERE City.Country=Country.Code AND
2824Country.Name LIKE 'L%' AND City.Population > 100000;
2825Name	Name
2826?iauliai	Lithuania
2827Beirut	Lebanon
2828Bengasi	Libyan Arab Jamahiriya
2829Daugavpils	Latvia
2830Kaunas	Lithuania
2831Klaipeda	Lithuania
2832Maseru	Lesotho
2833Misrata	Libyan Arab Jamahiriya
2834Monrovia	Liberia
2835Panevezys	Lithuania
2836Riga	Latvia
2837Tripoli	Lebanon
2838Tripoli	Libyan Arab Jamahiriya
2839Vientiane	Laos
2840Vilnius	Lithuania
2841ALTER TABLE Country ADD COLUMN PopulationBar text;
2842UPDATE Country
2843SET PopulationBar=REPEAT('x', CAST(Population/100000 AS unsigned int));
2844SELECT City.Name, Country.Name, Country.PopulationBar FROM City,Country
2845WHERE City.Country=Country.Code AND
2846Country.Name LIKE 'L%' AND City.Population > 100000;
2847Name	Name	PopulationBar
2848?iauliai	Lithuania	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2849Beirut	Lebanon	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2850Bengasi	Libyan Arab Jamahiriya	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2851Daugavpils	Latvia	xxxxxxxxxxxxxxxxxxxxxxxx
2852Kaunas	Lithuania	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2853Klaipeda	Lithuania	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2854Maseru	Lesotho	xxxxxxxxxxxxxxxxxxxxxx
2855Misrata	Libyan Arab Jamahiriya	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2856Monrovia	Liberia	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2857Panevezys	Lithuania	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2858Riga	Latvia	xxxxxxxxxxxxxxxxxxxxxxxx
2859Tripoli	Lebanon	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2860Tripoli	Libyan Arab Jamahiriya	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2861Vientiane	Laos	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2862Vilnius	Lithuania	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2863set join_buffer_size=256;
2864SELECT City.Name, Country.Name, Country.PopulationBar FROM City,Country
2865WHERE City.Country=Country.Code AND
2866Country.Name LIKE 'L%' AND City.Population > 100000;
2867Name	Name	PopulationBar
2868?iauliai	Lithuania	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2869Beirut	Lebanon	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2870Bengasi	Libyan Arab Jamahiriya	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2871Daugavpils	Latvia	xxxxxxxxxxxxxxxxxxxxxxxx
2872Kaunas	Lithuania	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2873Klaipeda	Lithuania	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2874Maseru	Lesotho	xxxxxxxxxxxxxxxxxxxxxx
2875Misrata	Libyan Arab Jamahiriya	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2876Monrovia	Liberia	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2877Panevezys	Lithuania	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2878Riga	Latvia	xxxxxxxxxxxxxxxxxxxxxxxx
2879Tripoli	Lebanon	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2880Tripoli	Libyan Arab Jamahiriya	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2881Vientiane	Laos	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2882Vilnius	Lithuania	xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2883set join_cache_level=@save_join_cache_level;
2884set join_buffer_size=@save_join_buffer_size;
2885#
2886# MDEV-17752: Plan changes from hash_index_merge to index_merge with new optimizer defaults
2887#
2888set @save_optimizer_use_condition_selectivity=@@optimizer_use_condition_selectivity;
2889set @save_use_stat_tables=@@use_stat_tables;
2890set optimizer_use_condition_selectivity=4;
2891set use_stat_tables='preferably';
2892use world;
2893set join_cache_level=4;
2894CREATE INDEX City_Name ON City(Name);
2895ANALYZE TABLE City, Country;
2896EXPLAIN
2897SELECT Country.Name, Country.Population, City.Name, City.Population
2898FROM Country LEFT JOIN City
2899ON City.Country=Country.Code AND City.Population > 5000000
2900WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000;
2901id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
29021	SIMPLE	Country	range	Name	Name	302	NULL	15	Using index condition; Using where; Rowid-ordered scan
29031	SIMPLE	City	hash_range	Population,Country	#hash#Country:Population	3:4	world.Country.Code	24	Using where; Rowid-ordered scan; Using join buffer (flat, BNLH join)
2904EXPLAIN
2905SELECT Country.Name, Country.Population, City.Name, City.Population
2906FROM Country LEFT JOIN City
2907ON City.Country=Country.Code AND
2908(City.Population > 5000000 OR City.Name LIKE 'Za%')
2909WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000;
2910id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
29111	SIMPLE	Country	range	Name	Name	302	NULL	15	Using index condition; Using where; Rowid-ordered scan
29121	SIMPLE	City	hash_index_merge	Population,Country,City_Name	#hash#Country:Population,City_Name	3:4,35	world.Country.Code	96	Using sort_union(Population,City_Name); Using where; Using join buffer (flat, BNLH join)
2913set @@optimizer_use_condition_selectivity=@save_optimizer_use_condition_selectivity;
2914set @@use_stat_tables=@save_use_stat_tables;
2915set @@join_cache_level=@save_join_cache_level;
2916DROP DATABASE world;
2917use test;
2918CREATE TABLE t1(
2919affiliatetometaid int  NOT NULL default '0',
2920uniquekey int NOT NULL default '0',
2921metaid int  NOT NULL default '0',
2922affiliateid int  NOT NULL default '0',
2923xml text,
2924isactive char(1) NOT NULL default 'Y',
2925PRIMARY KEY  (affiliatetometaid)
2926);
2927CREATE UNIQUE INDEX t1_uniquekey ON t1(uniquekey);
2928CREATE INDEX t1_affiliateid ON t1(affiliateid);
2929CREATE INDEX t1_metaid on t1 (metaid);
2930INSERT INTO t1 VALUES
2931(1616, 1571693233, 1391, 2, NULL, 'Y'), (1943, 1993216749, 1726, 2, NULL, 'Y');
2932CREATE TABLE t2(
2933metaid int  NOT NULL default '0',
2934name varchar(80) NOT NULL default '',
2935dateadded timestamp NOT NULL ,
2936xml text,
2937status int default NULL,
2938origin int default NULL,
2939gid int NOT NULL default '1',
2940formattypeid int  default NULL,
2941PRIMARY KEY  (metaid)
2942);
2943CREATE INDEX t2_status ON t2(status);
2944CREATE INDEX t2_gid ON t2(gid);
2945CREATE INDEX t2_formattypeid ON t2(formattypeid);
2946INSERT INTO t2 VALUES
2947(1391, "I Just Died", "2003-10-02 10:07:37", "", 1, NULL, 3, NULL),
2948(1726, "Me, Myself & I", "2003-12-05 11:24:36", " ", 1, NULL, 3, NULL);
2949CREATE TABLE t3(
2950mediaid int  NOT NULL ,
2951metaid int  NOT NULL default '0',
2952formatid int  NOT NULL default '0',
2953status int default NULL,
2954path varchar(100) NOT NULL default '',
2955datemodified timestamp NOT NULL ,
2956resourcetype int  NOT NULL default '1',
2957parameters text,
2958signature int  default NULL,
2959quality int  NOT NULL default '255',
2960PRIMARY KEY  (mediaid)
2961);
2962CREATE INDEX t3_metaid ON t3(metaid);
2963CREATE INDEX t3_formatid ON t3(formatid);
2964CREATE INDEX t3_status ON t3(status);
2965CREATE INDEX t3_metaidformatid ON t3(metaid,formatid);
2966CREATE INDEX t3_signature ON t3(signature);
2967CREATE INDEX t3_quality ON t3(quality);
2968INSERT INTO t3 VALUES
2969(6, 4, 8, 0, "010101_anastacia_spmidi.mid", "2004-03-16 13:40:00", 1, NULL, NULL, 255),
2970(3343, 3, 8, 1, "010102_4VN4bsPwnxRQUJW5Zp1RhG2IL9vvl_8.mid", "2004-03-16 13:40:00", 1, NULL, NULL, 255);
2971insert into t3 (mediaid, formatid) values (1000,1),(1001,2),(1002,3),(1003,1),(1004,2),(1005,3);
2972CREATE TABLE t4(
2973formatid int  NOT NULL ,
2974name varchar(60) NOT NULL default '',
2975formatclassid int  NOT NULL default '0',
2976mime varchar(60) default NULL,
2977extension varchar(10) default NULL,
2978priority int NOT NULL default '0',
2979canaddtocapability char(1) NOT NULL default 'Y',
2980PRIMARY KEY  (formatid)
2981);
2982CREATE INDEX t4_formatclassid ON t4(formatclassid);
2983CREATE INDEX t4_formats_idx ON t4(canaddtocapability);
2984INSERT INTO t4 VALUES
2985(19, "XHTML", 11, "text/html", "xhtml", 10, 'Y'),
2986(54, "AMR (wide band)", 13, "audio/amr-wb", "awb", 0, 'Y');
2987CREATE TABLE t5(
2988formatclassid int  NOT NULL ,
2989name varchar(60) NOT NULL default '',
2990priority int NOT NULL default '0',
2991formattypeid int  NOT NULL default '0',
2992PRIMARY KEY  (formatclassid)
2993);
2994CREATE INDEX t5_formattypeid on t5(formattypeid);
2995INSERT INTO t5 VALUES
2996(11, "Info", 0, 4), (13, "Digital Audio", 0, 2);
2997CREATE TABLE t6(
2998formattypeid int  NOT NULL ,
2999name varchar(60) NOT NULL default '',
3000priority int default NULL,
3001PRIMARY KEY  (formattypeid)
3002);
3003INSERT INTO t6 VALUES
3004(2, "Ringtones", 0);
3005CREATE TABLE t7(
3006metaid int  NOT NULL default '0',
3007artistid int  NOT NULL default '0',
3008PRIMARY KEY  (metaid,artistid)
3009);
3010INSERT INTO t7 VALUES
3011(4, 5), (3, 4);
3012CREATE TABLE t8(
3013artistid int  NOT NULL ,
3014name varchar(80) NOT NULL default '',
3015PRIMARY KEY  (artistid)
3016);
3017INSERT INTO t8 VALUES
3018(5, "Anastacia"), (4, "John Mayer");
3019CREATE TABLE t9(
3020subgenreid int  NOT NULL default '0',
3021metaid int  NOT NULL default '0',
3022PRIMARY KEY  (subgenreid,metaid)
3023) ;
3024CREATE INDEX t9_subgenreid ON t9(subgenreid);
3025CREATE INDEX t9_metaid ON t9(metaid);
3026INSERT INTO t9 VALUES
3027(138, 4), (31, 3);
3028CREATE TABLE t10(
3029subgenreid int  NOT NULL ,
3030genreid int  NOT NULL default '0',
3031name varchar(80) NOT NULL default '',
3032PRIMARY KEY  (subgenreid)
3033) ;
3034CREATE INDEX t10_genreid ON t10(genreid);
3035INSERT INTO t10 VALUES
3036(138, 19, ''), (31, 3, '');
3037CREATE TABLE t11(
3038genreid int  NOT NULL default '0',
3039name char(80) NOT NULL default '',
3040priority int NOT NULL default '0',
3041masterclip char(1) default NULL,
3042PRIMARY KEY  (genreid)
3043) ;
3044CREATE INDEX t11_masterclip ON t11( masterclip);
3045INSERT INTO t11 VALUES
3046(19, "Pop & Dance", 95, 'Y'), (3, "Rock & Alternative", 100, 'Y');
3047set join_cache_level=6;
3048EXPLAIN
3049SELECT t1.uniquekey, t1.xml AS affiliateXml,
3050t8.name AS artistName, t8.artistid,
3051t11.name AS genreName, t11.genreid, t11.priority AS genrePriority,
3052t10.subgenreid, t10.name AS subgenreName,
3053t2.name AS metaName, t2.metaid, t2.xml AS metaXml,
3054t4.priority + t5.priority + t6.priority AS overallPriority,
3055t3.path AS path, t3.mediaid,
3056t4.formatid, t4.name AS formatName,
3057t5.formatclassid, t5.name AS formatclassName,
3058t6.formattypeid, t6.name AS formattypeName
3059FROM t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11
3060WHERE t7.metaid = t2.metaid AND t7.artistid = t8.artistid AND
3061t9.metaid = t2.metaid AND t9.subgenreid = t10.subgenreid AND
3062t10.genreid = t11.genreid AND  t3.metaid = t2.metaid AND
3063t3.formatid = t4.formatid AND t4.formatclassid = t5.formatclassid AND
3064t4.canaddtocapability =  'Y' AND t5.formattypeid = t6.formattypeid AND
3065t6.formattypeid IN (2) AND (t3.formatid IN (31, 8, 76)) AND
3066t1.metaid = t2.metaid AND t1.affiliateid = '2';
3067id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
30681	SIMPLE	t6	system	PRIMARY	NULL	NULL	NULL	1
30691	SIMPLE	t5	ref	PRIMARY,t5_formattypeid	t5_formattypeid	4	const	1
30701	SIMPLE	t1	ref	t1_affiliateid,t1_metaid	t1_affiliateid	4	const	2	Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
30711	SIMPLE	t2	eq_ref	PRIMARY	PRIMARY	4	test.t1.metaid	1	Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
30721	SIMPLE	t7	ref	PRIMARY	PRIMARY	4	test.t1.metaid	1	Using index
30731	SIMPLE	t8	eq_ref	PRIMARY	PRIMARY	4	test.t7.artistid	1	Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
30741	SIMPLE	t3	ref	t3_metaid,t3_formatid,t3_metaidformatid	t3_metaidformatid	4	test.t1.metaid	1	Using index condition; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
30751	SIMPLE	t4	eq_ref	PRIMARY,t4_formatclassid,t4_formats_idx	PRIMARY	4	test.t3.formatid	1	Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
30761	SIMPLE	t9	index	PRIMARY,t9_subgenreid,t9_metaid	PRIMARY	8	NULL	2	Using where; Using index; Using join buffer (incremental, BNL join)
30771	SIMPLE	t10	eq_ref	PRIMARY,t10_genreid	PRIMARY	4	test.t9.subgenreid	1	Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
30781	SIMPLE	t11	eq_ref	PRIMARY	PRIMARY	4	test.t10.genreid	1	Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
3079SELECT t1.uniquekey, t1.xml AS affiliateXml,
3080t8.name AS artistName, t8.artistid,
3081t11.name AS genreName, t11.genreid, t11.priority AS genrePriority,
3082t10.subgenreid, t10.name AS subgenreName,
3083t2.name AS metaName, t2.metaid, t2.xml AS metaXml,
3084t4.priority + t5.priority + t6.priority AS overallPriority,
3085t3.path AS path, t3.mediaid,
3086t4.formatid, t4.name AS formatName,
3087t5.formatclassid, t5.name AS formatclassName,
3088t6.formattypeid, t6.name AS formattypeName
3089FROM t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11
3090WHERE t7.metaid = t2.metaid AND t7.artistid = t8.artistid AND
3091t9.metaid = t2.metaid AND t9.subgenreid = t10.subgenreid AND
3092t10.genreid = t11.genreid AND  t3.metaid = t2.metaid AND
3093t3.formatid = t4.formatid AND t4.formatclassid = t5.formatclassid AND
3094t4.canaddtocapability =  'Y' AND t5.formattypeid = t6.formattypeid AND
3095t6.formattypeid IN (2) AND (t3.formatid IN (31, 8, 76)) AND
3096t1.metaid = t2.metaid AND t1.affiliateid = '2';
3097uniquekey	affiliateXml	artistName	artistid	genreName	genreid	genrePriority	subgenreid	subgenreName	metaName	metaid	metaXml	overallPriority	path	mediaid	formatid	formatName	formatclassid	formatclassName	formattypeid	formattypeName
3098DROP TABLE t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11;
3099CREATE TABLE t1 (a1 int, filler1 char(64) default ' ' );
3100CREATE TABLE t2 (
3101a2 int, b2 int, filler2 char(64) default ' ',
3102PRIMARY KEY idx(a2,b2,filler2)
3103) ;
3104Warnings:
3105Warning	1280	Name 'idx' ignored for PRIMARY key.
3106CREATE TABLE t3 (b3 int, c3 int, INDEX idx(b3));
3107INSERT INTO t1(a1) VALUES
3108(4), (7), (1), (9), (8), (5), (3), (6), (2);
3109INSERT INTO t2(a2,b2) VALUES
3110(1,30), (3,40), (2,61), (6,73), (8,92), (9,27), (4,18), (5,84), (7,56),
3111(4,14), (6,76), (8,98), (7,55), (1,39), (2,68), (3,45), (9,21), (5,81),
3112(5,88), (2,65), (6,74), (9,23), (1,37), (3,44), (4,17), (8,99), (7,51),
3113(9,28), (7,52), (1,33), (4,13), (5,87), (3,43), (8,91), (2,62), (6,79),
3114(3,49), (8,93), (7,34), (5,82), (6,78), (2,63), (1,32), (9,22), (4,11);
3115INSERT INTO t3 VALUES
3116(30,302), (92,923), (18,187), (45,459), (30,309),
3117(39,393), (68,685), (45,458), (21,210), (81,817),
3118(40,405), (61,618), (73,738), (92,929), (27,275),
3119(18,188), (84,846), (56,564), (14,144), (76,763),
3120(98,982), (55,551), (17,174), (99,998), (51,513),
3121(28,282), (52,527), (33,336), (13,138), (87,878),
3122(43,431), (91,916), (62,624), (79,797), (49,494),
3123(93,933), (34,347), (82,829), (78,780), (63,634),
3124(32,329), (22,228), (11,114), (74,749), (23,236);
3125set join_cache_level=1;
3126EXPLAIN
3127SELECT a1<>a2, a1, a2, b2, b3, c3,
3128SUBSTR(filler1,1,1) AS s1, SUBSTR(filler2,1,1) AS s2
3129FROM t1,t2,t3 WHERE a1=a2 AND b2=b3 AND MOD(c3,10)>7;
3130id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
31311	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	9	Using where
31321	SIMPLE	t2	ref	PRIMARY	PRIMARY	4	test.t1.a1	1	Using index
31331	SIMPLE	t3	ref	idx	idx	5	test.t2.b2	5	Using where
3134SELECT a1<>a2, a1, a2, b2, b3, c3,
3135SUBSTR(filler1,1,1) AS s1, SUBSTR(filler2,1,1) AS s2
3136FROM t1,t2,t3 WHERE a1=a2 AND b2=b3 AND MOD(c3,10)>7;
3137a1<>a2	a1	a2	b2	b3	c3	s1	s2
31380	4	4	13	13	138
31390	4	4	18	18	188
31400	1	1	30	30	309
31410	1	1	32	32	329
31420	9	9	22	22	228
31430	8	8	92	92	929
31440	8	8	99	99	998
31450	5	5	82	82	829
31460	5	5	87	87	878
31470	3	3	45	45	459
31480	3	3	45	45	458
31490	6	6	73	73	738
31500	6	6	74	74	749
31510	2	2	61	61	618
3152set join_cache_level=5;
3153set join_buffer_size=512;
3154EXPLAIN
3155SELECT a1<>a2, a1, a2, b2, b3, c3,
3156SUBSTR(filler1,1,1) AS s1, SUBSTR(filler2,1,1) AS s2
3157FROM t1,t2,t3 WHERE a1=a2 AND b2=b3 AND MOD(c3,10)>7;
3158id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
31591	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	9	Using where
31601	SIMPLE	t2	ref	PRIMARY	PRIMARY	4	test.t1.a1	1	Using index
31611	SIMPLE	t3	ref	idx	idx	5	test.t2.b2	5	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
3162SELECT a1<>a2, a1, a2, b2, b3, c3,
3163SUBSTR(filler1,1,1) AS s1, SUBSTR(filler2,1,1) AS s2
3164FROM t1,t2,t3 WHERE a1=a2 AND b2=b3 AND MOD(c3,10)>7;
3165a1<>a2	a1	a2	b2	b3	c3	s1	s2
31660	4	4	18	18	188
31670	4	4	13	13	138
31680	1	1	30	30	309
31690	1	1	32	32	329
31700	9	9	22	22	228
31710	8	8	92	92	929
31720	8	8	99	99	998
31730	5	5	82	82	829
31740	3	3	45	45	459
31750	3	3	45	45	458
31760	5	5	87	87	878
31770	2	2	61	61	618
31780	6	6	73	73	738
31790	6	6	74	74	749
3180DROP TABLE t1,t2,t3;
3181CREATE TABLE t1 (a int, b int, INDEX idx(b));
3182CREATE TABLE t2 (a int, b int, INDEX idx(a));
3183INSERT INTO t1 VALUES (5,30), (3,20), (7,40), (2,10), (8,30), (1,10), (4,20);
3184INSERT INTO t2 VALUES (7,10), (1,20), (2,20), (8,20), (8,10), (1,20);
3185INSERT INTO t2 VALUES (1,10), (4,20), (3,20), (7,20), (7,10), (1,20);
3186INSERT INTO t2 VALUES (17,10), (11,20), (12,20), (18,20), (18,10), (11,20);
3187INSERT INTO t2 VALUES (11,10), (14,20), (13,20), (17,20), (17,10), (11,20);
3188set join_buffer_size=32;
3189Warnings:
3190Warning	1292	Truncated incorrect join_buffer_size value: '32'
3191set join_cache_level=8;
3192EXPLAIN SELECT * FROM t1,t2 WHERE t1.a=t2.a AND t1.b >= 30;
3193id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
31941	SIMPLE	t1	range	idx	idx	5	NULL	3	Using index condition; Using where; Rowid-ordered scan
31951	SIMPLE	t2	ref	idx	idx	5	test.t1.a	2	Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
3196SELECT * FROM t1,t2 WHERE t1.a=t2.a AND t1.b >= 30;
3197a	b	a	b
31987	40	7	10
31997	40	7	10
32007	40	7	20
32018	30	8	10
32028	30	8	20
3203DROP TABLE t1,t2;
3204#
3205# Bug #40134: outer join with not exists optimization and join buffer
3206#
3207set join_cache_level=@save_join_cache_level;
3208set join_buffer_size=@save_join_buffer_size;
3209CREATE TABLE t1 (a int NOT NULL);
3210INSERT INTO t1 VALUES (2), (4), (3), (5), (1);
3211CREATE TABLE t2 (a int NOT NULL, b int NOT NULL, INDEX i_a(a));
3212INSERT INTO t2 VALUES (4,10), (2,10), (2,30), (2,20), (4,20);
3213INSERT INTO t2 VALUES (14,10), (12,10), (15,30), (12,20), (14,20);
3214EXPLAIN
3215SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.a WHERE t2.b IS NULL;
3216id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
32171	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5
32181	SIMPLE	t2	ref	i_a	i_a	4	test.t1.a	2	Using where; Not exists
3219SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.a WHERE t2.b IS NULL;
3220a	a	b
32213	NULL	NULL
32225	NULL	NULL
32231	NULL	NULL
3224SET join_cache_level=6;
3225EXPLAIN
3226SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.a WHERE t2.b IS NULL;
3227id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
32281	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5
32291	SIMPLE	t2	ref	i_a	i_a	4	test.t1.a	2	Using where; Not exists; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
3230SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.a WHERE t2.b IS NULL;
3231a	a	b
32323	NULL	NULL
32335	NULL	NULL
32341	NULL	NULL
3235DROP TABLE t1, t2;
3236set join_cache_level=@save_join_cache_level;
3237set join_buffer_size=@save_join_buffer_size;
3238#
3239# BUG#40136: Group by is ignored when join buffer is used for an outer join
3240#
3241create table t1(a int PRIMARY KEY, b int);
3242insert into t1 values
3243(5, 10), (2, 70), (7, 80), (6, 20), (1, 50), (9, 40), (8, 30), (3, 60);
3244create table t2 (p int, a int, INDEX i_a(a));
3245insert into t2 values
3246(103, 7), (109, 3), (102, 3), (108, 1), (106, 3),
3247(107, 7), (105, 1), (101, 3), (100, 7), (110, 1);
3248set @save_join_cache_level=@@join_cache_level;
3249set join_cache_level=6;
3250The following must not show "using join cache":
3251explain
3252select t1.a, count(t2.p) as count
3253from t1 left join t2 on t1.a=t2.a and t2.p % 2 = 1 group by t1.a;
3254id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
32551	SIMPLE	t1	index	NULL	PRIMARY	4	NULL	8	Using index; Using temporary; Using filesort
32561	SIMPLE	t2	ref	i_a	i_a	5	test.t1.a	2	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
3257select t1.a, count(t2.p) as count
3258from t1 left join t2 on t1.a=t2.a and t2.p % 2 = 1 group by t1.a;
3259a	count
32601	1
32612	0
32623	2
32635	0
32646	0
32657	2
32668	0
32679	0
3268set join_cache_level=@save_join_cache_level;
3269drop table t1, t2;
3270#
3271# BUG#40268: Nested outer join with not null-rejecting where condition
3272#            over an inner table which is not the last in the nest
3273#
3274CREATE TABLE t2 (a int, b int, c int);
3275CREATE TABLE t3 (a int, b int, c int);
3276CREATE TABLE t4 (a int, b int, c int);
3277INSERT INTO t2 VALUES (3,3,0), (4,2,0), (5,3,0);
3278INSERT INTO t3 VALUES (1,2,0), (2,2,0);
3279INSERT INTO t4 VALUES (3,2,0), (4,2,0);
3280set join_cache_level=6;
3281SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
3282FROM t2 LEFT JOIN (t3, t4) ON t2.b=t4.b
3283WHERE t3.a+2<t2.a OR t3.c IS NULL;
3284a	b	a	b	a	b
32854	2	1	2	3	2
32864	2	1	2	4	2
32873	3	NULL	NULL	NULL	NULL
32885	3	NULL	NULL	NULL	NULL
3289set join_cache_level=@save_join_cache_level;
3290DROP TABLE t2, t3, t4;
3291#
3292# Bug #40192: outer join with where clause when using BNL
3293#
3294create table t1 (a int, b int);
3295insert into t1 values (2, 20), (3, 30), (1, 10);
3296create table t2 (a int, c int);
3297insert into t2 values (1, 101), (3, 102), (1, 100);
3298set join_cache_level=6;
3299select * from t1 left join t2 on t1.a=t2.a;
3300a	b	a	c
33011	10	1	101
33023	30	3	102
33031	10	1	100
33042	20	NULL	NULL
3305explain select * from t1 left join t2 on t1.a=t2.a where t2.c=102 or t2.c is null;
3306id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
33071	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3
33081	SIMPLE	t2	hash_ALL	NULL	#hash#$hj	5	test.t1.a	3	Using where; Using join buffer (flat, BNLH join)
3309select * from t1 left join t2 on t1.a=t2.a where t2.c=102 or t2.c is null;
3310a	b	a	c
33113	30	3	102
33122	20	NULL	NULL
3313set join_cache_level=@save_join_cache_level;
3314drop table t1, t2;
3315#
3316# Bug #40317: outer join with with constant on expression equal to FALSE
3317#
3318create table t1 (a int);
3319insert into t1 values (30), (40), (20);
3320create table t2 (b int);
3321insert into t2 values (200), (100);
3322set join_cache_level=6;
3323select * from t1 left join t2 on (1=0);
3324a	b
332530	NULL
332640	NULL
332720	NULL
3328explain select * from t1 left join t2 on (1=0) where a=40;
3329id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
33301	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
33311	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	2	Using where; Using join buffer (flat, BNL join)
3332select * from t1 left join t2 on (1=0) where a=40;
3333a	b
333440	NULL
3335set join_cache_level=0;
3336explain select * from t1 left join t2 on (1=0);
3337id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
33381	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3
33391	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	2	Using where
3340set join_cache_level=@save_join_cache_level;
3341drop table t1, t2;
3342#
3343# Bug #41204: small buffer with big rec_per_key for ref access
3344#
3345CREATE TABLE t1 (a int);
3346INSERT INTO t1 VALUES (0);
3347INSERT INTO t1(a) SELECT a FROM t1;
3348INSERT INTO t1(a) SELECT a FROM t1;
3349INSERT INTO t1(a) SELECT a FROM t1;
3350INSERT INTO t1(a) SELECT a FROM t1;
3351INSERT INTO t1(a) SELECT a FROM t1;
3352INSERT INTO t1(a) SELECT a FROM t1;
3353INSERT INTO t1(a) SELECT a FROM t1;
3354INSERT INTO t1(a) SELECT a FROM t1;
3355INSERT INTO t1(a) SELECT a FROM t1;
3356INSERT INTO t1(a) SELECT a FROM t1;
3357INSERT INTO t1(a) SELECT a FROM t1;
3358INSERT INTO t1 VALUES (20000), (10000);
3359CREATE TABLE t2 (pk int AUTO_INCREMENT PRIMARY KEY, b int, c int, INDEX idx(b));
3360INSERT INTO t2(b,c) VALUES (10000, 3), (20000, 7), (20000, 1), (10000, 9), (20000, 5);
3361INSERT INTO t2(b,c) SELECT b,c FROM t2;
3362INSERT INTO t2(b,c) SELECT b,c FROM t2;
3363INSERT INTO t2(b,c) SELECT b,c FROM t2;
3364INSERT INTO t2(b,c) SELECT b,c FROM t2;
3365INSERT INTO t2(b,c) SELECT b,c FROM t2;
3366INSERT INTO t2(b,c) SELECT b,c FROM t2;
3367INSERT INTO t2(b,c) SELECT b,c FROM t2;
3368INSERT INTO t2(b,c) SELECT b,c FROM t2;
3369ANALYZE TABLE t1,t2;
3370set join_cache_level=6;
3371set join_buffer_size=1024;
3372EXPLAIN SELECT AVG(c) FROM t1,t2 WHERE t1.a=t2.b;
3373id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
33741	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2050	Using where
33751	SIMPLE	t2	ref	idx	idx	5	test.t1.a	640	Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
3376SELECT AVG(c) FROM t1,t2 WHERE t1.a=t2.b;
3377AVG(c)
33785.0000
3379set join_buffer_size=@save_join_buffer_size;
3380set join_cache_level=@save_join_cache_level;
3381DROP TABLE t1, t2;
3382#
3383# Bug #41894: big join buffer of level 7 used to join records
3384#              with null values in place of varchar strings
3385#
3386CREATE TABLE t1 (a int NOT NULL AUTO_INCREMENT PRIMARY KEY,
3387b varchar(127) DEFAULT NULL);
3388INSERT INTO t1(a) VALUES (1);
3389INSERT INTO t1(b) SELECT b FROM t1;
3390INSERT INTO t1(b) SELECT b FROM t1;
3391INSERT INTO t1(b) SELECT b FROM t1;
3392INSERT INTO t1(b) SELECT b FROM t1;
3393INSERT INTO t1(b) SELECT b FROM t1;
3394INSERT INTO t1(b) SELECT b FROM t1;
3395INSERT INTO t1(b) SELECT b FROM t1;
3396INSERT INTO t1(b) SELECT b FROM t1;
3397INSERT INTO t1(b) SELECT b FROM t1;
3398INSERT INTO t1(b) SELECT b FROM t1;
3399INSERT INTO t1(b) SELECT b FROM t1;
3400INSERT INTO t1(b) SELECT b FROM t1;
3401INSERT INTO t1(b) SELECT b FROM t1;
3402INSERT INTO t1(b) SELECT b FROM t1;
3403CREATE TABLE t2 (a int NOT NULL PRIMARY KEY, b varchar(127) DEFAULT NULL);
3404INSERT INTO t2 SELECT * FROM t1;
3405CREATE TABLE t3 (a int NOT NULL PRIMARY KEY, b varchar(127) DEFAULT NULL);
3406INSERT INTO t3 SELECT * FROM t1;
3407set join_cache_level=7;
3408set join_buffer_size=1024*1024;
3409EXPLAIN
3410SELECT COUNT(*) FROM t1,t2,t3
3411WHERE t1.a=t2.a AND t2.a=t3.a AND
3412t1.b IS NULL AND t2.b IS NULL AND t3.b IS NULL;
3413id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
34141	SIMPLE	t1	ALL	PRIMARY	NULL	NULL	NULL	16384	Using where
34151	SIMPLE	t2	eq_ref	PRIMARY	PRIMARY	4	test.t1.a	1	Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
34161	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	4	test.t1.a	1	Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
3417SELECT COUNT(*) FROM t1,t2,t3
3418WHERE t1.a=t2.a AND t2.a=t3.a AND
3419t1.b IS NULL AND t2.b IS NULL AND t3.b IS NULL;
3420COUNT(*)
342116384
3422set join_buffer_size=@save_join_buffer_size;
3423set join_cache_level=@save_join_cache_level;
3424DROP TABLE t1,t2,t3;
3425#
3426# Bug #42020: join buffer is used  for outer join with fields of
3427#             several outer tables in join buffer
3428#
3429CREATE TABLE t1 (
3430a bigint NOT NULL,
3431PRIMARY KEY (a)
3432);
3433INSERT INTO t1 VALUES
3434(2), (1);
3435CREATE TABLE t2 (
3436a bigint NOT NULL,
3437b bigint NOT NULL,
3438PRIMARY KEY (a,b)
3439);
3440INSERT INTO t2 VALUES
3441(2,30), (2,40), (2,50), (2,60), (2,70), (2,80),
3442(1,10), (1, 20), (1,30), (1,40), (1,50);
3443CREATE TABLE t3 (
3444pk bigint NOT NULL AUTO_INCREMENT,
3445a bigint NOT NULL,
3446b bigint NOT NULL,
3447val bigint DEFAULT '0',
3448PRIMARY KEY (pk),
3449KEY idx (a,b)
3450);
3451INSERT INTO t3(a,b) VALUES
3452(2,30), (2,40), (2,50), (2,60), (2,70), (2,80),
3453(4,30), (4,40), (4,50), (4,60), (4,70), (4,80),
3454(5,30), (5,40), (5,50), (5,60), (5,70), (5,80),
3455(7,30), (7,40), (7,50), (7,60), (7,70), (7,80);
3456set join_cache_level=0;
3457SELECT t1.a, t2.a, t3.a, t2.b, t3.b, t3.val
3458FROM (t1,t2) LEFT JOIN t3 ON (t1.a=t3.a AND t2.b=t3.b)
3459WHERE t1.a=t2.a;
3460a	a	a	b	b	val
34611	1	NULL	10	NULL	NULL
34621	1	NULL	20	NULL	NULL
34631	1	NULL	30	NULL	NULL
34641	1	NULL	40	NULL	NULL
34651	1	NULL	50	NULL	NULL
34662	2	2	30	30	0
34672	2	2	40	40	0
34682	2	2	50	50	0
34692	2	2	60	60	0
34702	2	2	70	70	0
34712	2	2	80	80	0
3472set join_cache_level=6;
3473set join_buffer_size=256;
3474EXPLAIN
3475SELECT t1.a, t2.a, t3.a, t2.b, t3.b, t3.val
3476FROM (t1,t2) LEFT JOIN t3 ON (t1.a=t3.a AND t2.b=t3.b)
3477WHERE t1.a=t2.a;
3478id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
34791	SIMPLE	t1	index	PRIMARY	PRIMARY	8	NULL	2	Using index
34801	SIMPLE	t2	ref	PRIMARY	PRIMARY	8	test.t1.a	1	Using index
34811	SIMPLE	t3	ref	idx	idx	16	test.t1.a,test.t2.b	2	Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
3482SELECT t1.a, t2.a, t3.a, t2.b, t3.b, t3.val
3483FROM (t1,t2) LEFT JOIN t3 ON (t1.a=t3.a AND t2.b=t3.b)
3484WHERE t1.a=t2.a;
3485a	a	a	b	b	val
34861	1	NULL	10	NULL	NULL
34871	1	NULL	20	NULL	NULL
34881	1	NULL	30	NULL	NULL
34891	1	NULL	40	NULL	NULL
34901	1	NULL	50	NULL	NULL
34912	2	2	30	30	0
34922	2	2	40	40	0
34932	2	2	50	50	0
34942	2	2	60	60	0
34952	2	2	70	70	0
34962	2	2	80	80	0
3497DROP INDEX idx ON t3;
3498set join_cache_level=2;
3499EXPLAIN
3500SELECT t1.a, t2.a, t3.a, t2.b, t3.b, t3.val
3501FROM (t1,t2) LEFT JOIN t3 ON (t1.a=t3.a AND t2.b=t3.b)
3502WHERE t1.a=t2.a;
3503id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
35041	SIMPLE	t1	index	PRIMARY	PRIMARY	8	NULL	2	Using index
35051	SIMPLE	t2	ref	PRIMARY	PRIMARY	8	test.t1.a	1	Using index
35061	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	24	Using where; Using join buffer (flat, BNL join)
3507SELECT t1.a, t2.a, t3.a, t2.b, t3.b, t3.val
3508FROM (t1,t2) LEFT JOIN t3 ON (t1.a=t3.a AND t2.b=t3.b)
3509WHERE t1.a=t2.a;
3510a	a	a	b	b	val
35111	1	NULL	10	NULL	NULL
35121	1	NULL	20	NULL	NULL
35131	1	NULL	30	NULL	NULL
35141	1	NULL	40	NULL	NULL
35151	1	NULL	50	NULL	NULL
35162	2	2	30	30	0
35172	2	2	40	40	0
35182	2	2	50	50	0
35192	2	2	60	60	0
35202	2	2	70	70	0
35212	2	2	80	80	0
3522set join_buffer_size=@save_join_buffer_size;
3523set join_cache_level=@save_join_cache_level;
3524DROP TABLE t1,t2,t3;
3525create table t1(f1 int, f2 int);
3526insert into t1 values (1,1),(2,2),(3,3);
3527create table t2(f1 int not null, f2 int not null, f3 char(200), key(f1,f2));
3528insert into t2 values (1,1, 'qwerty'),(1,2, 'qwerty'),(1,3, 'qwerty');
3529insert into t2 values (2,1, 'qwerty'),(2,2, 'qwerty'),(2,3, 'qwerty'),
3530(2,4, 'qwerty'),(2,5, 'qwerty');
3531insert into t2 values (3,1, 'qwerty'),(3,4, 'qwerty');
3532insert into t2 values (4,1, 'qwerty'),(4,2, 'qwerty'),(4,3, 'qwerty'),
3533(4,4, 'qwerty');
3534insert into t2 values (1,1, 'qwerty'),(1,2, 'qwerty'),(1,3, 'qwerty');
3535insert into t2 values (2,1, 'qwerty'),(2,2, 'qwerty'),(2,3, 'qwerty'),
3536(2,4, 'qwerty'),(2,5, 'qwerty');
3537insert into t2 values (3,1, 'qwerty'),(3,4, 'qwerty');
3538insert into t2 values (4,1, 'qwerty'),(4,2, 'qwerty'),(4,3, 'qwerty'),
3539(4,4, 'qwerty');
3540flush status;
3541set join_cache_level=5;
3542select t2.f1, t2.f2, t2.f3 from t1,t2
3543where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1;
3544f1	f2	f3
35451	1	qwerty
35462	2	qwerty
35471	1	qwerty
35482	2	qwerty
3549explain select t2.f1, t2.f2, t2.f3 from t1,t2
3550where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2;
3551id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
35521	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
35531	SIMPLE	t2	ref	f1	f1	4	test.t1.f1	3	Using index condition(BKA); Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
3554show status like "Handler_icp%";
3555Variable_name	Value
3556Handler_icp_attempts	20
3557Handler_icp_match	4
3558set join_cache_level=6;
3559select t2.f1, t2.f2, t2.f3 from t1,t2
3560where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1;
3561f1	f2	f3
35621	1	qwerty
35632	2	qwerty
35641	1	qwerty
35652	2	qwerty
3566explain select t2.f1, t2.f2, t2.f3 from t1,t2
3567where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2;
3568id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
35691	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
35701	SIMPLE	t2	ref	f1	f1	4	test.t1.f1	3	Using index condition(BKA); Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
3571show status like "Handler_icp%";
3572Variable_name	Value
3573Handler_icp_attempts	40
3574Handler_icp_match	8
3575set join_cache_level=7;
3576select t2.f1, t2.f2, t2.f3 from t1,t2
3577where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1;
3578f1	f2	f3
35791	1	qwerty
35802	2	qwerty
35811	1	qwerty
35822	2	qwerty
3583explain select t2.f1, t2.f2, t2.f3 from t1,t2
3584where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2;
3585id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
35861	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
35871	SIMPLE	t2	ref	f1	f1	4	test.t1.f1	3	Using index condition(BKA); Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
3588show status like "Handler_icp%";
3589Variable_name	Value
3590Handler_icp_attempts	60
3591Handler_icp_match	12
3592set join_cache_level=8;
3593select t2.f1, t2.f2, t2.f3 from t1,t2
3594where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1;
3595f1	f2	f3
35961	1	qwerty
35972	2	qwerty
35981	1	qwerty
35992	2	qwerty
3600explain select t2.f1, t2.f2, t2.f3 from t1,t2
3601where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2;
3602id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
36031	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
36041	SIMPLE	t2	ref	f1	f1	4	test.t1.f1	3	Using index condition(BKA); Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
3605show status like "Handler_icp%";
3606Variable_name	Value
3607Handler_icp_attempts	80
3608Handler_icp_match	16
3609drop table t1,t2;
3610set join_cache_level=@save_join_cache_level;
3611#
3612# Bug #42955: join with GROUP BY/ORDER BY and when BKA is enabled
3613#
3614create table t1 (d int, id1 int, index idx1 (d, id1));
3615insert into t1 values
3616(3, 20), (2, 40), (3, 10), (1, 10), (3, 20), (1, 40), (2, 30), (3, 30);
3617create table t2 (id1 int, id2 int, index idx2 (id1));
3618insert into t2 values
3619(20, 100), (30, 400), (20, 400), (30, 200), (10, 300), (10, 200), (40, 100),
3620(40, 200), (30, 300), (10, 400), (20, 200), (20, 300);
3621insert into t2 values
3622(21, 10), (31, 400), (21, 400), (31, 200), (11, 300), (11, 200), (41, 100),
3623(41, 200), (31, 300), (11, 400), (21, 200), (21, 300);
3624set join_cache_level=6;
3625explain
3626select t1.id1, sum(t2.id2) from t1 join t2 on t1.id1=t2.id1
3627where t1.d=3 group by t1.id1;
3628id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
36291	SIMPLE	t1	ref	idx1	idx1	5	const	4	Using where; Using index; Using temporary; Using filesort
36301	SIMPLE	t2	ref	idx2	idx2	5	test.t1.id1	2	Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
3631select t1.id1, sum(t2.id2) from t1 join t2 on t1.id1=t2.id1
3632where t1.d=3 group by t1.id1;
3633id1	sum(t2.id2)
363410	900
363520	2000
363630	900
3637explain
3638select t1.id1  from t1 join t2 on t1.id1=t2.id1
3639where t1.d=3 and t2.id2 > 200 order by t1.id1;
3640id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
36411	SIMPLE	t1	ref	idx1	idx1	5	const	4	Using where; Using index; Using temporary; Using filesort
36421	SIMPLE	t2	ref	idx2	idx2	5	test.t1.id1	2	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
3643select t1.id1  from t1 join t2 on t1.id1=t2.id1
3644where t1.d=3 and t2.id2 > 200 order by t1.id1;
3645id1
364610
364710
364820
364920
365020
365120
365230
365330
3654set join_cache_level=@save_join_cache_level;
3655drop table t1,t2;
3656#
3657# Bug #44019: star-like multi-join query executed join_cache_level=6
3658#
3659create table t1 (a int, b int, c int, d int);
3660create table t2 (b int, e varchar(16), index idx(b));
3661create table t3 (d int, f varchar(16), index idx(d));
3662create table t4 (c int, g varchar(16), index idx(c));
3663insert into t1 values
3664(5, 50, 500, 5000), (3, 30, 300, 3000), (9, 90, 900, 9000),
3665(2, 20, 200, 2000), (4, 40, 400, 4000), (8, 80, 800, 800),
3666(7, 70, 700, 7000);
3667insert into t2 values
3668(30, 'bbb'), (10, 'b'), (70, 'bbbbbbb'), (60, 'bbbbbb'),
3669(31, 'bbb'), (11, 'b'), (71, 'bbbbbbb'), (61, 'bbbbbb'),
3670(32, 'bbb'), (12, 'b'), (72, 'bbbbbbb'), (62, 'bbbbbb');
3671insert into t2 values
3672(130, 'bbb'), (110, 'b'), (170, 'bbbbbbb'), (160, 'bbbbbb'),
3673(131, 'bbb'), (111, 'b'), (171, 'bbbbbbb'), (161, 'bbbbbb'),
3674(132, 'bbb'), (112, 'b'), (172, 'bbbbbbb'), (162, 'bbbbbb');
3675insert into t3 values
3676(4000, 'dddd'), (3000, 'ddd'), (1000, 'd'), (8000, 'dddddddd'),
3677(4001, 'dddd'), (3001, 'ddd'), (1001, 'd'), (8001, 'dddddddd'),
3678(4002, 'dddd'), (3002, 'ddd'), (1002, 'd'), (8002, 'dddddddd');
3679insert into t3 values
3680(14000, 'dddd'), (13000, 'ddd'), (11000, 'd'), (18000, 'dddddddd'),
3681(14001, 'dddd'), (13001, 'ddd'), (11001, 'd'), (18001, 'dddddddd'),
3682(4002, 'dddd'), (3002, 'ddd'), (1002, 'd'), (8002, 'dddddddd');
3683insert into t4 values
3684(200, 'cc'), (600, 'cccccc'), (300, 'ccc'), (500, 'ccccc'),
3685(201, 'cc'), (601, 'cccccc'), (301, 'ccc'), (501, 'ccccc'),
3686(202, 'cc'), (602, 'cccccc'), (302, 'ccc'), (502, 'ccccc');
3687insert into t4 values
3688(1200, 'cc'), (1600, 'cccccc'), (1300, 'ccc'), (1500, 'ccccc'),
3689(1201, 'cc'), (1601, 'cccccc'), (1301, 'ccc'), (1501, 'ccccc'),
3690(1202, 'cc'), (1602, 'cccccc'), (1302, 'ccc'), (1502, 'ccccc');
3691analyze table t2,t3,t4;
3692set join_cache_level=1;
3693explain
3694select t1.a, t1.b, t1.c, t1.d, t2.e, t3.f, t4.g from t1,t2,t3,t4
3695where t2.b=t1.b and t3.d=t1.d and t4.c=t1.c;
3696id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
36971	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	7	Using where
36981	SIMPLE	t2	ref	idx	idx	5	test.t1.b	1
36991	SIMPLE	t4	ref	idx	idx	5	test.t1.c	1
37001	SIMPLE	t3	ref	idx	idx	5	test.t1.d	1
3701select t1.a, t1.b, t1.c, t1.d, t2.e, t3.f, t4.g from t1,t2,t3,t4
3702where t2.b=t1.b and t3.d=t1.d and t4.c=t1.c;
3703a	b	c	d	e	f	g
37043	30	300	3000	bbb	ddd	ccc
3705set join_cache_level=6;
3706explain
3707select t1.a, t1.b, t1.c, t1.d, t2.e, t3.f, t4.g from t1,t2,t3,t4
3708where t2.b=t1.b and t3.d=t1.d and t4.c=t1.c;
3709id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
37101	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	7	Using where
37111	SIMPLE	t2	ref	idx	idx	5	test.t1.b	1	Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
37121	SIMPLE	t4	ref	idx	idx	5	test.t1.c	1	Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
37131	SIMPLE	t3	ref	idx	idx	5	test.t1.d	1	Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
3714select t1.a, t1.b, t1.c, t1.d, t2.e, t3.f, t4.g from t1,t2,t3,t4
3715where t2.b=t1.b and t3.d=t1.d and t4.c=t1.c;
3716a	b	c	d	e	f	g
37173	30	300	3000	bbb	ddd	ccc
3718set join_cache_level=@save_join_cache_level;
3719drop table t1,t2,t3,t4;
3720#
3721# Bug #44250: Corruption of linked join buffers when using BKA
3722#
3723CREATE TABLE t1 (
3724id1 bigint(20) DEFAULT NULL,
3725id2 bigint(20) DEFAULT NULL,
3726id3 bigint(20) DEFAULT NULL,
3727num1 bigint(20) DEFAULT NULL,
3728num2 int(11) DEFAULT NULL,
3729num3 bigint(20) DEFAULT NULL
3730);
3731CREATE TABLE t2 (
3732id3 bigint(20) NOT NULL DEFAULT '0',
3733id4 bigint(20) DEFAULT NULL,
3734enum1 enum('Enabled','Disabled','Paused') DEFAULT NULL,
3735PRIMARY KEY (id3)
3736);
3737CREATE TABLE t3 (
3738id4 bigint(20) NOT NULL DEFAULT '0',
3739text1 text,
3740PRIMARY KEY (id4)
3741);
3742CREATE TABLE t4 (
3743id2 bigint(20) NOT NULL DEFAULT '0',
3744dummy int(11) DEFAULT '0',
3745PRIMARY KEY (id2)
3746);
3747CREATE TABLE t5 (
3748id1 bigint(20) NOT NULL DEFAULT '0',
3749id2 bigint(20) NOT NULL DEFAULT '0',
3750enum2 enum('Active','Deleted','Paused') DEFAULT NULL,
3751PRIMARY KEY (id1,id2)
3752);
3753set join_cache_level=8;
3754set join_buffer_size=2048;
3755EXPLAIN
3756SELECT STRAIGHT_JOIN t1.id1, t1.num3, t3.text1, t3.id4, t2.id3, t4.dummy
3757FROM t1 JOIN  t2 JOIN  t3 JOIN  t4 JOIN  t5
3758WHERE t1.id1=t5.id1 AND t1.id2=t5.id2 and  t4.id2=t1.id2 AND
3759t5.enum2='Active' AND t3.id4=t2.id4 AND t2.id3=t1.id3 AND t3.text1<'D';
3760id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
37611	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	349	Using where
37621	SIMPLE	t2	eq_ref	PRIMARY	PRIMARY	8	test.t1.id3	1	Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
37631	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	8	test.t2.id4	1	Using where; Using join buffer (incremental, BKAH join); Key-ordered Rowid-ordered scan
37641	SIMPLE	t4	eq_ref	PRIMARY	PRIMARY	8	test.t1.id2	1	Using join buffer (incremental, BKAH join); Key-ordered Rowid-ordered scan
37651	SIMPLE	t5	eq_ref	PRIMARY	PRIMARY	16	test.t1.id1,test.t1.id2	1	Using where; Using join buffer (incremental, BKAH join); Key-ordered Rowid-ordered scan
3766SELECT STRAIGHT_JOIN t1.id1, t1.num3, t3.text1, t3.id4, t2.id3, t4.dummy
3767FROM t1 JOIN  t2 JOIN  t3 JOIN  t4 JOIN  t5
3768WHERE t1.id1=t5.id1 AND t1.id2=t5.id2 and  t4.id2=t1.id2 AND
3769t5.enum2='Active' AND t3.id4=t2.id4 AND t2.id3=t1.id3 AND t3.text1<'D';
3770id1	num3	text1	id4	id3	dummy
3771228172702	14	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA	2567095402	2667134182	0
3772228172702	134	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA	2567095402	2667134182	0
3773228172702	15	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA	2567095402	2667134182	0
3774228172702	3	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA	2567095402	2667134182	0
3775228808822	61	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	826928662	935693782	0
3776228808822	13	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	826928662	935693782	0
3777228808822	60	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	826928662	935693782	0
3778228808822	13	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	826928662	935693782	0
3779228808822	3	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	826928662	935693782	0
3780228808822	4	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	826928662	935693782	0
3781228808822	6	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	826928662	935693782	0
3782228808822	18	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	826928662	935693782	0
3783228808822	1	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	826928662	935693782	0
3784228808822	3	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	826928662	935693782	0
3785228808822	17	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	826928662	935693782	0
3786228808822	50	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	826928662	935693782	0
3787228808822	4	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	826928662	935693782	0
3788228808822	89	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	2381969632	2482416112	0
3789228808822	19	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	2381969632	2482416112	0
3790228808822	9	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	2381969632	2482416112	0
3791228808822	84	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	2381969632	2482416112	0
3792228808822	14	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	2381969632	2482416112	0
3793228808822	1	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	2381969632	2482416112	0
3794228808822	10	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	2381969632	2482416112	0
3795228808822	26	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	2381969632	2482416112	0
3796228808822	4	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	2381969632	2482416112	0
3797228808822	3	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	2381969632	2482416112	0
3798228808822	1	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	2381969632	2482416112	0
3799228808822	3	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	2381969632	2482416112	0
3800228808822	28	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	2381969632	2482416112	0
3801228808822	62	CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC	2381969632	2482416112	0
3802set join_buffer_size=@save_join_buffer_size;
3803set join_cache_level=@save_join_cache_level;
3804DROP TABLE t1,t2,t3,t4,t5;
3805#
3806# Bug#45267: Incomplete check caused wrong result.
3807#
3808CREATE TABLE t1 (
3809`pk` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY
3810);
3811CREATE TABLE t3 (
3812`pk` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY
3813);
3814INSERT INTO t3 VALUES
3815(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),
3816(16),(17),(18),(19),(20);
3817CREATE TABLE t2 (
3818`pk` int(11) NOT NULL AUTO_INCREMENT,
3819`int_nokey` int(11) NOT NULL,
3820`time_key` time NOT NULL,
3821PRIMARY KEY (`pk`),
3822KEY `time_key` (`time_key`)
3823);
3824INSERT INTO t2 VALUES (10,9,'22:36:46'),(11,0,'08:46:46');
3825SELECT DISTINCT t1.`pk`
3826FROM t1 RIGHT JOIN t2 STRAIGHT_JOIN t3 ON t2.`int_nokey`  ON t2.`time_key`
3827GROUP BY 1;
3828pk
3829NULL
3830DROP TABLE IF EXISTS t1, t2, t3;
3831#
3832# Bug #46328: Use of aggregate function without GROUP BY clause
3833#             returns many rows (vs. one )
3834#
3835CREATE TABLE t1 (
3836int_key int(11) NOT NULL,
3837KEY int_key (int_key)
3838);
3839INSERT INTO t1 VALUES
3840(0),(2),(2),(2),(3),(4),(5),(5),(6),(6),(8),(8),(9),(9);
3841CREATE TABLE t2 (
3842int_key int(11) NOT NULL,
3843KEY int_key (int_key)
3844);
3845INSERT INTO t2 VALUES (2),(3);
3846
3847# The query shall return 1 record with a max value 9 and one of the
3848# int_key values inserted above (undefined which one). A changed
3849# execution plan may change the value in the second column
3850SELECT  MAX(t1.int_key), t1.int_key
3851FROM t1 STRAIGHT_JOIN t2
3852ORDER BY t1.int_key;
3853MAX(t1.int_key)	int_key
38549	0
3855
3856explain
3857SELECT  MAX(t1.int_key), t1.int_key
3858FROM t1 STRAIGHT_JOIN t2
3859ORDER BY t1.int_key;
3860id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
38611	SIMPLE	t1	index	NULL	int_key	4	NULL	14	Using index
38621	SIMPLE	t2	index	NULL	int_key	4	NULL	2	Using index; Using join buffer (flat, BNL join)
3863
3864DROP TABLE t1,t2;
3865SET join_cache_level=@save_join_cache_level;
3866#
3867# Regression test for
3868# Bug#46733 - NULL value not returned for aggregate on empty result
3869#             set w/ semijoin on
3870#
3871CREATE TABLE t1 (
3872i int(11) NOT NULL,
3873v varchar(1) DEFAULT NULL,
3874PRIMARY KEY (i)
3875);
3876INSERT INTO t1 VALUES (10,'a'),(11,'b'),(12,'c'),(13,'d');
3877CREATE TABLE t2 (
3878i int(11) NOT NULL,
3879v varchar(1) DEFAULT NULL,
3880PRIMARY KEY (i)
3881);
3882INSERT INTO t2 VALUES (1,'x'),(2,'y');
3883
3884SELECT MAX(t1.i)
3885FROM t1 JOIN t2 ON t2.v
3886ORDER BY t2.v;
3887MAX(t1.i)
3888NULL
3889Warnings:
3890Warning	1292	Truncated incorrect DOUBLE value: 'x'
3891Warning	1292	Truncated incorrect DOUBLE value: 'y'
3892
3893EXPLAIN
3894SELECT MAX(t1.i)
3895FROM t1 JOIN t2 ON t2.v
3896ORDER BY t2.v;
3897id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
38981	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	2	Using where
38991	SIMPLE	t1	index	NULL	PRIMARY	4	NULL	4	Using index; Using join buffer (flat, BNL join)
3900
3901DROP TABLE t1,t2;
3902#
3903# Bug #45092: join buffer contains two blob columns one of which is
3904#             used in the key employed to access the joined table
3905#
3906CREATE TABLE t1 (c1 int, c2 int, key (c2));
3907INSERT INTO t1 VALUES (1,1);
3908INSERT INTO t1 VALUES (2,2);
3909CREATE TABLE t2 (c1 text, c2 text);
3910INSERT INTO t2 VALUES('tt', 'uu');
3911INSERT INTO t2 VALUES('zzzz', 'xxxxxxxxx');
3912ANALYZE TABLE t1,t2;
3913set join_cache_level=6;
3914SELECT t1.*, t2.*, LENGTH(t2.c1), LENGTH(t2.c2) FROM t1,t2
3915WHERE t1.c2=LENGTH(t2.c2) and t1.c1=LENGTH(t2.c1);
3916c1	c2	c1	c2	LENGTH(t2.c1)	LENGTH(t2.c2)
39172	2	tt	uu	2	2
3918set join_cache_level=@save_join_cache_level;
3919DROP TABLE t1,t2;
3920#
3921# Bug #51092: linked join buffer is used for a 3-way cross join query
3922#             that selects only records of the first table
3923#
3924create table t1 (a int, b int);
3925insert into t1 values (1,1),(2,2);
3926create table t2 (a int, b int);
3927insert into t2 values (1,1),(2,2);
3928create table t3 (a int, b int);
3929insert into t3 values (1,1),(2,2);
3930set join_cache_level=1;
3931explain select t1.* from t1,t2,t3;
3932id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
39331	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2
39341	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	2	Using join buffer (flat, BNL join)
39351	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	2	Using join buffer (flat, BNL join)
3936select t1.* from t1,t2,t3;
3937a	b
39381	1
39392	2
39401	1
39412	2
39421	1
39432	2
39441	1
39452	2
3946set join_cache_level=2;
3947explain select t1.* from t1,t2,t3;
3948id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
39491	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2
39501	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	2	Using join buffer (flat, BNL join)
39511	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	2	Using join buffer (incremental, BNL join)
3952select t1.* from t1,t2,t3;
3953a	b
39541	1
39552	2
39561	1
39572	2
39581	1
39592	2
39601	1
39612	2
3962set join_cache_level=@save_join_cache_level;
3963drop table t1,t2,t3;
3964#
3965# Bug #52394:  using join buffer for 3 table join with ref access
3966# LP #623209: and no references to the columns of the middle table
3967#
3968set join_cache_level=6;
3969CREATE TABLE t1 (a int(11), b varchar(1));
3970INSERT INTO t1 VALUES (6,'r'),(27,'o');
3971CREATE TABLE t2(a int);
3972INSERT INTO t2 VALUES(1),(2),(3),(4),(5);
3973CREATE TABLE t3 (a int(11) primary key, b varchar(1));
3974INSERT INTO t3 VALUES
3975(14,'d'),(15,'z'),(16,'e'),(17,'h'),(18,'b'),(19,'s'),(20,'e'),
3976(21,'j'),(22,'e'),(23,'f'),(24,'v'),(25,'x'),(26,'m'),(27,'o');
3977EXPLAIN
3978SELECT t3.a FROM t1,t2,t3 WHERE t1.a = t3.a AND t1.b = t3.b;
3979id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
39801	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	Using where
39811	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	4	test.t1.a	1	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
39821	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	5	Using join buffer (incremental, BNL join)
3983SELECT t3.a FROM t1,t2,t3 WHERE t1.a = t3.a AND t1.b = t3.b;
3984a
398527
398627
398727
398827
398927
3990DROP TABLE t1,t2,t3;
3991set join_cache_level=@save_join_cache_level;
3992#
3993# Bug #51084: Batched key access crashes for SELECT with
3994#             derived table and LEFT JOIN
3995#
3996CREATE TABLE t1 (
3997carrier int,
3998id int PRIMARY KEY
3999);
4000INSERT INTO t1 VALUES (1,11),(1,12),(2,13);
4001CREATE TABLE t2 (
4002scan_date int,
4003package_id int
4004);
4005INSERT INTO t2 VALUES (2008,21),(2008,22);
4006CREATE TABLE t3 (
4007carrier int PRIMARY KEY,
4008id int
4009);
4010INSERT INTO t3 VALUES (1,31);
4011CREATE TABLE t4 (
4012carrier_id int,
4013INDEX carrier_id(carrier_id)
4014);
4015INSERT INTO t4 VALUES (31),(32);
4016SET join_cache_level=8;
4017SELECT COUNT(*)
4018FROM (t2 JOIN t1) LEFT JOIN (t3 JOIN t4 ON t3.id = t4.carrier_id)
4019ON t3.carrier = t1.carrier;
4020COUNT(*)
40216
4022EXPLAIN
4023SELECT COUNT(*)
4024FROM (t2 JOIN t1) LEFT JOIN (t3 JOIN t4 ON t3.id = t4.carrier_id)
4025ON t3.carrier = t1.carrier;
4026id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
40271	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	2
40281	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	Using join buffer (flat, BNL join)
40291	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	4	test.t1.carrier	1	Using where
40301	SIMPLE	t4	ref	carrier_id	carrier_id	5	test.t3.id	2	Using index
4031SET join_cache_level=@save_join_cache_level;
4032DROP TABLE t1,t2,t3,t4;
4033#
4034# Bug #52636: allowing JOINs on NULL values w/ join_cache_level = 5-8
4035#
4036CREATE TABLE t1 (b int);
4037INSERT INTO t1 VALUES (NULL),(3);
4038CREATE TABLE t2 (a int, b int, KEY (b));
4039INSERT INTO t2 VALUES
4040(100,NULL),(150,200),(50,150),(250,350),(180,210),(100,150),
4041(101,NULL),(151,200),(51,150),(251,350),(181,210),(101,150);
4042set join_cache_level = 5;
4043explain SELECT t2.a FROM t1 LEFT JOIN t2 ON t2.b  = t1.b;
4044id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
40451	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2
40461	SIMPLE	t2	ref	b	b	5	test.t1.b	2	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
4047SELECT t2.a FROM t1 LEFT JOIN t2 ON t2.b  = t1.b;
4048a
4049NULL
4050NULL
4051set join_cache_level = 8;
4052explain SELECT t2.a FROM t1 LEFT JOIN t2 ON t2.b  = t1.b;
4053id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
40541	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2
40551	SIMPLE	t2	ref	b	b	5	test.t1.b	2	Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
4056SELECT t2.a FROM t1 LEFT JOIN t2 ON t2.b  = t1.b;
4057a
4058NULL
4059NULL
4060delete from t1;
4061INSERT INTO t1 VALUES (NULL),(NULL);
4062set join_cache_level = 5;
4063explain SELECT t2.a FROM t1 LEFT JOIN t2 ON t2.b  = t1.b;
4064id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
40651	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2
40661	SIMPLE	t2	ref	b	b	5	test.t1.b	2	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
4067SELECT t2.a FROM t1 LEFT JOIN t2 ON t2.b  = t1.b;
4068a
4069NULL
4070NULL
4071DROP TABLE t1,t2;
4072CREATE TABLE t1 (b varchar(100));
4073INSERT INTO t1 VALUES (NULL),("some varchar");
4074CREATE TABLE t2 (a int, b varchar(100), KEY (b));
4075INSERT INTO t2 VALUES (100,NULL),(150,"varchar"),(200,NULL),(250,"long long varchar");
4076INSERT INTO t2 VALUES (100,NULL),(150,"long varchar"),(200,"varchar"),(250,"long long long varchar");
4077set join_cache_level = 5;
4078explain SELECT t2.a FROM t1 LEFT JOIN t2 ON t2.b  = t1.b;
4079id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
40801	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2
40811	SIMPLE	t2	ref	b	b	103	test.t1.b	2	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
4082SELECT t2.a FROM t1 LEFT JOIN t2 ON t2.b  = t1.b;
4083a
4084NULL
4085NULL
4086set join_cache_level = 8;
4087explain SELECT t2.a FROM t1 LEFT JOIN t2 ON t2.b  = t1.b;
4088id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
40891	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2
40901	SIMPLE	t2	ref	b	b	103	test.t1.b	2	Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
4091SELECT t2.a FROM t1 LEFT JOIN t2 ON t2.b  = t1.b;
4092a
4093NULL
4094NULL
4095set join_cache_level=@save_join_cache_level;
4096DROP TABLE t1,t2;
4097#
4098# Bug #54359: Extra rows with join_cache_level=7,8 and two joins
4099#             and multi-column index"
4100#
4101CREATE TABLE t1 (
4102pk int NOT NULL,
4103a int DEFAULT NULL,
4104b varchar(16) DEFAULT NULL,
4105c varchar(16) DEFAULT NULL,
4106INDEX idx (b,a))
4107;
4108INSERT INTO t1 VALUES (4,9,'k','k');
4109INSERT INTO t1 VALUES (12,5,'k','k');
4110set join_cache_level = 8;
4111EXPLAIN
4112SELECT t.a FROM t1 t, t1 s FORCE INDEX(idx)
4113WHERE s.pk AND s.a  >= t.pk AND  s.b  = t.c;
4114id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
41151	SIMPLE	t	ALL	NULL	NULL	NULL	NULL	2	Using where
41161	SIMPLE	s	ref	idx	idx	19	test.t.c	1	Using index condition(BKA); Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan
4117SELECT t.a FROM t1 t, t1 s FORCE INDEX(idx)
4118WHERE s.pk AND s.a  >= t.pk AND  s.b  = t.c;
4119a
41209
41219
4122set join_cache_level=@save_join_cache_level;
4123DROP TABLE t1;
4124#
4125# Bug #54235: Extra rows with join_cache_level=6,8 and two LEFT JOINs
4126#
4127CREATE TABLE t1 (a int);
4128CREATE TABLE t2 (a int);
4129CREATE TABLE t3 (a int);
4130CREATE TABLE t4 (a int);
4131INSERT INTO t1 VALUES (null), (2), (null), (1);
4132set join_cache_level = 6;
4133EXPLAIN
4134SELECT t1.a
4135FROM t1 LEFT JOIN (t2 LEFT JOIN t3 ON t2.a) ON 0
4136WHERE t1.a OR t3.a;
4137id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
41381	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	4
41391	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	0	Using where; Using join buffer (flat, BNL join)
41401	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	0	Using where; Using join buffer (incremental, BNL join)
4141SELECT t1.a
4142FROM t1 LEFT JOIN (t2 LEFT JOIN t3 ON t2.a) ON 0
4143WHERE t1.a OR t3.a;
4144a
41452
41461
4147EXPLAIN
4148SELECT t1.a
4149FROM t1 LEFT JOIN (t2 LEFT JOIN (t3 LEFT JOIN t4 ON 1) ON t2.a) ON 0
4150WHERE t1.a OR t4.a;
4151id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
41521	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	4
41531	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	0	Using where; Using join buffer (flat, BNL join)
41541	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	0	Using where; Using join buffer (incremental, BNL join)
41551	SIMPLE	t4	ALL	NULL	NULL	NULL	NULL	0	Using where; Using join buffer (incremental, BNL join)
4156SELECT t1.a
4157FROM t1 LEFT JOIN (t2 LEFT JOIN (t3 LEFT JOIN t4 ON 1) ON t2.a) ON 0
4158WHERE t1.a OR t4.a;
4159a
41602
41611
4162set join_cache_level=@save_join_cache_level;
4163DROP TABLE t1,t2,t3,t4;
4164#
4165# Bug #663840: Memory overwrite causing crash with hash join
4166#
4167SET SESSION join_cache_level=3;
4168SET SESSION join_buffer_size=100;
4169Warnings:
4170Warning	1292	Truncated incorrect join_buffer_size value: '100'
4171CREATE TABLE t3 (
4172i int NOT NULL,
4173j int NOT NULL,
4174d date NOT NULL,
4175t time NOT NULL,
4176v varchar(1) NOT NULL,
4177u varchar(1) NOT NULL,
4178INDEX idx (v)
4179)  COLLATE=latin1_bin;
4180INSERT INTO t3 VALUES
4181(3,8,'2008-12-04','00:00:00','v','v'), (3,8,'2009-03-28','00:00:00','f','f'),
4182(3,5,'1900-01-01','00:55:47','v','v'), (2,8,'2009-10-02','00:00:00','s','s'),
4183(1,8,'1900-01-01','20:51:59','a','a'), (0,6,'2008-06-04','09:47:27','p','p'),
4184(8,7,'2009-01-13','21:58:29','z','z'), (5,2,'1900-01-01','22:45:53','a','a'),
4185(9,5,'2008-01-28','14:06:48','h','h'), (5,7,'2004-09-18','22:17:16','h','h'),
4186(4,2,'2006-10-14','14:59:37','v','v'), (2,9,'1900-01-01','23:37:40','v','v'),
4187(33,142,'2000-11-28','14:14:01','b','b'), (5,3,'2008-04-04','02:54:19','y','y'),
4188(1,0,'2002-07-13','06:34:26','v','v'), (9,3,'2003-01-03','18:07:38','m','m'),
4189(1,5,'2006-04-02','13:55:23','z','z'), (3,9,'2006-10-19','20:32:28','n','n'),
4190(8,1,'2005-06-08','11:57:44','d','d'), (231,107,'2006-12-26','03:10:35','a','a');
4191INSERT INTO t3 VALUES
4192(103,108,'2008-12-04','00:00:00','a','v'), (103,108,'2009-03-28','00:00:00','b','f'),
4193(103,105,'1900-01-01','00:55:47','c','v'), (102,108,'2009-10-02','00:00:00','d','s'),
4194(100,108,'1900-01-01','20:51:59','e','a'), (100,106,'2008-06-04','09:47:27','f','p'),
4195(108,107,'2009-01-13','21:58:29','g','z'), (105,102,'1900-01-01','22:45:53','h','a'),
4196(109,105,'2008-01-28','14:06:48','i','h'), (105,107,'2004-09-18','22:17:16','j','h'),
4197(104,102,'2006-10-14','14:59:37','k','v'), (102,109,'1900-01-01','23:37:40','l','v'),
4198(1033,1142,'2000-11-28','14:14:01','m','b'), (105,103,'2008-04-04','02:54:19','n','y'),
4199(100,100,'2002-07-13','06:34:26','o','v'), (109,103,'2003-01-03','18:07:38','p','m'),
4200(100,105,'2006-04-02','13:55:23','q','z'), (103,109,'2006-10-19','20:32:28','s','n'),
4201(108,100,'2005-06-08','11:57:44','t','d'), (1231,1107,'2006-12-26','03:10:35','v','a');
4202CREATE TABLE t1 SELECT * FROM t3;
4203DELETE FROM t1 WHERE i > 8;
4204CREATE TABLE t2 SELECT * FROM t3;
4205DELETE FROM t2 WHERE j > 10;
4206EXPLAIN
4207SELECT t1.i, t1.d,  t1.v, t2.i, t2.d, t2.t, t2.v FROM t1,t2,t3
4208WHERE t3.u <='a' AND t2.j < 5 AND t3.v = t2.u;
4209id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
42101	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	16
42111	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	18	Using where; Using join buffer (flat, BNL join)
42121	SIMPLE	t3	hash_ALL	idx	#hash#idx	3	test.t2.u	40	Using where; Using join buffer (flat, BNLH join)
4213SELECT t1.i, t1.d,  t1.v, t2.i, t2.d, t2.t, t2.v FROM t1,t2,t3
4214WHERE t3.u <='a' AND t2.j < 5 AND t3.v = t2.u;
4215i	d	v	i	d	t	v
42160	2008-06-04	p	1	2002-07-13	06:34:26	v
42170	2008-06-04	p	4	2006-10-14	14:59:37	v
42180	2008-06-04	p	5	1900-01-01	22:45:53	a
42190	2008-06-04	p	5	1900-01-01	22:45:53	a
42200	2008-06-04	p	5	1900-01-01	22:45:53	a
42211	1900-01-01	a	1	2002-07-13	06:34:26	v
42221	1900-01-01	a	4	2006-10-14	14:59:37	v
42231	1900-01-01	a	5	1900-01-01	22:45:53	a
42241	1900-01-01	a	5	1900-01-01	22:45:53	a
42251	1900-01-01	a	5	1900-01-01	22:45:53	a
42261	2002-07-13	v	1	2002-07-13	06:34:26	v
42271	2002-07-13	v	4	2006-10-14	14:59:37	v
42281	2002-07-13	v	5	1900-01-01	22:45:53	a
42291	2002-07-13	v	5	1900-01-01	22:45:53	a
42301	2002-07-13	v	5	1900-01-01	22:45:53	a
42311	2006-04-02	z	1	2002-07-13	06:34:26	v
42321	2006-04-02	z	4	2006-10-14	14:59:37	v
42331	2006-04-02	z	5	1900-01-01	22:45:53	a
42341	2006-04-02	z	5	1900-01-01	22:45:53	a
42351	2006-04-02	z	5	1900-01-01	22:45:53	a
42362	1900-01-01	v	1	2002-07-13	06:34:26	v
42372	1900-01-01	v	4	2006-10-14	14:59:37	v
42382	1900-01-01	v	5	1900-01-01	22:45:53	a
42392	1900-01-01	v	5	1900-01-01	22:45:53	a
42402	1900-01-01	v	5	1900-01-01	22:45:53	a
42412	2009-10-02	s	1	2002-07-13	06:34:26	v
42422	2009-10-02	s	4	2006-10-14	14:59:37	v
42432	2009-10-02	s	5	1900-01-01	22:45:53	a
42442	2009-10-02	s	5	1900-01-01	22:45:53	a
42452	2009-10-02	s	5	1900-01-01	22:45:53	a
42463	1900-01-01	v	1	2002-07-13	06:34:26	v
42473	1900-01-01	v	4	2006-10-14	14:59:37	v
42483	1900-01-01	v	5	1900-01-01	22:45:53	a
42493	1900-01-01	v	5	1900-01-01	22:45:53	a
42503	1900-01-01	v	5	1900-01-01	22:45:53	a
42513	2006-10-19	n	1	2002-07-13	06:34:26	v
42523	2006-10-19	n	4	2006-10-14	14:59:37	v
42533	2006-10-19	n	5	1900-01-01	22:45:53	a
42543	2006-10-19	n	5	1900-01-01	22:45:53	a
42553	2006-10-19	n	5	1900-01-01	22:45:53	a
42563	2008-12-04	v	1	2002-07-13	06:34:26	v
42573	2008-12-04	v	4	2006-10-14	14:59:37	v
42583	2008-12-04	v	5	1900-01-01	22:45:53	a
42593	2008-12-04	v	5	1900-01-01	22:45:53	a
42603	2008-12-04	v	5	1900-01-01	22:45:53	a
42613	2009-03-28	f	1	2002-07-13	06:34:26	v
42623	2009-03-28	f	4	2006-10-14	14:59:37	v
42633	2009-03-28	f	5	1900-01-01	22:45:53	a
42643	2009-03-28	f	5	1900-01-01	22:45:53	a
42653	2009-03-28	f	5	1900-01-01	22:45:53	a
42664	2006-10-14	v	1	2002-07-13	06:34:26	v
42674	2006-10-14	v	4	2006-10-14	14:59:37	v
42684	2006-10-14	v	5	1900-01-01	22:45:53	a
42694	2006-10-14	v	5	1900-01-01	22:45:53	a
42704	2006-10-14	v	5	1900-01-01	22:45:53	a
42715	1900-01-01	a	1	2002-07-13	06:34:26	v
42725	1900-01-01	a	4	2006-10-14	14:59:37	v
42735	1900-01-01	a	5	1900-01-01	22:45:53	a
42745	1900-01-01	a	5	1900-01-01	22:45:53	a
42755	1900-01-01	a	5	1900-01-01	22:45:53	a
42765	2004-09-18	h	1	2002-07-13	06:34:26	v
42775	2004-09-18	h	4	2006-10-14	14:59:37	v
42785	2004-09-18	h	5	1900-01-01	22:45:53	a
42795	2004-09-18	h	5	1900-01-01	22:45:53	a
42805	2004-09-18	h	5	1900-01-01	22:45:53	a
42815	2008-04-04	y	1	2002-07-13	06:34:26	v
42825	2008-04-04	y	4	2006-10-14	14:59:37	v
42835	2008-04-04	y	5	1900-01-01	22:45:53	a
42845	2008-04-04	y	5	1900-01-01	22:45:53	a
42855	2008-04-04	y	5	1900-01-01	22:45:53	a
42868	2005-06-08	d	1	2002-07-13	06:34:26	v
42878	2005-06-08	d	4	2006-10-14	14:59:37	v
42888	2005-06-08	d	5	1900-01-01	22:45:53	a
42898	2005-06-08	d	5	1900-01-01	22:45:53	a
42908	2005-06-08	d	5	1900-01-01	22:45:53	a
42918	2009-01-13	z	1	2002-07-13	06:34:26	v
42928	2009-01-13	z	4	2006-10-14	14:59:37	v
42938	2009-01-13	z	5	1900-01-01	22:45:53	a
42948	2009-01-13	z	5	1900-01-01	22:45:53	a
42958	2009-01-13	z	5	1900-01-01	22:45:53	a
4296DROP TABLE t1,t2,t3;
4297SET SESSION join_cache_level=@save_join_cache_level;
4298SET SESSION join_buffer_size=@save_join_buffer_size;
4299#
4300# Bug #664508: 'Simple' GROUP BY + ORDER BY
4301#              when join buffers are used
4302#
4303CREATE TABLE t1 (
4304pk int NOT NULL, i int NOT NULL, v  varchar(1) NOT NULL,
4305PRIMARY KEY (pk), INDEX idx1(i), INDEX idx2 (v,i)
4306) COLLATE latin1_bin;
4307INSERT INTO t1 VALUES
4308(10,8,'v'), (11,8,'f'), (13,8,'s'), (14,8,'a'),
4309(15,6,'p'), (16,7,'z'), (17,2,'a'), (18,5,'h'), (19,7,'h'),
4310(25,3,'m'), (26,5,'a'), (27,9,'n'), (28,1,'d'), (29,107,'a');
4311INSERT INTO t1 VALUES
4312(110,8,'x'), (111,8,'y'), (112,5,'v'), (113,8,'z'), (114,8,'i'),
4313(115,6,'j'), (116,7,'t'), (117,2,'b'), (118,5,'j'), (119,7,'w'),
4314(125,3,'q'), (126,5,'o'), (127,9,'n'), (128,1,'e'), (129,107,'c');
4315INSERT INTO t1 VALUES
4316(210,8,'b'), (211,8,'c'), (212,5,'d'), (213,8,'e'), (214,8,'g'),
4317(215,6,'f'), (216,7,'h'), (217,2,'i'), (218,5,'j'), (219,7,'k'),
4318(225,3,'l'), (226,5,'m'), (227,9,'n'), (228,1,'o'), (229,107,'p');
4319CREATE TABLE t2 (
4320pk int NOT NULL, i int NOT NULL, v varchar(1) NOT NULL,
4321PRIMARY KEY (pk), INDEX idx1(i), INDEX idx2(v,i)
4322) COLLATE latin1_bin;
4323INSERT INTO t2 VALUES
4324(10,8,'v'), (11,8,'f'), (12,5,'v'), (13,8,'s'), (14,8,'a'),
4325(15,6,'p'), (16,7,'z'), (17,2,'a'), (18,5,'h'), (19,7,'h'),
4326(20,2,'v'), (21,9,'v'), (22,142,'b'), (23,3,'y'), (24,0,'v'),
4327(25,3,'m'), (26,5,'b'), (27,9,'n'), (28,1,'d'), (29,107,'a');
4328CREATE TABLE t3 (
4329pk int NOT NULL, i int NOT NULL,  v varchar(1) NOT NULL,
4330PRIMARY KEY (pk), INDEX idx1(i), INDEX idx2(v,i)
4331) COLLATE latin1_bin;
4332INSERT INTO t3 VALUES
4333(1,9,'x'), (2,5,'g'), (3,1,'o'), (4,0,'g'), (5,1,'v'),
4334(6,190,'m'), (7,6,'x'), (8,3,'c'), (9,4,'z'), (10,3,'i'),
4335(11,186,'x'), (12,1,'g'), (13,8,'q'), (14,226,'m'), (15,133,'p'),
4336(16,6,'e'), (17,3,'t'), (18,8,'j'), (19,5,'h'), (20,7,'w');
4337SET SESSION join_cache_level=1;
4338EXPLAIN
4339SELECT t2.v FROM t1, t2, t3
4340WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
4341GROUP BY t2.v ORDER BY t1.pk,t2.v;
4342id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
43431	SIMPLE	t2	index	idx1	idx2	7	NULL	20	Using index; Using temporary; Using filesort
43441	SIMPLE	t3	eq_ref	PRIMARY,idx2	PRIMARY	4	test.t2.i	1	Using where
43451	SIMPLE	t1	ref	idx2	idx2	3	test.t3.v	5	Using where
4346SELECT t2.v FROM t1, t2, t3
4347WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
4348GROUP BY t2.v ORDER BY t1.pk,t2.v;
4349v
4350b
4351h
4352n
4353v
4354p
4355EXPLAIN
4356SELECT t2.v FROM t1, t2, t3
4357WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
4358GROUP BY t2.v ORDER BY t1.pk,t2.v;
4359id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
43601	SIMPLE	t2	index	idx1	idx2	7	NULL	20	Using index; Using temporary; Using filesort
43611	SIMPLE	t3	eq_ref	PRIMARY,idx2	PRIMARY	4	test.t2.i	1	Using where
43621	SIMPLE	t1	ref	idx2	idx2	3	test.t3.v	5	Using where
4363SELECT t2.v FROM t1, t2, t3
4364WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
4365GROUP BY t2.v ORDER BY t1.pk,t2.v;
4366v
4367b
4368h
4369n
4370v
4371p
4372SET SESSION join_cache_level=6;
4373EXPLAIN
4374SELECT t2.v FROM t1, t2, t3
4375WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
4376GROUP BY t2.v ORDER BY t1.pk,t2.v;
4377id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
43781	SIMPLE	t2	index	idx1	idx2	7	NULL	20	Using index; Using temporary; Using filesort
43791	SIMPLE	t3	eq_ref	PRIMARY,idx2	PRIMARY	4	test.t2.i	1	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
43801	SIMPLE	t1	ref	idx2	idx2	3	test.t3.v	5	Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
4381SELECT t2.v FROM t1, t2, t3
4382WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
4383GROUP BY t2.v ORDER BY t1.pk,t2.v;
4384v
4385b
4386h
4387n
4388v
4389p
4390EXPLAIN
4391SELECT t2.v FROM t1, t2, t3
4392WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
4393GROUP BY t2.v ORDER BY t1.pk,t2.v;
4394id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
43951	SIMPLE	t2	index	idx1	idx2	7	NULL	20	Using index; Using temporary; Using filesort
43961	SIMPLE	t3	eq_ref	PRIMARY,idx2	PRIMARY	4	test.t2.i	1	Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
43971	SIMPLE	t1	ref	idx2	idx2	3	test.t3.v	5	Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
4398SELECT t2.v FROM t1, t2, t3
4399WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
4400GROUP BY t2.v ORDER BY t1.pk,t2.v;
4401v
4402b
4403h
4404n
4405v
4406p
4407SET SESSION join_cache_level=4;
4408EXPLAIN
4409SELECT t2.v FROM t1, t2, t3
4410WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
4411GROUP BY t2.v ORDER BY t1.pk,t2.v;
4412id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
44131	SIMPLE	t2	index	idx1	idx2	7	NULL	20	Using index; Using temporary; Using filesort
44141	SIMPLE	t3	hash_ALL	PRIMARY,idx2	#hash#PRIMARY	4	test.t2.i	20	Using where; Using join buffer (flat, BNLH join)
44151	SIMPLE	t1	hash_ALL	idx2	#hash#idx2	3	test.t3.v	44	Using where; Using join buffer (incremental, BNLH join)
4416SELECT t2.v FROM t1, t2, t3
4417WHERE t3.v <> t2.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
4418GROUP BY t2.v ORDER BY t1.pk,t2.v;
4419v
4420b
4421h
4422n
4423v
4424p
4425EXPLAIN
4426SELECT t2.v FROM t1, t2, t3
4427WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
4428GROUP BY t2.v ORDER BY t1.pk,t2.v;
4429id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
44301	SIMPLE	t2	index	idx1	idx2	7	NULL	20	Using index; Using temporary; Using filesort
44311	SIMPLE	t3	hash_ALL	PRIMARY,idx2	#hash#PRIMARY	4	test.t2.i	20	Using where; Using join buffer (flat, BNLH join)
44321	SIMPLE	t1	hash_ALL	idx2	#hash#idx2	3	test.t3.v	44	Using where; Using join buffer (incremental, BNLH join)
4433SELECT t2.v FROM t1, t2, t3
4434WHERE t2.v <> t3.v AND t3.pk = t2.i AND t1.v = t3.v AND t1.pk*2<100
4435GROUP BY t2.v ORDER BY t1.pk,t2.v;
4436v
4437b
4438h
4439n
4440v
4441p
4442DROP TABLE t1,t2,t3;
4443SET SESSION join_cache_level=@save_join_cache_level;
4444#
4445# Bug #668290: hash join with non-binary collations
4446#
4447CREATE TABLE t1 (
4448i int DEFAULT NULL,
4449cl varchar(10) CHARACTER SET latin1 DEFAULT NULL,
4450cu varchar(10) CHARACTER SET utf8 DEFAULT NULL,
4451INDEX cl (cl),
4452INDEX cu (cu)
4453);
4454INSERT INTO t1 VALUES
4455(650903552,'cmxffkpsel','z'), (535298048,'tvtjrcmxff','y'),
4456(1626865664,'when','for'), (39649280,'rcvljitvtj','ercvljitvt'),
4457(792068096,'ttercvljit','jttercvlji');
4458INSERT INTO t1 SELECT * FROM t1;
4459CREATE TABLE t2 (
4460cu varchar(10) CHARACTER SET utf8 DEFAULT NULL,
4461i int DEFAULT NULL,
4462cl varchar(10) CHARACTER SET latin1 DEFAULT NULL,
4463INDEX cu (cu),
4464INDEX cl (cl)
4465);
4466INSERT INTO t2 VALUES
4467('g',7,'like'), ('fujttercvl',6,'y'),
4468('s',2,'e'), ('didn\'t',0,'v'),
4469  ('gvdrodpedk',8,'chogvdrodp'), ('jichogvdro',7,'will');
4470EXPLAIN
4471SELECT t2.i FROM t1,t2 WHERE t1.cu = t2.cl ;
4472id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
44731	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	6
44741	SIMPLE	t1	ref	cu	cu	33	func	2	Using where; Using index
4475SELECT t2.i FROM t1,t2 WHERE t1.cu = t2.cl ;
4476i
44776
44786
4479SET SESSION join_cache_level = 4;
4480EXPLAIN
4481SELECT t2.i FROM t1,t2 WHERE t1.cu = t2.cl ;
4482id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
44831	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	6
44841	SIMPLE	t1	hash_index	cu	#hash#cu:cu	33:33	func	10	Using where; Using index; Using join buffer (flat, BNLH join)
4485SELECT t2.i FROM t1,t2 WHERE t1.cu = t2.cl ;
4486i
44876
44886
4489SET SESSION join_cache_level=@save_join_cache_level;
4490DROP TABLE t1,t2;
4491#
4492# Bug #669382: hash join using a ref with constant key parts
4493#
4494CREATE TABLE t1 (a int);
4495INSERT INTO t1 VALUES
4496(9), (11), (7), (8), (4), (1), (12), (3), (5);
4497INSERT INTO t1 SELECT * FROM t1;
4498INSERT INTO t1 SELECT * FROM t1;
4499CREATE TABLE t2 (a int, b int, c int, INDEX idx (a,b));
4500INSERT INTO t2 VALUES
4501(8, 80, 800), (1, 10, 100), (1, 11, 101), (3, 30, 300),
4502(1, 12, 102), (8, 81, 801), (7, 70, 700), (12, 120, 1200),
4503(8, 82, 802), (1, 13, 103), (1, 14, 104), (3, 31, 301),
4504(1, 15, 105), (8, 83, 803), (7, 71, 701);
4505SET SESSION join_cache_level = 4;
4506SET SESSION join_buffer_size = 256;
4507EXPLAIN
4508SELECT t1.a, t2.c FROM t1,t2 WHERE t1.a=t2.a AND t2.b=99;
4509id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
45101	SIMPLE	t2	ALL	idx	NULL	NULL	NULL	15	Using where
45111	SIMPLE	t1	hash_ALL	NULL	#hash#$hj	5	test.t2.a	36	Using where; Using join buffer (flat, BNLH join)
4512SELECT t1.a, t2.c FROM t1,t2 WHERE t1.a=t2.a AND t2.b=99;
4513a	c
4514SET SESSION join_cache_level=@save_join_cache_level;
4515SET SESSION join_buffer_size=@save_join_buffer_size;
4516DROP TABLE t1,t2;
4517#
4518# Bug #671901: hash join using a ref to a varchar field
4519#
4520CREATE TABLE t1 (
4521v varchar(10) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL,
4522i int  DEFAULT NULL
4523);
4524INSERT INTO t1 VALUES
4525('k',8), ('abcdefjh',-575340544), ('f',77), ('because', 2), ('f',-517472256),
4526('abcdefjhj',5), ('z',7);
4527CREATE TABLE t2 (
4528v varchar(10) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL,
4529i int DEFAULT NULL,
4530INDEX idx (v)
4531);
4532INSERT INTO t2 VALUES
4533('did',5), ('was',-1631322112), ('are',3), ('abcdefjhjk',3),
4534('abcdefjhjk',4), ('tell',-824573952), ('t',0),('v',-1711013888),
4535('abcdefjhjk',1015414784), ('or',4), ('now',0), ('abcdefjhjk',-32702464),
4536('abcdefjhjk',4), ('time',1078394880), ('f',4), ('m',-1845559296),
4537('ff', 5), ('abcdefjhjk',-1074397184);
4538INSERT INTO t2 VALUES
4539('dig',5), ('were',-1631322112), ('is',3), ('abcdefjhjl',3),
4540('abcdefjh',4), ('told',-824573952), ('tt',0),('vv',-1711013888),
4541('abcdefjhjj',1015414784), ('and',4), ('here',0), ('abcdefjhjm',-32702464),
4542('abcdefjhji',4), ('space',1078394880), ('fs',4), ('mn',-1845559296),
4543('fq', 5), ('abcdefjhjp',-1074397184);
4544EXPLAIN
4545SELECT t1.v,t2.i FROM t1,t2 WHERE t2.v = t1.v;
4546id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
45471	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	7	Using where
45481	SIMPLE	t2	ref	idx	idx	13	test.t1.v	3
4549SELECT t1.v,t2.i FROM t1,t2 WHERE t2.v = t1.v;
4550v	i
4551abcdefjh	4
4552f	4
4553f	4
4554EXPLAIN
4555SELECT t1.v,t2.i FROM t1,t2 WHERE t2.v = concat(t1.v, t1.v);
4556id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
45571	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	7
45581	SIMPLE	t2	ref	idx	idx	13	func	3	Using index condition
4559SELECT t1.v,t2.i FROM t1,t2 WHERE t2.v = concat(t1.v, t1.v);
4560v	i
4561f	5
4562f	5
4563SET SESSION join_cache_level = 4;
4564EXPLAIN
4565SELECT t1.v,t2.i FROM t1,t2 WHERE t2.v = t1.v;
4566id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
45671	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	7	Using where
45681	SIMPLE	t2	hash_ALL	idx	#hash#idx	13	test.t1.v	36	Using join buffer (flat, BNLH join)
4569SELECT t1.v,t2.i FROM t1,t2 WHERE t2.v = t1.v;
4570v	i
4571f	4
4572f	4
4573abcdefjh	4
4574EXPLAIN
4575SELECT t1.v,t2.i FROM t1,t2 WHERE t2.v = concat(t1.v, t1.v);
4576id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
45771	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	7
45781	SIMPLE	t2	hash_ALL	idx	#hash#idx	13	func	36	Using where; Using join buffer (flat, BNLH join)
4579SELECT t1.v,t2.i FROM t1,t2 WHERE t2.v = concat(t1.v, t1.v);
4580v	i
4581f	5
4582f	5
4583SET SESSION join_cache_level=@save_join_cache_level;
4584DROP TABLE t1,t2;
4585# Bug #672497: 3 way join with tiny incremental join buffer with
4586#              and a ref access from the first table
4587#
4588CREATE TABLE t1 (
4589pk int PRIMARY KEY,
4590v varchar(10) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL,
4591INDEX idx (v)
4592);
4593INSERT INTO t1 VALUES
4594(1,'abcdefjhjk'), (2,'i'),(3,'abcdefjhjk'), (4,'well'), (5,'abcdefjhjk'),
4595(6,'abcdefjhjk'), (7,'that');
4596CREATE TABLE t2 (
4597pk int PRIMARY KEY,
4598i int DEFAULT NULL,
4599v varchar(1000) CHARACTER SET latin1 COLLATE latin1_bin DEFAULT NULL,
4600INDEX idx (v)
4601);
4602INSERT INTO t2 VALUES
4603(1,6,'yes'), (2,NULL,'will'), (3,NULL,'o'), (4,NULL,'k'), (5,NULL,'she'),
4604(6,-1450835968,'abcdefjhjkl'), (7,-975831040,'abcdefjhjkl'), (8,NULL,'z'),
4605(10,-343932928,'t'),
4606(11,6,'yes'), (12,NULL,'will'), (13,NULL,'o'), (14,NULL,'k'), (15,NULL,'she'),
4607(16,-1450835968,'abcdefjhjkl'), (17,-975831040,'abcdefjhjkl'), (18,NULL,'z'),
4608(19,-343932928,'t');
4609INSERT INTO t2 VALUES
4610(101,6,'yes'), (102,NULL,'will'), (103,NULL,'o'), (104,NULL,'k'), (105,NULL,'she'),
4611(106,-1450835968,'abcdefjhjkl'), (107,-975831040,'abcdefjhjkl'), (108,NULL,'z'),
4612(100,-343932928,'t'),
4613(111,6,'yes'), (112,NULL,'will'), (113,NULL,'o'), (114,NULL,'k'), (115,NULL,'she'),
4614(116,-1450835968,'abcdefjhjkl'), (117,-975831040,'abcdefjhjkl'), (118,NULL,'z'),
4615(119,-343932928,'t');
4616CREATE TABLE t3 (
4617pk int NOT NULL PRIMARY KEY,
4618i int,
4619v varchar(1024) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
4620INDEX idx (v(333))
4621);
4622INSERT INTO t3 VALUES
4623(1,7,'abcdefjhjkl'),(2,6,'y'), (3,NULL,'to'),(4,7,'n'),(5,7,'look'), (6,NULL,'all'),
4624(7,1443168256,'c'), (8,1427046400,'right'),
4625(11,7,'abcdefjhjkl'), (12,6,'y'), (13,NULL,'to'), (14,7,'n'), (15,7,'look'),
4626(16,NULL,'all'), (17,1443168256,'c'), (18,1427046400,'right'),
4627(21,7,'abcdefjhjkl'), (22,6,'y'), (23,NULL,'to'), (24,7,'n'), (25,7,'look'),
4628(26,NULL,'all'), (27,1443168256,'c'), (28,1427046400,'right'),
4629(31,7,'abcdefjhjkl'), (32,6,'y'), (33,NULL,'to'), (34,7,'n'), (35,7,'look'),
4630(36,NULL,'all'), (37,1443168256,'c'), (38,1427046400,'right');
4631INSERT INTO t3 VALUES
4632(101,7,'abcdefjhjkl'),(102,6,'y'), (103,NULL,'to'),(104,7,'n'),(105,7,'look'),
4633(106,NULL,'all'), (107,1443168256,'c'), (108,1427046400,'right'),
4634(111,7,'abcdefjhjkl'), (112,6,'y'), (113,NULL,'to'), (114,7,'n'), (115,7,'look'),
4635(116,NULL,'all'), (117,1443168256,'c'), (118,1427046400,'right'),
4636(121,7,'abcdefjhjkl'), (122,6,'y'), (123,NULL,'to'), (124,7,'n'), (125,7,'look'),
4637(126,NULL,'all'), (127,1443168256,'c'), (128,1427046400,'right'),
4638(131,7,'abcdefjhjkl'), (132,6,'y'), (133,NULL,'to'), (134,7,'n'), (135,7,'look'),
4639(136,NULL,'all'), (137,1443168256,'c'), (138,1427046400,'right');
4640SET SESSION join_buffer_size = 256;
4641SET SESSION join_cache_level = 4;
4642EXPLAIN
4643SELECT t3.i FROM t1,t2,t3
4644WHERE t1.v = t2.v AND t3.v = t1.v AND t2.i <> 0;
4645id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
46461	SIMPLE	t1	index	idx	idx	13	NULL	7	Using where; Using index
46471	SIMPLE	t2	hash_ALL	idx	#hash#idx	1003	test.t1.v	36	Using where; Using join buffer (flat, BNLH join)
46481	SIMPLE	t3	hash_ALL	idx	#hash#idx	1002	func	64	Using where; Using join buffer (incremental, BNLH join)
4649SELECT t3.i FROM t1,t2,t3
4650WHERE t1.v = t2.v AND t3.v = t1.v AND t2.i <> 0;
4651i
4652SET SESSION join_cache_level=@save_join_cache_level;
4653SET SESSION join_buffer_size=@save_join_buffer_size;
4654DROP TABLE t1,t2,t3;
4655#
4656# Bug #672551: hash join over a long varchar field
4657#
4658CREATE TABLE t1 (
4659pk int PRIMARY KEY,
4660a varchar(512) CHARSET latin1 COLLATE latin1_bin DEFAULT NULL,
4661INDEX idx (a)
4662);
4663INSERT INTO t1 VALUES (2, 'aa'), (5, 'ccccccc'), (3, 'bb');
4664CREATE TABLE t2(
4665pk int PRIMARY KEY,
4666a varchar(512) CHARSET latin1 COLLATE latin1_bin DEFAULT NULL,
4667INDEX idx (a)
4668);
4669INSERT INTO t2 VALUES
4670(10, 'a'), (20, 'c'), (30, 'aa'), (4, 'bb'),
4671(11, 'a'), (21, 'c'), (31, 'aa'), (41, 'cc'),
4672(12, 'a'), (22, 'c'), (32, 'bb'), (42, 'aa');
4673INSERT INTO t2 VALUES
4674(110, 'a'), (120, 'c'), (130, 'aa'), (14, 'bb'),
4675(111, 'a'), (121, 'c'), (131, 'aa'), (141, 'cc'),
4676(112, 'a'), (122, 'c'), (132, 'bb'), (142, 'aa');
4677SELECT * FROM t1,t2 WHERE t2.a=t1.a;
4678pk	a	pk	a
46792	aa	30	aa
46802	aa	31	aa
46812	aa	42	aa
46822	aa	130	aa
46832	aa	131	aa
46842	aa	142	aa
46853	bb	4	bb
46863	bb	32	bb
46873	bb	14	bb
46883	bb	132	bb
4689SET SESSION join_cache_level = 4;
4690EXPLAIN
4691SELECT * FROM t1,t2 WHERE t2.a=t1.a;
4692id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
46931	SIMPLE	t1	ALL	idx	NULL	NULL	NULL	3	Using where
46941	SIMPLE	t2	hash_ALL	idx	#hash#idx	515	test.t1.a	24	Using join buffer (flat, BNLH join)
4695SELECT * FROM t1,t2 WHERE t2.a=t1.a;
4696pk	a	pk	a
46972	aa	30	aa
46983	bb	4	bb
46992	aa	31	aa
47003	bb	32	bb
47012	aa	42	aa
47022	aa	130	aa
47033	bb	14	bb
47042	aa	131	aa
47053	bb	132	bb
47062	aa	142	aa
4707SET SESSION join_cache_level=@save_join_cache_level;
4708DROP TABLE t1,t2;
4709#
4710# Bug #674431: nested outer join when join_cache_level is set to 7
4711#
4712CREATE TABLE t1 (a int, b varchar(32)) ;
4713INSERT INTO t1 VALUES (5,'h'), (NULL,'j');
4714CREATE TABLE t2 (a int, b varchar(32), c int) ;
4715INSERT INTO t2 VALUES (5,'h',100), (NULL,'j',200);
4716CREATE TABLE t3 (a int, b varchar(32), INDEX idx(b));
4717INSERT INTO t3 VALUES (77,'h'), (88,'g');
4718SET SESSION optimizer_switch = 'outer_join_with_cache=on';
4719SET SESSION join_cache_level = 7;
4720SELECT t3.a
4721FROM t1 LEFT JOIN
4722(t2 LEFT OUTER JOIN t3 ON t2.b = t3.b) ON t2.a = t1.b
4723WHERE t3.a BETWEEN 3 AND 11 OR t1.a <= t2.c;
4724a
4725Warnings:
4726Warning	1292	Truncated incorrect INTEGER value: 'h'
4727Warning	1292	Truncated incorrect INTEGER value: 'j'
4728SET SESSION optimizer_switch=@local_optimizer_switch;
4729SET SESSION join_cache_level=@save_join_cache_level;
4730DROP TABLE t1,t2,t3;
4731#
4732# Bug #52540: nested outer join when join_cache_level is set to 3
4733#
4734CREATE TABLE t1 (a int);
4735INSERT INTO t1 VALUES (2);
4736CREATE TABLE t2 (a varchar(10));
4737INSERT INTO t2 VALUES ('f'),('x');
4738CREATE TABLE t3 (pk int(11) PRIMARY KEY);
4739INSERT INTO t3 VALUES (2);
4740CREATE TABLE t4 (a varchar(10));
4741SET SESSION optimizer_switch = 'outer_join_with_cache=on';
4742SET SESSION join_cache_level = 3;
4743SELECT *
4744FROM t2 LEFT JOIN
4745((t1 JOIN t3 ON t1.a = t3.pk) LEFT JOIN t4 ON 1) ON 1;
4746a	a	pk	a
4747f	2	2	NULL
4748x	2	2	NULL
4749SET SESSION optimizer_switch=@local_optimizer_switch;
4750SET SESSION join_cache_level=@save_join_cache_level;
4751DROP TABLE t1,t2,t3,t4;
4752#
4753# Bug #674423: outer join with ON expression over only outer tables
4754#
4755CREATE TABLE t1 (a int) ;
4756INSERT INTO t1 VALUES ('9');
4757CREATE TABLE t2 (pk int, a int) ;
4758INSERT INTO t2 VALUES ('9',NULL), ('1',NULL);
4759SET SESSION optimizer_switch = 'outer_join_with_cache=on';
4760SET SESSION join_cache_level = 0;
4761EXPLAIN
4762SELECT * FROM t2 LEFT JOIN t1 ON t2.a <> 0 WHERE t1.a <> 0 OR t2.pk < 9;
4763id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
47641	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	2
47651	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	1	Using where
4766SELECT * FROM t2 LEFT JOIN t1 ON t2.a <> 0 WHERE t1.a <>0 OR t2.pk < 9;
4767pk	a	a
47681	NULL	NULL
4769SET SESSION join_cache_level = 1;
4770EXPLAIN
4771SELECT * FROM t2 LEFT JOIN t1 ON t2.a <> 0 WHERE t1.a <> 0 OR t2.pk < 9;
4772id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
47731	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	2
47741	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (flat, BNL join)
4775SELECT * FROM t2 LEFT JOIN t1 ON t2.a <> 0 WHERE t1.a <> 0 OR t2.pk < 9;
4776pk	a	a
47771	NULL	NULL
4778SET SESSION optimizer_switch=@local_optimizer_switch;
4779SET SESSION join_cache_level=@save_join_cache_level;
4780DROP TABLE t1,t2;
4781#
4782# Bug #675095: nested outer join using join buffer
4783#
4784CREATE TABLE t1 (pk int, a1 int) ;
4785INSERT IGNORE INTO t1 VALUES (2,NULL), (8,0);
4786CREATE TABLE t2 (pk int, a2 int, c2 int, d2 int) ;
4787INSERT IGNORE INTO t2 VALUES  (9,0,0,2), (1,0,0,7);
4788CREATE TABLE t3 (pk int, a3 int, c3 int, d3 int) ;
4789INSERT IGNORE INTO t3 VALUES  (9,0,0,2), (1,0,0,7);
4790CREATE TABLE t4 (pk int, a4 int, INDEX idx(a4)) ;
4791INSERT IGNORE INTO t4 VALUES (2,NULL), (8,0);
4792INSERT IGNORE INTO t4 VALUES (12,10), (18,20);
4793INSERT IGNORE INTO t4 VALUES (22,11), (28,21);
4794INSERT IGNORE INTO t4 VALUES (32,12), (38,22);
4795CREATE TABLE t5 (pk int, a5 int) ;
4796INSERT IGNORE INTO t5 VALUES (2,0), (8,0);
4797SET SESSION optimizer_switch = 'outer_join_with_cache=on';
4798SET SESSION join_cache_level = 0;
4799EXPLAIN EXTENDED
4800SELECT *
4801FROM ((t1 LEFT JOIN (t2 JOIN t3 ON t2.c2 = t3.a3) ON t1.pk = t2.d2)
4802LEFT JOIN t4 ON t1.a1 = t4.a4) LEFT JOIN t5 ON t3.a3 = t5.a5;
4803id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
48041	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00
48051	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
48061	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
48071	SIMPLE	t4	ref	idx	idx	5	test.t1.a1	2	100.00	Using where
48081	SIMPLE	t5	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
4809Warnings:
4810Note	1003	select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`a1` AS `a1`,`test`.`t2`.`pk` AS `pk`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`c2` AS `c2`,`test`.`t2`.`d2` AS `d2`,`test`.`t3`.`pk` AS `pk`,`test`.`t3`.`a3` AS `a3`,`test`.`t3`.`c3` AS `c3`,`test`.`t3`.`d3` AS `d3`,`test`.`t4`.`pk` AS `pk`,`test`.`t4`.`a4` AS `a4`,`test`.`t5`.`pk` AS `pk`,`test`.`t5`.`a5` AS `a5` from `test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(`test`.`t2`.`d2` = `test`.`t1`.`pk` and `test`.`t3`.`a3` = `test`.`t2`.`c2`) left join `test`.`t4` on(`test`.`t4`.`a4` = `test`.`t1`.`a1` and `test`.`t1`.`a1` is not null) left join `test`.`t5` on(`test`.`t5`.`a5` = `test`.`t3`.`a3`) where 1
4811SELECT *
4812FROM ((t1 LEFT JOIN (t2 JOIN t3 ON t2.c2 = t3.a3) ON t1.pk = t2.d2)
4813LEFT JOIN t4 ON t1.a1 = t4.a4) LEFT JOIN t5 ON t3.a3 = t5.a5;
4814pk	a1	pk	a2	c2	d2	pk	a3	c3	d3	pk	a4	pk	a5
48152	NULL	9	0	0	2	9	0	0	2	NULL	NULL	2	0
48162	NULL	9	0	0	2	9	0	0	2	NULL	NULL	8	0
48172	NULL	9	0	0	2	1	0	0	7	NULL	NULL	2	0
48182	NULL	9	0	0	2	1	0	0	7	NULL	NULL	8	0
48198	0	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	8	0	NULL	NULL
4820SET SESSION join_cache_level = 2;
4821EXPLAIN EXTENDED
4822SELECT *
4823FROM ((t1 LEFT JOIN (t2 JOIN t3 ON t2.c2 = t3.a3) ON t1.pk = t2.d2)
4824LEFT JOIN t4 ON t1.a1 = t4.a4) LEFT JOIN t5 ON t3.a3 = t5.a5;
4825id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
48261	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00
48271	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (flat, BNL join)
48281	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (incremental, BNL join)
48291	SIMPLE	t4	ref	idx	idx	5	test.t1.a1	2	100.00	Using where
48301	SIMPLE	t5	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (flat, BNL join)
4831Warnings:
4832Note	1003	select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`a1` AS `a1`,`test`.`t2`.`pk` AS `pk`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`c2` AS `c2`,`test`.`t2`.`d2` AS `d2`,`test`.`t3`.`pk` AS `pk`,`test`.`t3`.`a3` AS `a3`,`test`.`t3`.`c3` AS `c3`,`test`.`t3`.`d3` AS `d3`,`test`.`t4`.`pk` AS `pk`,`test`.`t4`.`a4` AS `a4`,`test`.`t5`.`pk` AS `pk`,`test`.`t5`.`a5` AS `a5` from `test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(`test`.`t2`.`d2` = `test`.`t1`.`pk` and `test`.`t3`.`a3` = `test`.`t2`.`c2`) left join `test`.`t4` on(`test`.`t4`.`a4` = `test`.`t1`.`a1` and `test`.`t1`.`a1` is not null) left join `test`.`t5` on(`test`.`t5`.`a5` = `test`.`t3`.`a3`) where 1
4833SELECT *
4834FROM ((t1 LEFT JOIN (t2 JOIN t3 ON t2.c2 = t3.a3) ON t1.pk = t2.d2)
4835LEFT JOIN t4 ON t1.a1 = t4.a4) LEFT JOIN t5 ON t3.a3 = t5.a5;
4836pk	a1	pk	a2	c2	d2	pk	a3	c3	d3	pk	a4	pk	a5
48372	NULL	9	0	0	2	9	0	0	2	NULL	NULL	2	0
48382	NULL	9	0	0	2	1	0	0	7	NULL	NULL	2	0
48392	NULL	9	0	0	2	9	0	0	2	NULL	NULL	8	0
48402	NULL	9	0	0	2	1	0	0	7	NULL	NULL	8	0
48418	0	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	8	0	NULL	NULL
4842SET SESSION join_cache_level = 1;
4843EXPLAIN EXTENDED
4844SELECT *
4845FROM ((t1 LEFT JOIN (t2 JOIN t3 ON t2.c2 = t3.a3) ON t1.pk = t2.d2)
4846LEFT JOIN t4 ON t1.a1 = t4.a4) LEFT JOIN t5 ON t3.a3 = t5.a5;
4847id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
48481	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	100.00
48491	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
48501	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where
48511	SIMPLE	t4	ref	idx	idx	5	test.t1.a1	2	100.00	Using where
48521	SIMPLE	t5	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer (flat, BNL join)
4853Warnings:
4854Note	1003	select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`a1` AS `a1`,`test`.`t2`.`pk` AS `pk`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`c2` AS `c2`,`test`.`t2`.`d2` AS `d2`,`test`.`t3`.`pk` AS `pk`,`test`.`t3`.`a3` AS `a3`,`test`.`t3`.`c3` AS `c3`,`test`.`t3`.`d3` AS `d3`,`test`.`t4`.`pk` AS `pk`,`test`.`t4`.`a4` AS `a4`,`test`.`t5`.`pk` AS `pk`,`test`.`t5`.`a5` AS `a5` from `test`.`t1` left join (`test`.`t2` join `test`.`t3`) on(`test`.`t2`.`d2` = `test`.`t1`.`pk` and `test`.`t3`.`a3` = `test`.`t2`.`c2`) left join `test`.`t4` on(`test`.`t4`.`a4` = `test`.`t1`.`a1` and `test`.`t1`.`a1` is not null) left join `test`.`t5` on(`test`.`t5`.`a5` = `test`.`t3`.`a3`) where 1
4855SELECT *
4856FROM ((t1 LEFT JOIN (t2 JOIN t3 ON t2.c2 = t3.a3) ON t1.pk = t2.d2)
4857LEFT JOIN t4 ON t1.a1 = t4.a4) LEFT JOIN t5 ON t3.a3 = t5.a5;
4858pk	a1	pk	a2	c2	d2	pk	a3	c3	d3	pk	a4	pk	a5
48592	NULL	9	0	0	2	9	0	0	2	NULL	NULL	2	0
48602	NULL	9	0	0	2	1	0	0	7	NULL	NULL	2	0
48612	NULL	9	0	0	2	9	0	0	2	NULL	NULL	8	0
48622	NULL	9	0	0	2	1	0	0	7	NULL	NULL	8	0
48638	0	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	8	0	NULL	NULL
4864SET SESSION optimizer_switch=@local_optimizer_switch;
4865SET SESSION join_cache_level=@save_join_cache_level;
4866DROP TABLE t1,t2,t3,t4,t5;
4867#
4868# Bug #675516: nested outer join with 3 tables in the nest
4869#             using BNL + BNLH
4870#
4871CREATE TABLE t1 (a1 int, b1 int, c1 int) ;
4872INSERT INTO t1 VALUES (7,8,0), (6,4,0);
4873CREATE TABLE t2 (a2 int) ;
4874INSERT INTO t2 VALUES (5);
4875CREATE TABLE t3 (a3 int, b3 int, c3 int, PRIMARY KEY (b3)) ;
4876INSERT INTO t3 VALUES (2,5,0);
4877CREATE TABLE t4 (a4 int, b4 int, c4 int) ;
4878INSERT INTO t4 VALUES (7,8,0);
4879SET SESSION optimizer_switch = 'outer_join_with_cache=on';
4880SET SESSION join_cache_level = 4;
4881EXPLAIN
4882SELECT * FROM
4883t1 LEFT JOIN
4884((t2 JOIN t3 ON t2.a2 = t3.b3) JOIN t4 ON t4.b4 <> 0) ON t1.c1 = t3.c3
4885WHERE t3.a3 IS NULL;
4886id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
48871	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2
48881	SIMPLE	t3	hash_ALL	PRIMARY	#hash#$hj	5	test.t1.c1	1	Using where; Using join buffer (flat, BNLH join)
48891	SIMPLE	t2	hash_ALL	NULL	#hash#$hj	5	test.t3.b3	1	Using where; Using join buffer (incremental, BNLH join)
48901	SIMPLE	t4	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
4891SELECT * FROM
4892t1 LEFT JOIN
4893((t2 JOIN t3 ON t2.a2 = t3.b3) JOIN t4 ON t4.b4 <> 0) ON t1.c1 = t3.c3
4894WHERE t3.a3 IS NULL;
4895a1	b1	c1	a2	a3	b3	c3	a4	b4	c4
4896SET SESSION join_cache_level = 0;
4897EXPLAIN
4898SELECT * FROM
4899t1 LEFT JOIN
4900((t2 JOIN t3 ON t2.a2 = t3.b3) JOIN t4 ON t4.b4 <> 0) ON t1.c1 = t3.c3
4901WHERE t3.a3 IS NULL;
4902id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
49031	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2
49041	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1	Using where
49051	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	4	test.t2.a2	1	Using where
49061	SIMPLE	t4	ALL	NULL	NULL	NULL	NULL	1	Using where
4907SELECT * FROM
4908t1 LEFT JOIN
4909((t2 JOIN t3 ON t2.a2 = t3.b3) JOIN t4 ON t4.b4 <> 0) ON t1.c1 = t3.c3
4910WHERE t3.a3 IS NULL;
4911a1	b1	c1	a2	a3	b3	c3	a4	b4	c4
4912SET SESSION optimizer_switch=@local_optimizer_switch;
4913SET SESSION join_cache_level=@save_join_cache_level;
4914DROP TABLE t1,t2,t3,t4;
4915#
4916# Bug #660963: nested outer join with join_cache_level set to 5
4917#
4918CREATE TABLE t1 (a1 int) ;
4919INSERT INTO t1 VALUES (0),(0);
4920CREATE TABLE t2 (a2 int, b2 int, PRIMARY KEY (a2)) ;
4921INSERT INTO t2 VALUES (2,1);
4922CREATE TABLE t3 (a3 int, b3 int, PRIMARY KEY (a3)) ;
4923INSERT INTO t3 VALUES (2,1);
4924SET SESSION optimizer_switch = 'outer_join_with_cache=on';
4925SET SESSION join_cache_level = 6;
4926EXPLAIN
4927SELECT * FROM t1 LEFT JOIN t2 JOIN t3 ON t3.a3 = t2.a2 ON t3.b3 <> 0;
4928id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
49291	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2
49301	SIMPLE	t2	ALL	PRIMARY	NULL	NULL	NULL	1	Using where; Using join buffer (flat, BNL join)
49311	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	4	test.t2.a2	1	Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
4932SELECT * FROM t1 LEFT JOIN t2 JOIN t3 ON t3.a3 = t2.a2 ON t3.b3 <> 0;
4933a1	a2	b2	a3	b3
49340	2	1	2	1
49350	2	1	2	1
4936SET SESSION join_cache_level = 5;
4937EXPLAIN
4938SELECT * FROM t1 LEFT JOIN t2 JOIN t3 ON t3.a3 = t2.a2 ON t3.b3 <> 0;
4939id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
49401	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2
49411	SIMPLE	t2	ALL	PRIMARY	NULL	NULL	NULL	1	Using where; Using join buffer (flat, BNL join)
49421	SIMPLE	t3	hash_ALL	PRIMARY	#hash#PRIMARY	4	test.t2.a2	1	Using where; Using join buffer (incremental, BNLH join)
4943SELECT * FROM t1 LEFT JOIN t2 JOIN t3 ON t3.a3 = t2.a2 ON t3.b3 <> 0;
4944a1	a2	b2	a3	b3
49450	2	1	2	1
49460	2	1	2	1
4947SET SESSION optimizer_switch=@local_optimizer_switch;
4948SET SESSION join_cache_level=@save_join_cache_level;
4949DROP TABLE t1,t2,t3;
4950#
4951# Bug #675922: incremental buffer for BKA with access from previous
4952#      buffers from non-nullable columns whose values may be null
4953#
4954CREATE TABLE t1 (a1 varchar(32)) ;
4955INSERT INTO t1 VALUES ('s'),('k');
4956CREATE TABLE t2 (a2 int PRIMARY KEY, b2 varchar(32)) ;
4957INSERT INTO t2 VALUES (7,'s');
4958CREATE TABLE t3 (a3 int PRIMARY KEY, b3 varchar(32)) ;
4959INSERT INTO t3 VALUES (7,'s');
4960CREATE TABLE t4 (a4 int) ;
4961INSERT INTO t4 VALUES (9);
4962CREATE TABLE t5(a5 int PRIMARY KEY, b5 int) ;
4963INSERT INTO t5 VALUES (7,0);
4964SET SESSION optimizer_switch = 'outer_join_with_cache=on';
4965SET SESSION join_cache_level = 0;
4966EXPLAIN
4967SELECT t4.a4, t5.b5
4968FROM ((t1 LEFT JOIN (t2 JOIN t3 ON t2.a2 = t3.a3) ON t2.b2 = t1.a1)
4969LEFT JOIN t4 ON t4.a4 <> 0) LEFT JOIN t5 ON t5.a5 = t2.a2;
4970id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
49711	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2
49721	SIMPLE	t2	ALL	PRIMARY	NULL	NULL	NULL	1	Using where
49731	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	4	test.t2.a2	1	Using index
49741	SIMPLE	t4	ALL	NULL	NULL	NULL	NULL	1	Using where
49751	SIMPLE	t5	eq_ref	PRIMARY	PRIMARY	4	test.t2.a2	1	Using where
4976SELECT t4.a4, t5.b5
4977FROM ((t1 LEFT JOIN (t2 JOIN t3 ON t2.a2 = t3.a3) ON t2.b2 = t1.a1)
4978LEFT JOIN t4 ON t4.a4 <> 0) LEFT JOIN t5 ON t5.a5 = t2.a2;
4979a4	b5
49809	0
49819	NULL
4982SET SESSION join_cache_level = 6;
4983EXPLAIN
4984SELECT t4.a4, t5.b5
4985FROM ((t1 LEFT JOIN (t2 JOIN t3 ON t2.a2 = t3.a3) ON t2.b2 = t1.a1)
4986LEFT JOIN t4 ON t4.a4 <> 0) LEFT JOIN t5 ON t5.a5 = t2.a2;
4987id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
49881	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2
49891	SIMPLE	t2	ALL	PRIMARY	NULL	NULL	NULL	1	Using where
49901	SIMPLE	t3	eq_ref	PRIMARY	PRIMARY	4	test.t2.a2	1	Using index
49911	SIMPLE	t4	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (flat, BNL join)
49921	SIMPLE	t5	eq_ref	PRIMARY	PRIMARY	4	test.t2.a2	1	Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
4993SELECT t4.a4, t5.b5
4994FROM ((t1 LEFT JOIN (t2 JOIN t3 ON t2.a2 = t3.a3) ON t2.b2 = t1.a1)
4995LEFT JOIN t4 ON t4.a4 <> 0) LEFT JOIN t5 ON t5.a5 = t2.a2;
4996a4	b5
49979	0
49989	NULL
4999SET SESSION optimizer_switch=@local_optimizer_switch;
5000SET SESSION join_cache_level=@save_join_cache_level;
5001DROP TABLE t1,t2,t3,t4,t5;
5002#
5003# Bug #670380: hash join for non-binary collation
5004#
5005CREATE TABLE t1 (pk int PRIMARY KEY, a varchar(32));
5006CREATE TABLE t2 (pk int PRIMARY KEY, a varchar(32), INDEX idx(a));
5007INSERT INTO t1 VALUES
5008(10,'AAA'), (20,'BBBB'), (30,'Cc'), (40,'DD'), (50,'ee');
5009INSERT INTO t2 VALUES
5010(1,'Bbbb'), (2,'BBB'), (3,'bbbb'), (4,'AaA'), (5,'CC'),
5011(6,'cC'), (7,'CCC'), (8,'AAA'), (9,'bBbB'), (10,'aaaa'),
5012(11,'a'), (12,'dd'), (13,'EE'), (14,'ee'), (15,'D'),
5013(101,'Bbbb'), (102,'BBB'), (103,'bbbb'), (104,'AaA'), (105,'CC'),
5014(106,'cC'), (107,'CCC'), (108,'AAA'), (109,'bBbB'), (110,'aaaa'),
5015(111,'a'), (112,'dd'), (113,'EE'), (114,'ee'), (115,'D');
5016SET SESSION join_cache_level = 4;
5017EXPLAIN
5018SELECT * FROM t1,t2 WHERE t1.a=t2.a;
5019id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
50201	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	5	Using where
50211	SIMPLE	t2	hash_ALL	idx	#hash#idx	35	test.t1.a	30	Using join buffer (flat, BNLH join)
5022SELECT * FROM t1,t2 WHERE t1.a=t2.a;
5023pk	a	pk	a
502420	BBBB	1	Bbbb
502520	BBBB	3	bbbb
502610	AAA	4	AaA
502730	Cc	5	CC
502830	Cc	6	cC
502910	AAA	8	AAA
503020	BBBB	9	bBbB
503140	DD	12	dd
503250	ee	13	EE
503350	ee	14	ee
503420	BBBB	101	Bbbb
503520	BBBB	103	bbbb
503610	AAA	104	AaA
503730	Cc	105	CC
503830	Cc	106	cC
503910	AAA	108	AAA
504020	BBBB	109	bBbB
504140	DD	112	dd
504250	ee	113	EE
504350	ee	114	ee
5044SET SESSION join_cache_level=@save_join_cache_level;
5045DROP TABLE t1,t2;
5046#
5047# Bug #694092: incorrect detection of index only pushdown conditions
5048#
5049CREATE TABLE t1 (
5050f1 varchar(10), f3 int(11), PRIMARY KEY (f3)
5051);
5052INSERT INTO t1 VALUES ('y',1),('or',5);
5053CREATE TABLE t2 (
5054f3 int(11), f2 varchar(1024), f4 varchar(10), PRIMARY KEY (f3)
5055);
5056INSERT INTO t2 VALUES (6,'RPOYT','y'),(10,'JINQE','m');
5057SET SESSION join_cache_level = 1;
5058SET SESSION optimizer_switch = 'index_condition_pushdown=off';
5059EXPLAIN
5060SELECT * FROM t1,t2
5061WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6);
5062id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
50631	SIMPLE	t1	ALL	PRIMARY	NULL	NULL	NULL	2	Using where
50641	SIMPLE	t2	ALL	PRIMARY	NULL	NULL	NULL	2	Using where; Using join buffer (flat, BNL join)
5065SELECT * FROM t1,t2
5066WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6);
5067f1	f3	f3	f2	f4
5068SET SESSION optimizer_switch = 'index_condition_pushdown=on';
5069EXPLAIN
5070SELECT * FROM t1,t2
5071WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6);
5072id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
50731	SIMPLE	t1	ALL	PRIMARY	NULL	NULL	NULL	2	Using where
50741	SIMPLE	t2	ALL	PRIMARY	NULL	NULL	NULL	2	Using where; Using join buffer (flat, BNL join)
5075SELECT * FROM t1,t2
5076WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6);
5077f1	f3	f3	f2	f4
5078SET SESSION join_cache_level=@save_join_cache_level;
5079SET SESSION optimizer_switch=@local_optimizer_switch;
5080DROP TABLE t1,t2;
5081CREATE TABLE t1 (f1 int, f2 varchar(10), KEY (f1), KEY (f2)) ;
5082INSERT INTO t1 VALUES
5083(4,'e'), (891879424,'l'), (-243400704,'ectlyqupbk'), (1851981824,'of'),
5084(-1495203840,'you'), (4,'no'), (-1436942336,'c'), (891420672,'DQQYO'),
5085(608698368,'qergldqmec'), (1,'x');
5086CREATE TABLE t2 (f3 varchar(64), KEY (f3));
5087INSERT INTO t2 VALUES
5088('d'), ('UALLN'), ('d'), ('z'), ('r'), ('YVAKV'), ('d'), ('TNGZK'), ('e'),
5089('xucupaxdyythsgiw'), ('why'), ('ttugkxucupaxdyyt'), ('l'), ('LHTKN'),
5090('d'), ('o'), ('v'), ('KGLCJ'), ('your');
5091SET SESSION optimizer_switch='index_merge_sort_intersection=off';
5092SET SESSION optimizer_switch = 'index_condition_pushdown=off';
5093EXPLAIN SELECT * FROM t1,t2
5094WHERE t2.f3 = t1.f2 AND t1.f1 IN (9, 0, 100) ORDER BY t1.f2 LIMIT 1;
5095id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
50961	SIMPLE	t1	range	f1,f2	f2	13	NULL	10	Using where
50971	SIMPLE	t2	ref	f3	f3	67	test.t1.f2	2	Using where; Using index
5098SELECT * FROM t1,t2
5099WHERE t2.f3 = t1.f2 AND t1.f1 IN (9, 0 ,100) ORDER BY t1.f2 LIMIT 1;
5100f1	f2	f3
5101SET SESSION optimizer_switch=@local_optimizer_switch;
5102SET SESSION optimizer_switch = 'index_condition_pushdown=on';
5103EXPLAIN SELECT * FROM t1,t2
5104WHERE t2.f3 = t1.f2 AND t1.f1 IN (9, 0 ,100) ORDER BY t1.f2 LIMIT 1;
5105id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
51061	SIMPLE	t1	range	f1,f2	f2	13	NULL	10	Using where
51071	SIMPLE	t2	ref	f3	f3	67	test.t1.f2	2	Using where; Using index
5108SELECT * FROM t1,t2
5109WHERE t2.f3 = t1.f2 AND t1.f1 IN (9, 0 ,100) ORDER BY t1.f2 LIMIT 1;
5110f1	f2	f3
5111SET SESSION optimizer_switch=@local_optimizer_switch;
5112DROP TABLE t1,t2;
5113#
5114# Bug #694443: hash join using IS NULL the an equi-join condition
5115#
5116CREATE TABLE t1 (a int PRIMARY KEY);
5117INSERT INTO t1 VALUES
5118(7), (4), (9), (1), (3), (8), (2);
5119CREATE TABLE t2 (a int, b int, INDEX idx (a));
5120INSERT INTO t2 VALUES
5121(NULL,10), (4,80), (7,70), (6,11), (7,90), (NULL,40),
5122(4,77), (4,50), (NULL,41), (7,99), (7,88), (8,12),
5123(1,21), (4,90), (7,91), (8,22), (6,92), (NULL,42),
5124(2,78), (2,51), (1,43), (5,97), (5,89);
5125SET SESSION join_cache_level = 1;
5126EXPLAIN
5127SELECT * FROM t1,t2 WHERE t1.a < 3 and t2.a IS NULL;
5128id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
51291	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	2	Using where; Using index
51301	SIMPLE	t2	ref	idx	idx	5	const	4	Using index condition
5131SELECT * FROM t1,t2 WHERE t1.a < 3 and t2.a IS NULL;
5132a	a	b
51331	NULL	10
51341	NULL	40
51351	NULL	41
51361	NULL	42
51372	NULL	10
51382	NULL	40
51392	NULL	41
51402	NULL	42
5141SET SESSION join_cache_level = 4;
5142EXPLAIN
5143SELECT * FROM t1,t2 WHERE t1.a < 3 and t2.a IS NULL;
5144id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
51451	SIMPLE	t1	range	PRIMARY	PRIMARY	4	NULL	2	Using where; Using index
51461	SIMPLE	t2	hash_range	idx	#hash#idx:idx	5:5	const	4	Using index condition; Using where; Rowid-ordered scan; Using join buffer (flat, BNLH join)
5147SELECT * FROM t1,t2 WHERE t1.a < 3 and t2.a IS NULL;
5148a	a	b
51491	NULL	10
51502	NULL	10
51511	NULL	40
51522	NULL	40
51531	NULL	41
51542	NULL	41
51551	NULL	42
51562	NULL	42
5157SET SESSION join_cache_level=@save_join_cache_level;
5158DROP TABLE t1,t2;
5159#
5160# Bug #697557: hash join on a varchar field
5161#
5162CREATE TABLE t1 ( f1 varchar(10) , f2 int(11) , KEY (f1));
5163INSERT INTO t1 VALUES ('r',1), ('m',2);
5164CREATE TABLE t2 ( f1 varchar(10) , f2 int(11) , KEY (f1));
5165INSERT INTO t2 VALUES
5166('hgtofubn',1), ('GDOXZ',91), ('n',2), ('fggxgalh',88),
5167('hgtofu',1), ('GDO',101), ('n',3), ('fggxga',55),
5168('hgtofu',3), ('GDO',33), ('nn',3), ('fggxgarrr',77),
5169('jgtofu',3), ('JDO',33), ('mn',3), ('jggxgarrr',77),
5170('igtofu',3), ('IDO',33), ('ln',3), ('iggxgarrr',77);
5171SET SESSION join_cache_level=3;
5172EXPLAIN
5173SELECT * FROM t1,t2 WHERE t2.f1 = t1.f1;
5174id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
51751	SIMPLE	t1	ALL	f1	NULL	NULL	NULL	2	Using where
51761	SIMPLE	t2	hash_ALL	f1	#hash#f1	13	test.t1.f1	20	Using join buffer (flat, BNLH join)
5177SELECT * FROM t1,t2 WHERE t2.f1 = t1.f1;
5178f1	f2	f1	f2
5179SET SESSION join_cache_level=@save_join_cache_level;
5180DROP TABLE t1,t2;
5181#
5182# Bug #707827: hash join on varchar column with NULLs
5183#
5184CREATE TABLE t1 (v varchar(1));
5185INSERT INTO t1 VALUES ('o'), ('u');
5186CREATE TABLE t2 (a int, v varchar(1), INDEX idx (v)) ;
5187INSERT INTO t2 VALUES
5188(8,NULL), (10,'b'), (5,'k'), (4,NULL),
5189(1,NULL), (11,'u'), (7,NULL), (2,'d'),
5190(18,'u'), (11,'b'), (15,'k'), (12,'d'),
5191(18,'x'), (11,'y'), (15,'l'), (12,'e');
5192SET SESSION join_buffer_size = 256;
5193SET SESSION join_cache_level = 4;
5194EXPLAIN
5195SELECT a FROM t1,t2 WHERE t2.v = t1.v ;
5196id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
51971	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	Using where
51981	SIMPLE	t2	hash_ALL	idx	#hash#idx	4	test.t1.v	16	Using join buffer (flat, BNLH join)
5199SELECT a FROM t1,t2 WHERE t2.v = t1.v ;
5200a
520111
520218
5203SET SESSION join_cache_level = 1;
5204EXPLAIN
5205SELECT a FROM t1,t2 WHERE t2.v = t1.v ;
5206id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
52071	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	Using where
52081	SIMPLE	t2	ref	idx	idx	4	test.t1.v	2
5209SELECT a FROM t1,t2 WHERE t2.v = t1.v ;
5210a
521111
521218
5213SET SESSION join_cache_level=@save_join_cache_level;
5214SET SESSION join_buffer_size=@save_join_buffer_size;
5215DROP TABLE t1,t2;
5216#
5217# Bug #802860: crash on join cache + derived + duplicate_weedout
5218#
5219SET SESSION optimizer_switch=
5220'semijoin=on,materialization=off,firstmatch=off,loosescan=off,derived_with_keys=on';
5221CREATE TABLE t1 (a int) ;
5222INSERT IGNORE INTO t1 VALUES (0), (1), (0);
5223CREATE TABLE t2 (a int) ;
5224INSERT IGNORE INTO t2 VALUES (0), (3), (0), (2);
5225SET SESSION join_cache_level = 0;
5226EXPLAIN
5227SELECT * FROM (SELECT DISTINCT * FROM t1) t
5228WHERE t.a IN (SELECT t2.a FROM t2);
5229id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
52301	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	4	Using where; Start temporary
52311	PRIMARY	<derived2>	ref	key0	key0	5	test.t2.a	1	End temporary
52322	DERIVED	t1	ALL	NULL	NULL	NULL	NULL	3	Using temporary
5233SELECT * FROM (SELECT DISTINCT * FROM t1) t
5234WHERE t.a IN (SELECT t2.a FROM t2);
5235a
52360
5237SET SESSION join_cache_level = 1;
5238EXPLAIN
5239SELECT * FROM (SELECT DISTINCT * FROM t1) t
5240WHERE t.a  IN (SELECT t2.a FROM t2);
5241id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
52421	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	4	Using where; Start temporary
52431	PRIMARY	<derived2>	ref	key0	key0	5	test.t2.a	1	End temporary
52442	DERIVED	t1	ALL	NULL	NULL	NULL	NULL	3	Using temporary
5245SELECT * FROM (SELECT DISTINCT * FROM t1) t
5246WHERE t.a  IN (SELECT t2.a FROM t2);
5247a
52480
5249DROP TABLE t1, t2;
5250SET SESSION join_cache_level=@save_join_cache_level;
5251#
5252# Bug #887479: join_cache_level=3 + semijoin=on
5253#
5254CREATE TABLE t1 (a int, b int);
5255INSERT INTO t1 VALUES (3914,17), (3710,5), (3888,20);
5256CREATE TABLE t2 (c int, KEY (c));
5257INSERT INTO t2 VALUES (27), (17), (33), (20), (3), (7), (18), (2);
5258SET @tmp_optimizer_switch=@@optimizer_switch;
5259SET SESSION optimizer_switch='semijoin=on';
5260SET SESSION optimizer_switch='semijoin_with_cache=on';
5261SET SESSION join_cache_level=1;
5262EXPLAIN
5263SELECT * FROM t1 WHERE (t1.b) IN (SELECT c FROM t2);
5264id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
52651	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
52661	PRIMARY	t2	ref	c	c	5	test.t1.b	2	Using index; Start temporary; End temporary
5267SELECT * FROM t1 WHERE (t1.b) IN (SELECT c FROM t2);
5268a	b
52693914	17
52703888	20
5271SET SESSION join_cache_level=3;
5272EXPLAIN
5273SELECT * FROM t1 WHERE (t1.b) IN (SELECT c FROM t2);
5274id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
52751	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	3	Using where
52761	PRIMARY	t2	hash_index	c	#hash#c:c	5:5	test.t1.b	8	Using index; Start temporary; End temporary; Using join buffer (flat, BNLH join)
5277SELECT * FROM t1 WHERE (t1.b) IN (SELECT c FROM t2);
5278a	b
52793914	17
52803888	20
5281SET SESSION join_cache_level=@save_join_cache_level;
5282set @@optimizer_switch=@tmp_optimizer_switch;
5283DROP TABLE t1,t2;
5284#
5285# Bug #899777: join_cache_level=4 + semijoin=on
5286#
5287CREATE TABLE t1 (a int, b int, c int, UNIQUE INDEX idx (a));
5288INSERT INTO t1 VALUES (1,8,6), (2,2,8);
5289CREATE TABLE t2 (a int, b int, c int, UNIQUE INDEX idx (a));
5290INSERT INTO t2 VALUES (1,8,6), (2,2,8);
5291CREATE TABLE t3 (a int, b int, c int, UNIQUE INDEX idx (a));
5292INSERT INTO t3 VALUES (1,8,6), (2,2,8);
5293CREATE TABLE t4 (a int, b int, c int, UNIQUE INDEX idx (a));
5294INSERT INTO t4 VALUES (1,8,6), (2,2,8);
5295SET @tmp_optimizer_switch=@@optimizer_switch;
5296SET SESSION optimizer_switch='semijoin=on';
5297SET SESSION optimizer_switch='semijoin_with_cache=on';
5298SET SESSION join_cache_level=1;
5299EXPLAIN
5300SELECT t1.* FROM t1,t2
5301WHERE (t1.b,t2.b) IN (SELECT t3.b,t4.b FROM t3,t4 WHERE t4.c=t3.b)
5302AND t1.a = 1;
5303id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
53041	PRIMARY	t1	const	idx	idx	5	const	1
53051	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	2
53061	PRIMARY	t3	ALL	NULL	NULL	NULL	NULL	2	Using where; Start temporary; Using join buffer (flat, BNL join)
53071	PRIMARY	t4	ALL	NULL	NULL	NULL	NULL	2	Using where; End temporary; Using join buffer (flat, BNL join)
5308SELECT t1.* FROM t1,t2
5309WHERE (t1.b,t2.b) IN (SELECT t3.b,t4.b FROM t3,t4 WHERE t4.c=t3.b)
5310AND t1.a = 1;
5311a	b	c
53121	8	6
5313SET SESSION join_cache_level=4;
5314EXPLAIN
5315SELECT t1.* FROM t1,t2
5316WHERE (t1.b,t2.b) IN (SELECT t3.b,t4.b FROM t3,t4 WHERE t4.c=t3.b)
5317AND t1.a = 1;
5318id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
53191	PRIMARY	t1	const	idx	idx	5	const	1
53201	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	2	Using where
53211	PRIMARY	t3	hash_ALL	NULL	#hash#$hj	5	const	2	Using where; Start temporary; Using join buffer (flat, BNLH join)
53221	PRIMARY	t4	hash_ALL	NULL	#hash#$hj	10	const,test.t2.b	2	Using where; End temporary; Using join buffer (incremental, BNLH join)
5323SELECT t1.* FROM t1,t2
5324WHERE (t1.b,t2.b) IN (SELECT t3.b,t4.b FROM t3,t4 WHERE t4.c=t3.b)
5325AND t1.a = 1;
5326a	b	c
53271	8	6
5328SET SESSION join_cache_level=@save_join_cache_level;
5329set @@optimizer_switch=@local_optimizer_switch;
5330DROP TABLE t1,t2,t3,t4;
5331#
5332# Bug #899509: an attempt to use hash join with join_cache_level=0
5333#
5334CREATE TABLE t1 (a int);
5335INSERT INTO t1 VALUES (8), (7);
5336CREATE TABLE t2 (a int);
5337INSERT INTO t2 VALUES (8), (7);
5338CREATE TABLE t3 (a int);
5339INSERT INTO t3 VALUES (8), (7);
5340set @@optimizer_switch='semijoin_with_cache=off';
5341set @@optimizer_switch='outer_join_with_cache=off';
5342set @@optimizer_switch='derived_merge=off,derived_with_keys=off';
5343SET join_cache_level=0;
5344EXPLAIN
5345SELECT * FROM (SELECT t1.* FROM t1, t2) t WHERE t.a IN (SELECT * FROM t3);
5346id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
53471	PRIMARY	<derived2>	ALL	NULL	NULL	NULL	NULL	4
53481	PRIMARY	<subquery3>	eq_ref	distinct_key	distinct_key	4	func	1
53493	MATERIALIZED	t3	ALL	NULL	NULL	NULL	NULL	2
53502	DERIVED	t1	ALL	NULL	NULL	NULL	NULL	2
53512	DERIVED	t2	ALL	NULL	NULL	NULL	NULL	2
5352SELECT * FROM (SELECT t1.* FROM t1, t2) t WHERE t.a IN (SELECT * FROM t3);
5353a
53548
53558
53567
53577
5358SELECT * FROM ( SELECT ta.* FROM t1 AS ta, t1 ) tb WHERE a IN ( SELECT * FROM t1 );
5359a
53608
53618
53627
53637
5364SET SESSION join_cache_level=@save_join_cache_level;
5365set @@optimizer_switch=@local_optimizer_switch;
5366DROP TABLE t1,t2,t3;
5367#
5368# Bug #900469: semijoin + BNLH + ORDER BY
5369#
5370CREATE TABLE t1 (a int, b int);
5371INSERT INTO t1 VALUES (8,10);
5372CREATE TABLE t2 (c int, d int);
5373INSERT INTO t2 VALUES (8,10);
5374INSERT INTO t2 VALUES (9,11);
5375CREATE TABLE t3 (c int, d int);
5376INSERT INTO t3 VALUES (8,10);
5377INSERT INTO t3 VALUES (9,11);
5378set @@optimizer_switch='semijoin_with_cache=on';
5379set @@optimizer_switch='firstmatch=off';
5380SET join_cache_level=1;
5381EXPLAIN
5382SELECT * FROM t1,t2 WHERE b IN (SELECT d FROM t3 WHERE c <= t2.c) ORDER BY a,d;
5383id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
53841	PRIMARY	t1	system	NULL	NULL	NULL	NULL	1	Using temporary; Using filesort
53851	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	2
53861	PRIMARY	t3	ALL	NULL	NULL	NULL	NULL	2	Using where; Start temporary; End temporary; Using join buffer (flat, BNL join)
5387SELECT * FROM t1,t2 WHERE b IN (SELECT d FROM t3 WHERE c <= t2.c) ORDER BY a,d;
5388a	b	c	d
53898	10	8	10
53908	10	9	11
5391SET join_cache_level=3;
5392EXPLAIN
5393SELECT * FROM t1,t2 WHERE b IN (SELECT d FROM t3 WHERE c <= t2.c);
5394id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
53951	PRIMARY	t1	system	NULL	NULL	NULL	NULL	1
53961	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	2
53971	PRIMARY	t3	hash_ALL	NULL	#hash#$hj	5	const	2	Using where; Start temporary; End temporary; Using join buffer (flat, BNLH join)
5398SELECT * FROM t1,t2 WHERE b IN (SELECT d FROM t3 WHERE c <= t2.c);
5399a	b	c	d
54008	10	8	10
54018	10	9	11
5402SET join_cache_level=3;
5403EXPLAIN
5404SELECT * FROM t1,t2 WHERE b IN (SELECT d FROM t3 WHERE c <= t2.c) ORDER BY a,d;
5405id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
54061	PRIMARY	t1	system	NULL	NULL	NULL	NULL	1	Using temporary; Using filesort
54071	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	2
54081	PRIMARY	t3	hash_ALL	NULL	#hash#$hj	5	const	2	Using where; Start temporary; End temporary; Using join buffer (flat, BNLH join)
5409SELECT * FROM t1,t2 WHERE b IN (SELECT d FROM t3 WHERE c <= t2.c) ORDER BY a,d;
5410a	b	c	d
54118	10	8	10
54128	10	9	11
5413SET SESSION join_cache_level=@save_join_cache_level;
5414set @@optimizer_switch=@local_optimizer_switch;
5415DROP TABLE t1,t2,t3;
5416#
5417# Bug #901478: semijoin + ORDER BY + join_cache_level=4|6
5418#
5419CREATE TABLE t1 (a char(1));
5420INSERT INTO t1 VALUES ('x');
5421CREATE TABLE t2 (a int, b int, c int, KEY(a), KEY(b), KEY(c));
5422INSERT INTO t2 VALUES
5423(9,1,0), (7,2,8), (2,3,5), (4,2,9), (8,3,8), (3,4,1), (5,5,4);
5424CREATE TABLE t3 (a CHAR(1));
5425INSERT INTO t3 VALUES ('x');
5426CREATE TABLE t4 (a int, b int, c int, KEY(b), KEY(c));
5427INSERT INTO t4 VALUES
5428(9,1,0), (7,2,8), (2,3,5), (4,2,9), (8,3,8), (3,4,1), (5,5,4);
5429INSERT INTO t4 VALUES
5430(19,11,10), (17,12,18), (12,13,15), (14,12,19),
5431(18,13,18), (13,14,11), (15,15,14);
5432SET @@optimizer_switch='semijoin=on';
5433SET @@optimizer_switch='firstmatch=off';
5434SET @@optimizer_switch='mrr=off';
5435SET @@optimizer_switch='semijoin_with_cache=off';
5436set join_cache_level=1;
5437EXPLAIN
5438SELECT * FROM t1,t2
5439WHERE t2.c IN (SELECT c FROM t3,t4 WHERE t4.a < 10) AND
5440t2.a BETWEEN 4 and 5
5441ORDER BY t2.b;
5442id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
54431	PRIMARY	t1	system	NULL	NULL	NULL	NULL	1
54441	PRIMARY	t3	system	NULL	NULL	NULL	NULL	1
54451	PRIMARY	t2	range	a,c	a	5	NULL	2	Using index condition; Using where; Using filesort
54461	PRIMARY	t4	ref	c	c	5	test.t2.c	2	Using where; Start temporary; End temporary
5447SELECT * FROM t1,t2
5448WHERE t2.c IN (SELECT c FROM t3,t4 WHERE t4.a < 10) AND
5449t2.a BETWEEN 4 and 5
5450ORDER BY t2.b;
5451a	a	b	c
5452x	4	2	9
5453x	5	5	4
5454set join_cache_level=4;
5455EXPLAIN
5456SELECT * FROM t1,t2
5457WHERE t2.c IN (SELECT c FROM t3,t4 WHERE t4.a < 10) AND
5458t2.a BETWEEN 4 and 5
5459ORDER BY t2.b;
5460id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
54611	PRIMARY	t1	system	NULL	NULL	NULL	NULL	1	Using temporary; Using filesort
54621	PRIMARY	t3	system	NULL	NULL	NULL	NULL	1
54631	PRIMARY	t2	range	a,c	a	5	NULL	2	Using index condition; Using where
54641	PRIMARY	t4	ref	c	c	5	test.t2.c	2	Using where; Start temporary; End temporary
5465SELECT * FROM t1,t2
5466WHERE t2.c IN (SELECT c FROM t3,t4 WHERE t4.a < 10) AND
5467t2.a BETWEEN 4 and 5
5468ORDER BY t2.b;
5469a	a	b	c
5470x	4	2	9
5471x	5	5	4
5472SET @@optimizer_switch='semijoin_with_cache=on';
5473set join_cache_level=6;
5474EXPLAIN
5475SELECT * FROM t1,t2
5476WHERE t2.c IN (SELECT c FROM t3,t4 WHERE t4.a < 10) AND
5477t2.a BETWEEN 4 and 5
5478ORDER BY t2.b;
5479id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
54801	PRIMARY	t1	system	NULL	NULL	NULL	NULL	1	Using temporary; Using filesort
54811	PRIMARY	t3	system	NULL	NULL	NULL	NULL	1
54821	PRIMARY	t2	range	a,c	a	5	NULL	2	Using index condition; Using where
54831	PRIMARY	t4	ref	c	c	5	test.t2.c	2	Using where; Start temporary; End temporary
5484SELECT * FROM t1,t2
5485WHERE t2.c IN (SELECT c FROM t3,t4 WHERE t4.a < 10) AND
5486t2.a BETWEEN 4 and 5
5487ORDER BY t2.b;
5488a	a	b	c
5489x	4	2	9
5490x	5	5	4
5491set join_cache_level=@save_join_cache_level;
5492set @@optimizer_switch=@local_optimizer_switch;
5493DROP TABLE t1,t2,t3,t4;
5494#
5495# Bug#53305 Duplicate weedout + join buffer (join cache --level=7,8)
5496#
5497create table t1 (uid int, fid int, index(uid));
5498insert into t1 values
5499(1,1), (1,2), (1,3), (1,4),
5500(2,5), (2,6), (2,7), (2,8),
5501(3,1), (3,2), (3,9);
5502create table t2 (uid int primary key, name varchar(128), index(name));
5503insert into t2 values
5504(1, "A"), (2, "B"), (3, "C"), (4, "D"), (5, "E"),
5505(6, "F"), (7, "G"), (8, "H"), (9, "I");
5506create table t3 (uid int, fid int, index(uid));
5507insert into t3 values
5508(1,1), (1,2), (1,3),(1,4),
5509(2,5), (2,6), (2,7), (2,8),
5510(3,1), (3,2), (3,9);
5511set @@optimizer_switch='semijoin=on';
5512set @@optimizer_switch='materialization=off';
5513set @@optimizer_switch='loosescan=off,firstmatch=off';
5514set @@optimizer_switch='mrr_sort_keys=off';
5515set join_cache_level=7;
5516create table t4 (uid int primary key, name varchar(128), index(name));
5517insert into t4 values
5518(1, "A"), (2, "B"), (3, "C"), (4, "D"), (5, "E"),
5519(6, "F"), (7, "G"), (8, "H"), (9, "I");
5520explain select name from t2, t1
5521where t1.uid in (select t4.uid from t4, t3 where t3.uid=1 and t4.uid=t3.fid)
5522and t2.uid=t1.fid;
5523id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
55241	PRIMARY	t3	ref	uid	uid	5	const	4	Using where; Start temporary
55251	PRIMARY	t4	eq_ref	PRIMARY	PRIMARY	4	test.t3.fid	1	Using index
55261	PRIMARY	t1	ALL	uid	NULL	NULL	NULL	11	Using where; End temporary; Using join buffer (flat, BNL join)
55271	PRIMARY	t2	eq_ref	PRIMARY	PRIMARY	4	test.t1.fid	1	Using join buffer (flat, BKAH join); Rowid-ordered scan
5528select name from t2, t1
5529where t1.uid in (select t4.uid from t4, t3 where t3.uid=1 and t4.uid=t3.fid)
5530and t2.uid=t1.fid;
5531name
5532A
5533A
5534B
5535B
5536C
5537D
5538E
5539F
5540G
5541H
5542I
5543set join_cache_level=@save_join_cache_level;
5544set @@optimizer_switch=@local_optimizer_switch;
5545drop table t1,t2,t3,t4;
5546#
5547# Bug#50358 - semijoin execution of subquery with outerjoin
5548#             emplying join buffer
5549#
5550CREATE TABLE t1 (i int);
5551CREATE TABLE t2 (i int);
5552CREATE TABLE t3 (i int);
5553INSERT INTO t1 VALUES (1), (2);
5554INSERT INTO t2 VALUES (6);
5555INSERT INTO t3 VALUES (1), (2);
5556set @@optimizer_switch='semijoin=on';
5557set @@optimizer_switch='materialization=on';
5558set join_cache_level=0;
5559EXPLAIN
5560SELECT * FROM t1 WHERE t1.i IN
5561(SELECT t3.i FROM t3 LEFT JOIN t2 ON t2.i=t3.i);
5562id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
55631	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2
55641	PRIMARY	<subquery2>	eq_ref	distinct_key	distinct_key	4	func	1
55652	MATERIALIZED	t3	ALL	NULL	NULL	NULL	NULL	2
55662	MATERIALIZED	t2	ALL	NULL	NULL	NULL	NULL	1	Using where
5567SELECT * FROM t1 WHERE t1.i IN
5568(SELECT t3.i FROM t3 LEFT JOIN t2 ON t2.i=t3.i);
5569i
55701
55712
5572set join_cache_level=2;
5573EXPLAIN
5574SELECT * FROM t1 WHERE t1.i IN
5575(SELECT t3.i FROM t3 LEFT JOIN t2 ON t2.i=t3.i);
5576id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
55771	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2
55781	PRIMARY	<subquery2>	eq_ref	distinct_key	distinct_key	4	func	1
55792	MATERIALIZED	t3	ALL	NULL	NULL	NULL	NULL	2
55802	MATERIALIZED	t2	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (flat, BNL join)
5581SELECT * FROM t1 WHERE t1.i IN
5582(SELECT t3.i FROM t3 LEFT JOIN t2 ON t2.i=t3.i);
5583i
55841
55852
5586set join_cache_level=@save_join_cache_level;
5587set @@optimizer_switch=@local_optimizer_switch;
5588DROP TABLE t1,t2,t3;
5589#
5590# Bug #12546542: missing row with semijoin=off + join cache
5591# (LP bug #922971)
5592#
5593CREATE TABLE t1 (a varchar(1024));
5594INSERT INTO t1 VALUES ('v'), ('we');
5595CREATE TABLE t2 (
5596a varchar(1024) CHARACTER SET utf8 DEFAULT NULL, b int, c int
5597);
5598INSERT INTO t2 VALUES ('we',4,NULL), ('v',1305673728,6);
5599CREATE TABLE t3 (b int, c int);
5600INSERT INTO t3 VALUES (4,4);
5601set @@optimizer_switch='semijoin=off';
5602set @@optimizer_switch='materialization=off';
5603set join_cache_level=0;
5604EXPLAIN
5605SELECT * FROM t1
5606WHERE a IN (SELECT t2.a FROM t2 LEFT JOIN t3 ON t2.b = t3.b
5607WHERE t2.c < 10 OR t3.c > 1);
5608id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
56091	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2	Using where
56102	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	2	Using where
56112	DEPENDENT SUBQUERY	t3	ALL	NULL	NULL	NULL	NULL	1	Using where
5612SELECT * FROM t1
5613WHERE a IN (SELECT t2.a FROM t2 LEFT JOIN t3 ON t2.b = t3.b
5614WHERE t2.c < 10 OR t3.c > 1);
5615a
5616v
5617we
5618set join_cache_level=2;
5619EXPLAIN
5620SELECT * FROM t1
5621WHERE a IN (SELECT t2.a FROM t2 LEFT JOIN t3 ON t2.b = t3.b
5622WHERE t2.c < 10 OR t3.c > 1);
5623id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
56241	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2	Using where
56252	DEPENDENT SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	2	Using where
56262	DEPENDENT SUBQUERY	t3	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (flat, BNL join)
5627SELECT * FROM t1
5628WHERE a IN (SELECT t2.a FROM t2 LEFT JOIN t3 ON t2.b = t3.b
5629WHERE t2.c < 10 OR t3.c > 1);
5630a
5631v
5632we
5633set join_cache_level=@save_join_cache_level;
5634set @@optimizer_switch=@local_optimizer_switch;
5635DROP TABLE t1,t2,t3;
5636#
5637# lp:925985 LEFT JOIN with optimize_join_buffer_size=off +
5638#           join_buffer_size > join_buffer_space_limit
5639#
5640CREATE TABLE t1 (a int);
5641INSERT INTO t1 VALUES (5), (3);
5642CREATE TABLE t2 (a int, b int);
5643INSERT INTO t2 VALUES
5644(3,30), (1,10), (7,70), (2,20),
5645(3,31), (1,11), (7,71), (2,21),
5646(3,32), (1,12), (7,72), (2,22);
5647CREATE TABLE t3 (b int, c int);
5648INSERT INTO t3 VALUES (32, 302), (42,400), (30,300);
5649set @@optimizer_switch='optimize_join_buffer_size=off';
5650set @@optimizer_switch='outer_join_with_cache=on';
5651set join_buffer_space_limit=4096;
5652set join_buffer_size=4096*2;
5653set join_cache_level=2;
5654EXPLAIN
5655SELECT * FROM t1, t2 LEFT JOIN t3 ON t2.b=t3.b WHERE t1.a=t2.a;
5656id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
56571	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2
56581	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	12	Using where
56591	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	3	Using where
5660SELECT * FROM t1, t2 LEFT JOIN t3 ON t2.b=t3.b WHERE t1.a=t2.a;
5661a	a	b	b	c
56623	3	30	30	300
56633	3	31	NULL	NULL
56643	3	32	32	302
5665set join_buffer_space_limit=@save_join_buffer_space_limit;
5666set join_buffer_size=@save_join_buffer_size;
5667set join_cache_level=@save_join_cache_level;
5668set @@optimizer_switch=@local_optimizer_switch;
5669DROP TABLE t1,t2,t3;
5670#
5671# Bug #1058071: LEFT JOIN using blobs
5672# (MDEV-564)    when join buffer size is small
5673#
5674CREATE TABLE t1 (
5675col269 decimal(31,10) unsigned DEFAULT NULL,
5676col280 geometry DEFAULT NULL,
5677col281 tinyint(1) DEFAULT NULL,
5678col282 time NOT NULL,
5679col284 datetime DEFAULT NULL,
5680col286 date DEFAULT NULL,
5681col287 datetime DEFAULT NULL,
5682col288 decimal(30,29) DEFAULT NULL,
5683col291 time DEFAULT NULL,
5684col292 time DEFAULT NULL
5685) ENGINE=Aria;
5686INSERT INTO t1 VALUES
5687(0.0,PointFromText('POINT(9 0)'),0,'11:24:05','2013-04-14 21:30:28',NULL,'2011-12-20 06:00:34',9.9,'13:04:39',NULL),
5688(0.0,NULL,127,'05:43:12','2012-09-05 06:15:27','2027-01-01','2011-10-29 10:48:29',0.0,'06:24:05','11:33:37'),
5689(0.0,NULL,127,'12:54:41','2013-01-12 11:32:58','2011-11-03','2013-01-03 02:00:34',00,'11:54:15','20:19:15'),
5690(0.0,PointFromText('POINT(9 0)'),0,'19:48:07','2012-07-16 15:45:25','2012-03-25','2013-09-07 17:21:52',0.5,'17:36:54','21:24:19'),
5691(0.0,PointFromText('POINT(9 0)'),0,'03:43:48','2012-09-28 00:00:00','2012-06-26','2011-11-16 05:01:09',00,'01:25:42','19:30:06'),
5692(0.0,LineStringFromText('LINESTRING(0 0,9 9,0 0,9 0,0 0)'),127,'11:33:21','2012-03-31 10:29:22','2012-10-10','2012-04-21 19:21:06',NULL,'05:13:22','09:48:34'),
5693(NULL,PointFromText('POINT(9 0)'),127,'00:00:00','0000-00-00','2012-04-04 21:26:12','2013-03-04',0.0,'12:54:30',NULL),
5694(NULL,PointFromText('POINT(9 0)'),1,'00:00:00','2013-05-01 22:37:49','2013-06-26','2012-09-22 17:31:03',0.0,'08:09:57','11:15:36');
5695Warnings:
5696Note	1265	Data truncated for column 'col286' at row 7
5697CREATE TABLE t2 (b int) ENGINE=Aria;
5698INSERT INTO t2 VALUES (NULL);
5699CREATE TABLE t3 (c int) ENGINE=Aria;
5700INSERT INTO t3 VALUES (NULL);
5701set @@optimizer_switch = 'outer_join_with_cache=on,join_cache_incremental=on';
5702set join_buffer_size=128;
5703EXPLAIN
5704SELECT 1 AS c FROM t1 NATURAL LEFT JOIN t2 LEFT OUTER JOIN t3 ON 1
5705GROUP BY elt(t1.col282,1,t1.col280);
5706id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
57071	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	8	Using temporary; Using filesort
57081	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (flat, BNL join)
57091	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
5710SELECT 1 AS c FROM t1 NATURAL LEFT JOIN t2 LEFT OUTER JOIN t3 ON 1
5711GROUP BY elt(t1.col282,1,t1.col280);
5712c
57131
5714DROP table t1,t2,t3;
5715set join_buffer_size=@save_join_buffer_size;
5716set @@optimizer_switch=@org_optimizer_switch,@local_optimizer_switch= @org_optimizer_switch;
5717#
5718# MDEV-5293: outer join, join buffering, and order by - invalid query plan
5719#
5720create table t0 (a int primary key) engine=myisam;
5721insert into t0 values (1);
5722create table t1(a int) engine=myisam;
5723insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
5724alter table t1 add b int;
5725create table t2 like t1;
5726insert into t2 select * from t1;
5727#The following must use "Using temporary; Using filesort" and not just "Using filesort":
5728explain select * from t0,t1 left join t2 on t1.b=t2.b order by t0.a, t1.a;
5729id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
57301	SIMPLE	t0	system	NULL	NULL	NULL	NULL	1	Using temporary; Using filesort
57311	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	10
57321	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	10	Using where; Using join buffer (flat, BNL join)
5733drop table t0,t1,t2;
5734# MDEV-6292: huge performance degradation for a sequence
5735#            of LEFT JOIN operations when using join buffer
5736#
5737CREATE TABLE t1 (
5738id int(11) NOT NULL AUTO_INCREMENT,
5739col1 varchar(255) NOT NULL DEFAULT '',
5740PRIMARY KEY (id)
5741) ENGINE=INNODB;
5742CREATE TABLE t2 (
5743id int(11) NOT NULL AUTO_INCREMENT,
5744parent_id smallint(3) NOT NULL DEFAULT '0',
5745col2 varchar(25) NOT NULL DEFAULT '',
5746PRIMARY KEY (id)
5747) ENGINE=INNODB;
5748set join_buffer_size=8192;
5749set join_cache_level=0;
5750set @init_time:=now();
5751SELECT t.*
5752FROM
5753t1 t
5754LEFT JOIN t2 c1 ON c1.parent_id = t.id AND c1.col2 = "val"
5755  LEFT JOIN t2 c2 ON c2.parent_id = t.id AND c2.col2 = "val"
5756  LEFT JOIN t2 c3 ON c3.parent_id = t.id AND c3.col2 = "val"
5757  LEFT JOIN t2 c4 ON c4.parent_id = t.id AND c4.col2 = "val"
5758  LEFT JOIN t2 c5 ON c5.parent_id = t.id AND c5.col2 = "val"
5759  LEFT JOIN t2 c6 ON c6.parent_id = t.id AND c6.col2 = "val"
5760  LEFT JOIN t2 c7 ON c7.parent_id = t.id AND c7.col2 = "val"
5761  LEFT JOIN t2 c8 ON c8.parent_id = t.id AND c8.col2 = "val"
5762  LEFT JOIN t2 c9 ON c9.parent_id = t.id AND c9.col2 = "val"
5763  LEFT JOIN t2 c10 ON c10.parent_id = t.id AND c10.col2 = "val"
5764  LEFT JOIN t2 c11 ON c11.parent_id = t.id AND c11.col2 = "val"
5765  LEFT JOIN t2 c12 ON c12.parent_id = t.id AND c12.col2 = "val"
5766  LEFT JOIN t2 c13 ON c13.parent_id = t.id AND c13.col2 = "val"
5767  LEFT JOIN t2 c14 ON c14.parent_id = t.id AND c14.col2 = "val"
5768  LEFT JOIN t2 c15 ON c15.parent_id = t.id AND c15.col2 = "val"
5769  LEFT JOIN t2 c16 ON c16.parent_id = t.id AND c16.col2 = "val"
5770  LEFT JOIN t2 c17 ON c17.parent_id = t.id AND c17.col2 = "val"
5771  LEFT JOIN t2 c18 ON c18.parent_id = t.id AND c18.col2 = "val"
5772  LEFT JOIN t2 c19 ON c19.parent_id = t.id AND c19.col2 = "val"
5773  LEFT JOIN t2 c20 ON c20.parent_id = t.id AND c20.col2 = "val"
5774  LEFT JOIN t2 c21 ON c21.parent_id = t.id AND c21.col2 = "val"
5775  LEFT JOIN t2 c22 ON c22.parent_id = t.id AND c22.col2 = "val"
5776  LEFT JOIN t2 c23 ON c23.parent_id = t.id AND c23.col2 = "val"
5777  LEFT JOIN t2 c24 ON c24.parent_id = t.id AND c24.col2 = "val"
5778  LEFT JOIN t2 c25 ON c25.parent_id = t.id AND c25.col2 = "val"
5779  LEFT JOIN t2 c26 ON c26.parent_id = t.id AND c26.col2 = "val"
5780  LEFT JOIN t2 c27 ON c27.parent_id = t.id AND c27.col2 = "val"
5781ORDER BY
5782col1;
5783id	col1
5784select timestampdiff(second, @init_time, now()) <= 5;
5785timestampdiff(second, @init_time, now()) <= 5
57861
5787set join_cache_level=2;
5788set @init_time:=now();
5789SELECT t.*
5790FROM
5791t1 t
5792LEFT JOIN t2 c1 ON c1.parent_id = t.id AND c1.col2 = "val"
5793  LEFT JOIN t2 c2 ON c2.parent_id = t.id AND c2.col2 = "val"
5794  LEFT JOIN t2 c3 ON c3.parent_id = t.id AND c3.col2 = "val"
5795  LEFT JOIN t2 c4 ON c4.parent_id = t.id AND c4.col2 = "val"
5796  LEFT JOIN t2 c5 ON c5.parent_id = t.id AND c5.col2 = "val"
5797  LEFT JOIN t2 c6 ON c6.parent_id = t.id AND c6.col2 = "val"
5798  LEFT JOIN t2 c7 ON c7.parent_id = t.id AND c7.col2 = "val"
5799  LEFT JOIN t2 c8 ON c8.parent_id = t.id AND c8.col2 = "val"
5800  LEFT JOIN t2 c9 ON c9.parent_id = t.id AND c9.col2 = "val"
5801  LEFT JOIN t2 c10 ON c10.parent_id = t.id AND c10.col2 = "val"
5802  LEFT JOIN t2 c11 ON c11.parent_id = t.id AND c11.col2 = "val"
5803  LEFT JOIN t2 c12 ON c12.parent_id = t.id AND c12.col2 = "val"
5804  LEFT JOIN t2 c13 ON c13.parent_id = t.id AND c13.col2 = "val"
5805  LEFT JOIN t2 c14 ON c14.parent_id = t.id AND c14.col2 = "val"
5806  LEFT JOIN t2 c15 ON c15.parent_id = t.id AND c15.col2 = "val"
5807  LEFT JOIN t2 c16 ON c16.parent_id = t.id AND c16.col2 = "val"
5808  LEFT JOIN t2 c17 ON c17.parent_id = t.id AND c17.col2 = "val"
5809  LEFT JOIN t2 c18 ON c18.parent_id = t.id AND c18.col2 = "val"
5810  LEFT JOIN t2 c19 ON c19.parent_id = t.id AND c19.col2 = "val"
5811  LEFT JOIN t2 c20 ON c20.parent_id = t.id AND c20.col2 = "val"
5812  LEFT JOIN t2 c21 ON c21.parent_id = t.id AND c21.col2 = "val"
5813  LEFT JOIN t2 c22 ON c22.parent_id = t.id AND c22.col2 = "val"
5814  LEFT JOIN t2 c23 ON c23.parent_id = t.id AND c23.col2 = "val"
5815  LEFT JOIN t2 c24 ON c24.parent_id = t.id AND c24.col2 = "val"
5816  LEFT JOIN t2 c25 ON c25.parent_id = t.id AND c25.col2 = "val"
5817  LEFT JOIN t2 c26 ON c26.parent_id = t.id AND c26.col2 = "val"
5818  LEFT JOIN t2 c27 ON c27.parent_id = t.id AND c27.col2 = "val"
5819ORDER BY
5820col1;
5821id	col1
5822select timestampdiff(second, @init_time, now()) <= 5;
5823timestampdiff(second, @init_time, now()) <= 5
58241
5825EXPLAIN
5826SELECT t.*
5827FROM
5828t1 t
5829LEFT JOIN t2 c1 ON c1.parent_id = t.id AND c1.col2 = "val"
5830  LEFT JOIN t2 c2 ON c2.parent_id = t.id AND c2.col2 = "val"
5831  LEFT JOIN t2 c3 ON c3.parent_id = t.id AND c3.col2 = "val"
5832  LEFT JOIN t2 c4 ON c4.parent_id = t.id AND c4.col2 = "val"
5833  LEFT JOIN t2 c5 ON c5.parent_id = t.id AND c5.col2 = "val"
5834  LEFT JOIN t2 c6 ON c6.parent_id = t.id AND c6.col2 = "val"
5835  LEFT JOIN t2 c7 ON c7.parent_id = t.id AND c7.col2 = "val"
5836  LEFT JOIN t2 c8 ON c8.parent_id = t.id AND c8.col2 = "val"
5837  LEFT JOIN t2 c9 ON c9.parent_id = t.id AND c9.col2 = "val"
5838  LEFT JOIN t2 c10 ON c10.parent_id = t.id AND c10.col2 = "val"
5839  LEFT JOIN t2 c11 ON c11.parent_id = t.id AND c11.col2 = "val"
5840  LEFT JOIN t2 c12 ON c12.parent_id = t.id AND c12.col2 = "val"
5841  LEFT JOIN t2 c13 ON c13.parent_id = t.id AND c13.col2 = "val"
5842  LEFT JOIN t2 c14 ON c14.parent_id = t.id AND c14.col2 = "val"
5843  LEFT JOIN t2 c15 ON c15.parent_id = t.id AND c15.col2 = "val"
5844  LEFT JOIN t2 c16 ON c16.parent_id = t.id AND c16.col2 = "val"
5845  LEFT JOIN t2 c17 ON c17.parent_id = t.id AND c17.col2 = "val"
5846  LEFT JOIN t2 c18 ON c18.parent_id = t.id AND c18.col2 = "val"
5847  LEFT JOIN t2 c19 ON c19.parent_id = t.id AND c19.col2 = "val"
5848  LEFT JOIN t2 c20 ON c20.parent_id = t.id AND c20.col2 = "val"
5849  LEFT JOIN t2 c21 ON c21.parent_id = t.id AND c21.col2 = "val"
5850  LEFT JOIN t2 c22 ON c22.parent_id = t.id AND c22.col2 = "val"
5851  LEFT JOIN t2 c23 ON c23.parent_id = t.id AND c23.col2 = "val"
5852  LEFT JOIN t2 c24 ON c24.parent_id = t.id AND c24.col2 = "val"
5853  LEFT JOIN t2 c25 ON c25.parent_id = t.id AND c25.col2 = "val"
5854  LEFT JOIN t2 c26 ON c26.parent_id = t.id AND c26.col2 = "val"
5855  LEFT JOIN t2 c27 ON c27.parent_id = t.id AND c27.col2 = "val"
5856ORDER BY
5857col1;
5858id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
58591	SIMPLE	t	ALL	NULL	NULL	NULL	NULL	1	Using temporary; Using filesort
58601	SIMPLE	c1	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (flat, BNL join)
58611	SIMPLE	c2	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58621	SIMPLE	c3	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58631	SIMPLE	c4	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58641	SIMPLE	c5	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58651	SIMPLE	c6	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58661	SIMPLE	c7	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58671	SIMPLE	c8	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58681	SIMPLE	c9	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58691	SIMPLE	c10	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58701	SIMPLE	c11	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58711	SIMPLE	c12	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58721	SIMPLE	c13	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58731	SIMPLE	c14	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58741	SIMPLE	c15	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58751	SIMPLE	c16	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58761	SIMPLE	c17	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58771	SIMPLE	c18	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58781	SIMPLE	c19	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58791	SIMPLE	c20	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58801	SIMPLE	c21	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58811	SIMPLE	c22	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58821	SIMPLE	c23	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58831	SIMPLE	c24	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58841	SIMPLE	c25	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58851	SIMPLE	c26	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
58861	SIMPLE	c27	ALL	NULL	NULL	NULL	NULL	1	Using where; Using join buffer (incremental, BNL join)
5887set join_buffer_size=@save_join_buffer_size;
5888set join_cache_level=@save_join_cache_level;
5889DROP TABLE t1,t2;
5890#
5891# MDEV-14960: BNLH used for materialized semi-join
5892#
5893CREATE TABLE t1 (i1 int);
5894CREATE TABLE t2 (e1 int);
5895CREATE TABLE t4 (e1 int);
5896CREATE TABLE t5 (e1 int);
5897INSERT INTO t1 VALUES
5898(1),(2),(3),(4),(5),(6),(7),(8);
5899INSERT INTO t1 SELECT i1+8 FROM t1;
5900INSERT INTO t1 SELECT i1+16 FROM t1;
5901INSERT INTO t1 SELECT i1+32 FROM t1;
5902INSERT INTO t1 SELECT i1+64 FROM t1;
5903INSERT INTO t2 SELECT * FROM t1;
5904INSERT INTO t4 SELECT * FROM t1;
5905INSERT INTO t5 SELECT * FROM t1;
5906SET join_cache_level = 6;
5907SET join_buffer_size=4096;
5908SET join_buffer_space_limit=4096;
5909set @@optimizer_switch = 'join_cache_hashed=on,optimize_join_buffer_size=on';
5910EXPLAIN SELECT * FROM t1
5911WHERE
5912i1 < 10 AND
5913i1 IN
5914(SELECT i1 FROM
5915(SELECT  (t4.e1) i1  FROM   t4
5916LEFT JOIN t5  ON t4.e1 = t5.e1
5917LEFT JOIN  (SELECT e1  FROM t2 ) AS d ON  t4.e1 = d.e1) a);
5918id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
59191	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	128	Using where
59201	PRIMARY	<subquery2>	eq_ref	distinct_key	distinct_key	4	func	1
59212	MATERIALIZED	t4	ALL	NULL	NULL	NULL	NULL	128
59222	MATERIALIZED	t5	hash_ALL	NULL	#hash#$hj	5	test.t4.e1	128	Using where; Using join buffer (flat, BNLH join)
59232	MATERIALIZED	t2	hash_ALL	NULL	#hash#$hj	5	test.t4.e1	128	Using where; Using join buffer (incremental, BNLH join)
5924SELECT * FROM t1
5925WHERE
5926i1 < 10 AND
5927i1 IN
5928(SELECT i1 FROM
5929(SELECT  (t4.e1) i1  FROM   t4
5930LEFT JOIN t5  ON t4.e1 = t5.e1
5931LEFT JOIN  (SELECT e1  FROM t2 ) AS d ON  t4.e1 = d.e1) a);
5932i1
59331
59342
59353
59364
59375
59386
59397
59408
59419
5942set join_cache_level=@save_join_cache_level;
5943SET join_buffer_size=@save_join_buffer_size;
5944SET join_buffer_space_limit=@save_join_buffer_space_limit;
5945set @@optimizer_switch=@local_optimizer_switch;
5946DROP TABLE t1,t4,t5,t2;
5947#
5948# MDEV-16603: BNLH for query with materialized semi-join
5949#
5950set join_cache_level=4;
5951CREATE TABLE t1 ( i1 int, v1 varchar(1)) ENGINE=InnoDB;
5952INSERT INTO t1 VALUES (7,'x');
5953CREATE TABLE t2 (i1 int, v1 varchar(1), KEY v1 (v1,i1)) ENGINE=InnoDB;
5954INSERT INTO t2 VALUES
5955(NULL,'x'),(1,'x'),(3,'x'),(5,'x'),(8,'x'),(48,'x'),
5956(228,'x'),(3,'y'),(1,'z'),(9,'z');
5957ANALYZE TABLE t1,t2;
5958Table	Op	Msg_type	Msg_text
5959test.t1	analyze	status	Engine-independent statistics collected
5960test.t1	analyze	status	OK
5961test.t2	analyze	status	Engine-independent statistics collected
5962test.t2	analyze	status	OK
5963CREATE TABLE temp
5964SELECT t1.i1 AS f1, t1.v1 AS f2 FROM (t2 JOIN t1 ON (t1.v1 = t2.v1));
5965SELECT * FROM temp
5966WHERE (f1,f2) IN (SELECT t1.i1, t1.v1 FROM (t2 JOIN t1 ON (t1.v1 = t2.v1)));
5967f1	f2
59687	x
59697	x
59707	x
59717	x
59727	x
59737	x
59747	x
5975EXPLAIN EXTENDED SELECT * FROM temp
5976WHERE (f1,f2) IN (SELECT t1.i1, t1.v1 FROM (t2 JOIN t1 ON (t1.v1 = t2.v1)));
5977id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
59781	PRIMARY	<subquery2>	ALL	distinct_key	NULL	NULL	NULL	1	100.00
59791	PRIMARY	temp	hash_ALL	NULL	#hash#$hj	9	test.t1.i1,test.t1.v1	7	100.00	Using where; Using join buffer (flat, BNLH join)
59802	MATERIALIZED	t1	ALL	NULL	NULL	NULL	NULL	1	100.00	Using where
59812	MATERIALIZED	t2	hash_index	v1	#hash#v1:v1	4:9	test.t1.v1	10	33.33	Using index; Using join buffer (flat, BNLH join)
5982Warnings:
5983Note	1003	select `test`.`temp`.`f1` AS `f1`,`test`.`temp`.`f2` AS `f2` from `test`.`temp` semi join (`test`.`t2` join `test`.`t1`) where `test`.`temp`.`f1` = `test`.`t1`.`i1` and `test`.`t2`.`v1` = `test`.`t1`.`v1` and `test`.`temp`.`f2` = `test`.`t1`.`v1`
5984DROP TABLE t1,t2,temp;
5985set join_cache_level=@save_join_cache_level;
5986#
5987# MDEV-5123 Remove duplicated conditions pushed both to join_tab->select_cond and join_tab->cache_select->cond for blocked joins.
5988#
5989set expensive_subquery_limit=0;
5990create table t1 (c1 int);
5991create table t2 (c2 int);
5992create table t3 (c3 int);
5993insert into t1 values (1), (2);
5994insert into t2 values (1), (2);
5995insert into t3 values (2);
5996explain
5997select count(*) from t1 straight_join t2
5998where c1 = c2-0 and c2 <= (select max(c3) from t3 where c3 = 2 and @counter:=@counter+1);
5999id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
60001	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2
60011	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	2	Using where; Using join buffer (flat, BNL join)
60022	UNCACHEABLE SUBQUERY	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Impossible WHERE
6003set @counter=0;
6004select count(*) from t1 straight_join t2
6005where c1 = c2-0 and c2 <= (select max(c3) from t3 where c3 = 2 and @counter:=@counter+1);
6006count(*)
60072
6008select @counter;
6009@counter
60102
6011explain
6012select count(*) from t1 straight_join t2
6013where c1 = c2-0 and
6014c2 <= (select max(c3) from t3 where c3 = 2 and @counter:=@counter+1) and
6015c2 / 2 = 1;
6016id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
60171	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2
60181	PRIMARY	t2	ALL	NULL	NULL	NULL	NULL	2	Using where; Using join buffer (flat, BNL join)
60192	UNCACHEABLE SUBQUERY	t3	system	NULL	NULL	NULL	NULL	1
6020set @counter=0;
6021select count(*) from t1 straight_join t2
6022where c1 = c2-0 and
6023c2 <= (select max(c3) from t3 where c3 = 2 and @counter:=@counter+1) and
6024c2 / 2 = 1;
6025count(*)
60261
6027select @counter;
6028@counter
60292
6030drop table t1,t2,t3;
6031set expensive_subquery_limit=@save_expensive_subquery_limit;
6032#
6033# MDEV-6071: EXPLAIN chooses to use join buffer while execution turns it down
6034#
6035create table t1 (a int);
6036insert into t1 values
6037(7), (9), (1), (4), (2), (3), (5), (8), (11), (6), (10);
6038explain select count(*) from t1, t1 t2 where t1.a=t2.a;
6039id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
60401	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	11
60411	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	11	Using where; Using join buffer (flat, BNL join)
6042set join_buffer_space_limit=1024*8;
6043explain select count(*) from t1, t1 t2 where t1.a=t2.a;
6044id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
60451	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	11
60461	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	11	Using where; Using join buffer (flat, BNL join)
6047set join_buffer_space_limit=@save_join_buffer_space_limit;
6048drop table t1;
6049#
6050# MDEV-6687: Assertion `0' failed in Protocol::end_statement on query
6051#
6052SET join_cache_level = 3;
6053# The following should have
6054#  - table order PROFILING,user,
6055#  - table db accessed with hash_ALL:
6056explain
6057SELECT * FROM INFORMATION_SCHEMA.PROFILING, mysql.db WHERE Select_priv = PAGE_FAULTS_MINOR;
6058id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
60591	SIMPLE	PROFILING	ALL	NULL	NULL	NULL	NULL	NULL	Using where
60601	SIMPLE	db	hash_ALL	NULL	#hash#$hj	1	information_schema.PROFILING.PAGE_FAULTS_MINOR	2	Using where; Using join buffer (flat, BNLH join)
6061set join_cache_level=@save_join_cache_level;
6062create table t1 (c1 date not null, key (c1)) engine=innodb;
6063insert t1 values ('2017-12-27');
6064create table t2 (pk int, f1 int, f2 int);
6065insert t2 values (4,1,1), (6,1,1);
6066set join_buffer_size = 222222208;
6067select f2 from t2,t1 where f2 = 0;
6068f2
6069drop table t1, t2;
6070set join_buffer_size=@save_join_buffer_size;
6071#
6072# MDEV-21104: BNLH used for multi-join query with embedded outer join
6073#             and possible 'not exists' optimization
6074#
6075set join_cache_level=4;
6076CREATE TABLE t1 (a int) ENGINE=MyISAM;
6077INSERT INTO t1 VALUES (1),(2);
6078CREATE TABLE t2 (b int, c int) ENGINE=MyISAM;
6079INSERT INTO t2 VALUES  (1,2),(2,4);
6080CREATE TABLE t3 (d int, KEY(d)) ENGINE=MyISAM;
6081INSERT INTO t3 VALUES (1),(2);
6082CREATE TABLE t4 (e int primary key) ENGINE=MyISAM;
6083INSERT INTO t4 VALUES (1),(2);
6084ANALYZE TABLE t1,t2,t3,t4;
6085Table	Op	Msg_type	Msg_text
6086test.t1	analyze	status	Engine-independent statistics collected
6087test.t1	analyze	status	OK
6088test.t2	analyze	status	Engine-independent statistics collected
6089test.t2	analyze	status	OK
6090test.t3	analyze	status	Engine-independent statistics collected
6091test.t3	analyze	status	OK
6092test.t4	analyze	status	Engine-independent statistics collected
6093test.t4	analyze	status	OK
6094SELECT * FROM t2 LEFT JOIN t3 ON c = d;
6095b	c	d
60961	2	2
60972	4	NULL
6098SELECT * FROM (t2 LEFT JOIN t3 ON c = d ) JOIN t4;
6099b	c	d	e
61001	2	2	1
61012	4	NULL	1
61021	2	2	2
61032	4	NULL	2
6104EXPLAIN SELECT * FROM t1 LEFT JOIN ( ( t2 LEFT JOIN t3 ON c = d ) JOIN t4 ) ON b = e;
6105id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
61061	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2
61071	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	2	Using where; Using join buffer (flat, BNL join)
61081	SIMPLE	t3	hash_index	d	#hash#d:d	5:5	test.t2.c	2	Using where; Using index; Using join buffer (incremental, BNLH join)
61091	SIMPLE	t4	hash_index	PRIMARY	#hash#PRIMARY:PRIMARY	4:4	test.t2.b	2	Using index; Using join buffer (incremental, BNLH join)
6110SELECT * FROM t1 LEFT JOIN ( ( t2 LEFT JOIN t3 ON c = d ) JOIN t4 ) ON b = e;
6111a	b	c	d	e
61121	1	2	2	1
61132	1	2	2	1
61141	2	4	NULL	2
61152	2	4	NULL	2
6116EXPLAIN SELECT * FROM t1 LEFT JOIN ( ( t2 LEFT JOIN t3 ON c = d ) JOIN t4 ) ON b = e
6117WHERE e IS NULL;
6118id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
61191	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2
61201	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	2	Using where; Using join buffer (flat, BNL join)
61211	SIMPLE	t3	hash_index	d	#hash#d:d	5:5	test.t2.c	2	Using where; Using index; Using join buffer (incremental, BNLH join)
61221	SIMPLE	t4	hash_index	PRIMARY	#hash#PRIMARY:PRIMARY	4:4	test.t2.b	2	Using where; Using index; Not exists; Using join buffer (incremental, BNLH join)
6123SELECT * FROM t1 LEFT JOIN ( ( t2 LEFT JOIN t3 ON c = d ) JOIN t4 ) ON b = e
6124WHERE e IS NULL;
6125a	b	c	d	e
6126DROP TABLE t1,t2,t3,t4;
6127set join_cache_level=@save_join_cache_level;
6128#
6129# MDEV-24767: forced BNLH used for equi-join supported by compound index
6130#
6131create table t1 (a int, b int, c int ) engine=myisam ;
6132create table t2 (a int, b int, c int, primary key (c,a,b)) engine=myisam ;
6133insert into t1 values (3,4,2), (5,6,4);
6134insert into t2 values (3,4,2), (5,6,4);
6135select t1.a, t1.b, t1.c from t1,t2
6136where t2.a = t1.a and t2.b = t1.b and t2.c=t1.c;
6137a	b	c
61383	4	2
61395	6	4
6140explain select t1.a, t1.b, t1.c from t1,t2
6141where t2.a = t1.a and t2.b = t1.b and t2.c=t1.c;
6142id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
61431	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	Using where
61441	SIMPLE	t2	eq_ref	PRIMARY	PRIMARY	12	test.t1.c,test.t1.a,test.t1.b	1	Using index
6145set join_cache_level=3;
6146select t1.a, t1.b, t1.c from t1,t2
6147where t2.a = t1.a and t2.b = t1.b and t2.c=t1.c;
6148a	b	c
61493	4	2
61505	6	4
6151explain select t1.a, t1.b, t1.c from t1,t2
6152where t2.a = t1.a and t2.b = t1.b and t2.c=t1.c;
6153id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
61541	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	Using where
61551	SIMPLE	t2	hash_index	PRIMARY	#hash#PRIMARY:PRIMARY	12:12	test.t1.c,test.t1.a,test.t1.b	2	Using index; Using join buffer (flat, BNLH join)
6156drop table t1,t2;
6157set join_cache_level=@save_join_cache_level;
6158#
6159# MDEV-21243: Join buffer: condition is checked in wrong place for range access
6160#
6161create table t1(a int primary key);
6162insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
6163create table t2 (a int);
6164insert into t2 select A.a + 10*B.a from t1 A, t1 B;
6165create table t3 (
6166kp1 int,
6167kp2 int,
6168col1 int,
6169col2 int,
6170key (kp1, kp2)
6171);
6172insert into t3
6173select
6174A.a,
6175B.a,
6176A.a + 100*B.a,
6177A.a + 100*B.a
6178from
6179t2 A, t2 B;
6180analyze table t3;
6181Table	Op	Msg_type	Msg_text
6182test.t3	analyze	status	Engine-independent statistics collected
6183test.t3	analyze	status	Table is already up to date
6184# The following must have "B.col1 + 1 < 33333" attached to table B
6185# and not to the block-nl-join node:
6186explain format=json
6187select *
6188from t1 a, t3 b
6189where
6190b.kp1=a.a and
6191b.kp1 <= 10 and
6192b.kp2 <= 10 and
6193b.col1 +1 < 33333;
6194EXPLAIN
6195{
6196  "query_block": {
6197    "select_id": 1,
6198    "table": {
6199      "table_name": "a",
6200      "access_type": "index",
6201      "possible_keys": ["PRIMARY"],
6202      "key": "PRIMARY",
6203      "key_length": "4",
6204      "used_key_parts": ["a"],
6205      "rows": 10,
6206      "filtered": 100,
6207      "attached_condition": "a.a <= 10",
6208      "using_index": true
6209    },
6210    "block-nl-join": {
6211      "table": {
6212        "table_name": "b",
6213        "access_type": "range",
6214        "possible_keys": ["kp1"],
6215        "key": "kp1",
6216        "key_length": "10",
6217        "used_key_parts": ["kp1", "kp2"],
6218        "rows": 836,
6219        "filtered": 76.434,
6220        "index_condition": "b.kp2 <= 10",
6221        "attached_condition": "b.kp2 <= 10 and b.col1 + 1 < 33333"
6222      },
6223      "buffer_type": "flat",
6224      "buffer_size": "54",
6225      "join_type": "BNL",
6226      "attached_condition": "b.kp1 = a.a"
6227    }
6228  }
6229}
6230drop table t1,t2,t3;
6231# End of 10.3 tests
6232set @@optimizer_switch=@save_optimizer_switch;
6233set global innodb_stats_persistent= @innodb_stats_persistent_save;
6234set global innodb_stats_persistent_sample_pages=
6235@innodb_stats_persistent_sample_pages_save;
6236