List:Commits« Previous MessageNext Message »
From:igor Date:April 6 2008 9:20am
Subject:bk commit into 6.0 tree (igor:1.2608)
View as plain text  
Below is the list of changes that have just been committed into a local
6.0 repository of igor.  When igor does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2008-04-06 00:20:43-07:00, igor@stripped +11 -0
  Completed the function check_join_cache_usage taht determines
  whether a join buffer can be used to access a join table.
  
  Fixed many minor bugs/typos that made the code non-functional in many cases.
  
  Fixed a bug that caused serious problems with linking records: introduced
  the curr_rec_link member to JOIN_CACHE.
  

  mysql-test/r/index_merge_myisam.result@stripped, 2008-04-06 00:20:36-07:00,
igor@stripped +0 -2
    Adjusted test result after changing the lower limit for join_buffer_size.

  mysql-test/r/join_cache.result@stripped, 2008-04-06 00:20:36-07:00, igor@stripped +1076
-0
    Added new test cases.

  mysql-test/r/join_nested_jcl6.result@stripped, 2008-04-05 23:35:11-07:00, igor@stripped
+1756 -0
    BitKeeper file
/home/igor/dev-opt/mysql-6.0-bka-preview/mysql-test/r/join_nested_jcl6.result

  mysql-test/r/join_nested_jcl6.result@stripped, 2008-04-05 23:35:11-07:00, igor@stripped
+0 -0

  mysql-test/r/subselect_sj2.result@stripped, 2008-04-06 00:20:37-07:00, igor@stripped +0
-4
    Adjusted test result after changing the lower limit for join_buffer_size.

  mysql-test/suite/falcon/r/falcon_select.result@stripped, 2008-04-06 00:20:37-07:00,
igor@stripped +10 -10
    Adjusted results that should been adjusted before the commit with the BKA code.

  mysql-test/suite/ndb/r/ndb_condition_pushdown.result@stripped, 2008-04-06 00:20:37-07:00,
igor@stripped +1 -1
    Adjusted results.

  mysql-test/t/join_cache.test@stripped, 2008-04-06 00:20:37-07:00, igor@stripped +219 -0
    Added test cases.

  mysql-test/t/join_nested_jcl6.test@stripped, 2008-04-05 23:34:57-07:00, igor@stripped
+11 -0
    BitKeeper file
/home/igor/dev-opt/mysql-6.0-bka-preview/mysql-test/t/join_nested_jcl6.test

  mysql-test/t/join_nested_jcl6.test@stripped, 2008-04-05 23:34:57-07:00, igor@stripped
+0 -0

  sql/handler.cc@stripped, 2008-04-06 00:20:37-07:00, igor@stripped +1 -1
    Removed a warning.

  sql/sql_select.cc@stripped, 2008-04-06 00:20:37-07:00, igor@stripped +137 -55
    Completed the function check_join_cache_usage taht determines
    whether a join buffer can be used to access a join table.
    
    Fixed many minor bugs/typos that made the code non-functional in many cases.
    
    Fixed a bug that caused serious problems with linking records: introduced
    the curr_rec_link member to JOIN_CACHE.
    
    Used the flag HA_MRR_SEMI_JOIN when appropriate that tells the MRR interface 
    not to fetch a row with a given association if there is a match for the
    associated record.

  sql/sql_select.h@stripped, 2008-04-06 00:20:37-07:00, igor@stripped +38 -5
    Fixed a bug that caused serious problems with linking records: introduced
    the curr_rec_link member to JOIN_CACHE.
    
    The value of mrr_mode must be received from the call of multi_range_read_info 
    and passed to the cache constructor.

diff -Nrup a/mysql-test/r/index_merge_myisam.result
b/mysql-test/r/index_merge_myisam.result
--- a/mysql-test/r/index_merge_myisam.result	2008-01-10 14:04:52 -08:00
+++ b/mysql-test/r/index_merge_myisam.result	2008-04-06 00:20:36 -07:00
@@ -342,8 +342,6 @@ create table t4 (a int);
 insert into t4 values (1),(4),(3);
 set @save_join_buffer_size=@@join_buffer_size;
 set join_buffer_size= 4000;
-Warnings:
-Warning	1292	Truncated incorrect join_buffer_size value: '4000'
 explain select max(A.key1 + B.key1 + A.key2 + B.key2 + A.key3 + B.key3 + A.key4 + B.key4
+ A.key5 + B.key5)
 from t0 as A force index(i1,i2), t0 as B force index (i1,i2)
 where (A.key1 < 500000 or A.key2 < 3)
diff -Nrup a/mysql-test/r/join_cache.result b/mysql-test/r/join_cache.result
--- a/mysql-test/r/join_cache.result	2008-03-31 22:22:55 -07:00
+++ b/mysql-test/r/join_cache.result	2008-04-06 00:20:36 -07:00
@@ -698,3 +698,1079 @@ Variable_name	Value
 join_buffer_size	131072
 Variable_name	Value
 join_cache_level	1
+Variable_name	Value
+join_buffer_size	131072
+Variable_name	Value
+join_cache_level	5
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Using MRR
+1	SIMPLE	City	ref	Population,Country	Country	3	world.Country.Code	8	Using where; Using
join buffer
+Name	Name
+Vientiane	Laos
+Riga	Latvia
+Daugavpils	Latvia
+Maseru	Lesotho
+Beirut	Lebanon
+Tripoli	Lebanon
+Monrovia	Liberia
+Tripoli	Libyan Arab Jamahiriya
+Bengasi	Libyan Arab Jamahiriya
+Misrata	Libyan Arab Jamahiriya
+Vilnius	Lithuania
+Kaunas	Lithuania
+Klaipeda	Lithuania
+?iauliai	Lithuania
+Panevezys	Lithuania
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	CountryLanguage	ALL	PRIMARY,Percentage	NULL	NULL	NULL	984	Using where
+1	SIMPLE	Country	eq_ref	PRIMARY	PRIMARY	3	world.CountryLanguage.Country	1	Using where;
Using join buffer
+1	SIMPLE	City	ref	Country	Country	3	world.Country.Code	8	Using where; Using join buffer
+Name	Name	Language
+Leiden	Netherlands	Dutch
+La Matanza	Argentina	Spanish
+Lomas de Zamora	Argentina	Spanish
+La Plata	Argentina	Spanish
+Lanús	Argentina	Spanish
+Las Heras	Argentina	Spanish
+La Rioja	Argentina	Spanish
+Liège	Belgium	Dutch
+La Paz	Bolivia	Spanish
+Londrina	Brazil	Portuguese
+Limeira	Brazil	Portuguese
+Lages	Brazil	Portuguese
+Luziânia	Brazil	Portuguese
+Lauro de Freitas	Brazil	Portuguese
+Linhares	Brazil	Portuguese
+London	United Kingdom	English
+Liverpool	United Kingdom	English
+Leeds	United Kingdom	English
+Leicester	United Kingdom	English
+Luton	United Kingdom	English
+Los Angeles	Chile	Spanish
+La Serena	Chile	Spanish
+La Romana	Dominican Republic	Spanish
+Loja	Ecuador	Spanish
+Luxor	Egypt	Arabic
+Las Palmas de Gran Canaria	Spain	Spanish
+L´Hospitalet de Llobregat	Spain	Spanish
+Leganés	Spain	Spanish
+León	Spain	Spanish
+Logroño	Spain	Spanish
+Lleida (Lérida)	Spain	Spanish
+Le-Cap-Haïtien	Haiti	Haiti Creole
+La Ceiba	Honduras	Spanish
+Livorno	Italy	Italian
+Latina	Italy	Italian
+Lecce	Italy	Italian
+La Spezia	Italy	Italian
+Linz	Austria	German
+London	Canada	English
+Laval	Canada	English
+Longueuil	Canada	English
+Lanzhou	China	Chinese
+Luoyang	China	Chinese
+Liuzhou	China	Chinese
+Liaoyang	China	Chinese
+Liupanshui	China	Chinese
+Liaoyuan	China	Chinese
+Lianyungang	China	Chinese
+Leshan	China	Chinese
+Linyi	China	Chinese
+Luzhou	China	Chinese
+Laiwu	China	Chinese
+Liaocheng	China	Chinese
+Laizhou	China	Chinese
+Linfen	China	Chinese
+Liangcheng	China	Chinese
+Longkou	China	Chinese
+Langfang	China	Chinese
+Liu´an	China	Chinese
+Longjing	China	Chinese
+Lengshuijiang	China	Chinese
+Laiyang	China	Chinese
+Longyan	China	Chinese
+Linhe	China	Chinese
+Leiyang	China	Chinese
+Loudi	China	Chinese
+Luohe	China	Chinese
+Linqing	China	Chinese
+Laohekou	China	Chinese
+Linchuan	China	Chinese
+Lhasa	China	Chinese
+Lianyuan	China	Chinese
+Liyang	China	Chinese
+Liling	China	Chinese
+Linhai	China	Chinese
+Larisa	Greece	Greek
+La Habana	Cuba	Spanish
+Lilongwe	Malawi	Chichewa
+León	Mexico	Spanish
+La Paz	Mexico	Spanish
+La Paz	Mexico	Spanish
+Lázaro Cárdenas	Mexico	Spanish
+Lagos de Moreno	Mexico	Spanish
+Lerdo	Mexico	Spanish
+Los Cabos	Mexico	Spanish
+Lerma	Mexico	Spanish
+Las Margaritas	Mexico	Spanish
+Lashio (Lasho)	Myanmar	Burmese
+Lalitapur	Nepal	Nepali
+León	Nicaragua	Spanish
+Lambaré	Paraguay	Spanish
+Lima	Peru	Spanish
+Lisboa	Portugal	Portuguese
+Lódz	Poland	Polish
+Lublin	Poland	Polish
+Legnica	Poland	Polish
+Lyon	France	French
+Le Havre	France	French
+Lille	France	French
+Le Mans	France	French
+Limoges	France	French
+Linköping	Sweden	Swedish
+Lund	Sweden	Swedish
+Leipzig	Germany	German
+Lübeck	Germany	German
+Ludwigshafen am Rhein	Germany	German
+Leverkusen	Germany	German
+Lünen	Germany	German
+Lahti	Finland	Finnish
+Lausanne	Switzerland	German
+Latakia	Syria	Arabic
+Luchou	Taiwan	Min
+Lungtan	Taiwan	Min
+Liberec	Czech Republic	Czech
+Lviv	Ukraine	Ukrainian
+Lugansk	Ukraine	Ukrainian
+Lutsk	Ukraine	Ukrainian
+Lysyt?ansk	Ukraine	Ukrainian
+Lower Hutt	New Zealand	English
+Lida	Belarus	Belorussian
+Los Teques	Venezuela	Spanish
+Lipetsk	Russian Federation	Russian
+Ljubertsy	Russian Federation	Russian
+Leninsk-Kuznetski	Russian Federation	Russian
+Long Xuyen	Vietnam	Vietnamese
+Los Angeles	United States	English
+Las Vegas	United States	English
+Long Beach	United States	English
+Lexington-Fayette	United States	English
+Louisville	United States	English
+Lincoln	United States	English
+Lubbock	United States	English
+Little Rock	United States	English
+Laredo	United States	English
+Lakewood	United States	English
+Lansing	United States	English
+Lancaster	United States	English
+Lafayette	United States	English
+Lowell	United States	English
+Livonia	United States	English
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	Country	ALL	PRIMARY,Name	NULL	NULL	NULL	239	Using where
+1	PRIMARY	City	ref	Population,Country	Country	3	world.Country.Code	8	Using where; Using
join buffer
+Name
+Vientiane
+Riga
+Daugavpils
+Maseru
+Beirut
+Tripoli
+Monrovia
+Tripoli
+Bengasi
+Misrata
+Vilnius
+Kaunas
+Klaipeda
+?iauliai
+Panevezys
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
+1	SIMPLE	CountryLanguage	eq_ref	PRIMARY	PRIMARY	33	world.Country.Code,const	1	Using
where; Using join buffer
+Name	IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
+Australia	81.2
+United Kingdom	97.3
+Canada	60.4
+United States	86.2
+Zimbabwe	2.2
+Japan	0.1
+South Africa	8.5
+Malaysia	1.6
+Afghanistan	NULL
+Netherlands	NULL
+Algeria	NULL
+Angola	NULL
+Argentina	NULL
+Bangladesh	NULL
+Belgium	NULL
+Brazil	NULL
+Burkina Faso	NULL
+Chile	NULL
+Ecuador	NULL
+Egypt	NULL
+Spain	NULL
+Ethiopia	NULL
+Philippines	NULL
+Ghana	NULL
+Guatemala	NULL
+Indonesia	NULL
+India	NULL
+Iraq	NULL
+Iran	NULL
+Italy	NULL
+Yemen	NULL
+Yugoslavia	NULL
+Cambodia	NULL
+Cameroon	NULL
+Kazakstan	NULL
+Kenya	NULL
+China	NULL
+Colombia	NULL
+Congo, The Democratic Republic of the	NULL
+North Korea	NULL
+South Korea	NULL
+Greece	NULL
+Cuba	NULL
+Madagascar	NULL
+Malawi	NULL
+Mali	NULL
+Morocco	NULL
+Mexico	NULL
+Mozambique	NULL
+Myanmar	NULL
+Nepal	NULL
+Niger	NULL
+Nigeria	NULL
+Côte d?Ivoire	NULL
+Pakistan	NULL
+Peru	NULL
+Poland	NULL
+France	NULL
+Romania	NULL
+Germany	NULL
+Saudi Arabia	NULL
+Somalia	NULL
+Sri Lanka	NULL
+Sudan	NULL
+Syria	NULL
+Taiwan	NULL
+Tanzania	NULL
+Thailand	NULL
+Czech Republic	NULL
+Turkey	NULL
+Uganda	NULL
+Ukraine	NULL
+Hungary	NULL
+Uzbekistan	NULL
+Belarus	NULL
+Venezuela	NULL
+Russian Federation	NULL
+Vietnam	NULL
+Variable_name	Value
+join_cache_level	6
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Using MRR
+1	SIMPLE	City	ref	Population,Country	Country	3	world.Country.Code	8	Using where; Using
join buffer
+Name	Name
+Vientiane	Laos
+Riga	Latvia
+Daugavpils	Latvia
+Maseru	Lesotho
+Beirut	Lebanon
+Tripoli	Lebanon
+Monrovia	Liberia
+Tripoli	Libyan Arab Jamahiriya
+Bengasi	Libyan Arab Jamahiriya
+Misrata	Libyan Arab Jamahiriya
+Vilnius	Lithuania
+Kaunas	Lithuania
+Klaipeda	Lithuania
+?iauliai	Lithuania
+Panevezys	Lithuania
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	CountryLanguage	ALL	PRIMARY,Percentage	NULL	NULL	NULL	984	Using where
+1	SIMPLE	Country	eq_ref	PRIMARY	PRIMARY	3	world.CountryLanguage.Country	1	Using where;
Using join buffer
+1	SIMPLE	City	ref	Country	Country	3	world.Country.Code	8	Using where; Using join buffer
+Name	Name	Language
+Leiden	Netherlands	Dutch
+La Matanza	Argentina	Spanish
+Lomas de Zamora	Argentina	Spanish
+La Plata	Argentina	Spanish
+Lanús	Argentina	Spanish
+Las Heras	Argentina	Spanish
+La Rioja	Argentina	Spanish
+Liège	Belgium	Dutch
+La Paz	Bolivia	Spanish
+Londrina	Brazil	Portuguese
+Limeira	Brazil	Portuguese
+Lages	Brazil	Portuguese
+Luziânia	Brazil	Portuguese
+Lauro de Freitas	Brazil	Portuguese
+Linhares	Brazil	Portuguese
+London	United Kingdom	English
+Liverpool	United Kingdom	English
+Leeds	United Kingdom	English
+Leicester	United Kingdom	English
+Luton	United Kingdom	English
+Los Angeles	Chile	Spanish
+La Serena	Chile	Spanish
+La Romana	Dominican Republic	Spanish
+Loja	Ecuador	Spanish
+Luxor	Egypt	Arabic
+Las Palmas de Gran Canaria	Spain	Spanish
+L´Hospitalet de Llobregat	Spain	Spanish
+Leganés	Spain	Spanish
+León	Spain	Spanish
+Logroño	Spain	Spanish
+Lleida (Lérida)	Spain	Spanish
+Le-Cap-Haïtien	Haiti	Haiti Creole
+La Ceiba	Honduras	Spanish
+Livorno	Italy	Italian
+Latina	Italy	Italian
+Lecce	Italy	Italian
+La Spezia	Italy	Italian
+Linz	Austria	German
+London	Canada	English
+Laval	Canada	English
+Longueuil	Canada	English
+Lanzhou	China	Chinese
+Luoyang	China	Chinese
+Liuzhou	China	Chinese
+Liaoyang	China	Chinese
+Liupanshui	China	Chinese
+Liaoyuan	China	Chinese
+Lianyungang	China	Chinese
+Leshan	China	Chinese
+Linyi	China	Chinese
+Luzhou	China	Chinese
+Laiwu	China	Chinese
+Liaocheng	China	Chinese
+Laizhou	China	Chinese
+Linfen	China	Chinese
+Liangcheng	China	Chinese
+Longkou	China	Chinese
+Langfang	China	Chinese
+Liu´an	China	Chinese
+Longjing	China	Chinese
+Lengshuijiang	China	Chinese
+Laiyang	China	Chinese
+Longyan	China	Chinese
+Linhe	China	Chinese
+Leiyang	China	Chinese
+Loudi	China	Chinese
+Luohe	China	Chinese
+Linqing	China	Chinese
+Laohekou	China	Chinese
+Linchuan	China	Chinese
+Lhasa	China	Chinese
+Lianyuan	China	Chinese
+Liyang	China	Chinese
+Liling	China	Chinese
+Linhai	China	Chinese
+Larisa	Greece	Greek
+La Habana	Cuba	Spanish
+Lilongwe	Malawi	Chichewa
+León	Mexico	Spanish
+La Paz	Mexico	Spanish
+La Paz	Mexico	Spanish
+Lázaro Cárdenas	Mexico	Spanish
+Lagos de Moreno	Mexico	Spanish
+Lerdo	Mexico	Spanish
+Los Cabos	Mexico	Spanish
+Lerma	Mexico	Spanish
+Las Margaritas	Mexico	Spanish
+Lashio (Lasho)	Myanmar	Burmese
+Lalitapur	Nepal	Nepali
+León	Nicaragua	Spanish
+Lambaré	Paraguay	Spanish
+Lima	Peru	Spanish
+Lisboa	Portugal	Portuguese
+Lódz	Poland	Polish
+Lublin	Poland	Polish
+Legnica	Poland	Polish
+Lyon	France	French
+Le Havre	France	French
+Lille	France	French
+Le Mans	France	French
+Limoges	France	French
+Linköping	Sweden	Swedish
+Lund	Sweden	Swedish
+Leipzig	Germany	German
+Lübeck	Germany	German
+Ludwigshafen am Rhein	Germany	German
+Leverkusen	Germany	German
+Lünen	Germany	German
+Lahti	Finland	Finnish
+Lausanne	Switzerland	German
+Latakia	Syria	Arabic
+Luchou	Taiwan	Min
+Lungtan	Taiwan	Min
+Liberec	Czech Republic	Czech
+Lviv	Ukraine	Ukrainian
+Lugansk	Ukraine	Ukrainian
+Lutsk	Ukraine	Ukrainian
+Lysyt?ansk	Ukraine	Ukrainian
+Lower Hutt	New Zealand	English
+Lida	Belarus	Belorussian
+Los Teques	Venezuela	Spanish
+Lipetsk	Russian Federation	Russian
+Ljubertsy	Russian Federation	Russian
+Leninsk-Kuznetski	Russian Federation	Russian
+Long Xuyen	Vietnam	Vietnamese
+Los Angeles	United States	English
+Las Vegas	United States	English
+Long Beach	United States	English
+Lexington-Fayette	United States	English
+Louisville	United States	English
+Lincoln	United States	English
+Lubbock	United States	English
+Little Rock	United States	English
+Laredo	United States	English
+Lakewood	United States	English
+Lansing	United States	English
+Lancaster	United States	English
+Lafayette	United States	English
+Lowell	United States	English
+Livonia	United States	English
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	Country	ALL	PRIMARY,Name	NULL	NULL	NULL	239	Using where
+1	PRIMARY	City	ref	Population,Country	Country	3	world.Country.Code	8	Using where; Using
join buffer
+Name
+Vientiane
+Riga
+Daugavpils
+Maseru
+Beirut
+Tripoli
+Monrovia
+Tripoli
+Bengasi
+Misrata
+Vilnius
+Kaunas
+Klaipeda
+?iauliai
+Panevezys
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
+1	SIMPLE	CountryLanguage	eq_ref	PRIMARY	PRIMARY	33	world.Country.Code,const	1	Using
where; Using join buffer
+Name	IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
+Australia	81.2
+United Kingdom	97.3
+Canada	60.4
+United States	86.2
+Zimbabwe	2.2
+Japan	0.1
+South Africa	8.5
+Malaysia	1.6
+Afghanistan	NULL
+Netherlands	NULL
+Algeria	NULL
+Angola	NULL
+Argentina	NULL
+Bangladesh	NULL
+Belgium	NULL
+Brazil	NULL
+Burkina Faso	NULL
+Chile	NULL
+Ecuador	NULL
+Egypt	NULL
+Spain	NULL
+Ethiopia	NULL
+Philippines	NULL
+Ghana	NULL
+Guatemala	NULL
+Indonesia	NULL
+India	NULL
+Iraq	NULL
+Iran	NULL
+Italy	NULL
+Yemen	NULL
+Yugoslavia	NULL
+Cambodia	NULL
+Cameroon	NULL
+Kazakstan	NULL
+Kenya	NULL
+China	NULL
+Colombia	NULL
+Congo, The Democratic Republic of the	NULL
+North Korea	NULL
+South Korea	NULL
+Greece	NULL
+Cuba	NULL
+Madagascar	NULL
+Malawi	NULL
+Mali	NULL
+Morocco	NULL
+Mexico	NULL
+Mozambique	NULL
+Myanmar	NULL
+Nepal	NULL
+Niger	NULL
+Nigeria	NULL
+Côte d?Ivoire	NULL
+Pakistan	NULL
+Peru	NULL
+Poland	NULL
+France	NULL
+Romania	NULL
+Germany	NULL
+Saudi Arabia	NULL
+Somalia	NULL
+Sri Lanka	NULL
+Sudan	NULL
+Syria	NULL
+Taiwan	NULL
+Tanzania	NULL
+Thailand	NULL
+Czech Republic	NULL
+Turkey	NULL
+Uganda	NULL
+Ukraine	NULL
+Hungary	NULL
+Uzbekistan	NULL
+Belarus	NULL
+Venezuela	NULL
+Russian Federation	NULL
+Vietnam	NULL
+Variable_name	Value
+join_buffer_size	256
+Variable_name	Value
+join_cache_level	5
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Using MRR
+1	SIMPLE	City	ref	Population,Country	Country	3	world.Country.Code	8	Using where; Using
join buffer
+Name	Name
+Vientiane	Laos
+Riga	Latvia
+Daugavpils	Latvia
+Maseru	Lesotho
+Beirut	Lebanon
+Tripoli	Lebanon
+Monrovia	Liberia
+Tripoli	Libyan Arab Jamahiriya
+Bengasi	Libyan Arab Jamahiriya
+Misrata	Libyan Arab Jamahiriya
+Vilnius	Lithuania
+Kaunas	Lithuania
+Klaipeda	Lithuania
+?iauliai	Lithuania
+Panevezys	Lithuania
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	CountryLanguage	ALL	PRIMARY,Percentage	NULL	NULL	NULL	984	Using where
+1	SIMPLE	Country	eq_ref	PRIMARY	PRIMARY	3	world.CountryLanguage.Country	1	Using where;
Using join buffer
+1	SIMPLE	City	ref	Country	Country	3	world.Country.Code	8	Using where; Using join buffer
+Name	Name	Language
+Leiden	Netherlands	Dutch
+La Matanza	Argentina	Spanish
+Lomas de Zamora	Argentina	Spanish
+La Plata	Argentina	Spanish
+Lanús	Argentina	Spanish
+Las Heras	Argentina	Spanish
+La Rioja	Argentina	Spanish
+Liège	Belgium	Dutch
+La Paz	Bolivia	Spanish
+Londrina	Brazil	Portuguese
+Limeira	Brazil	Portuguese
+Lages	Brazil	Portuguese
+Luziânia	Brazil	Portuguese
+Lauro de Freitas	Brazil	Portuguese
+Linhares	Brazil	Portuguese
+London	United Kingdom	English
+Liverpool	United Kingdom	English
+Leeds	United Kingdom	English
+Leicester	United Kingdom	English
+Luton	United Kingdom	English
+Los Angeles	Chile	Spanish
+La Serena	Chile	Spanish
+La Romana	Dominican Republic	Spanish
+Loja	Ecuador	Spanish
+Luxor	Egypt	Arabic
+Las Palmas de Gran Canaria	Spain	Spanish
+L´Hospitalet de Llobregat	Spain	Spanish
+Leganés	Spain	Spanish
+León	Spain	Spanish
+Logroño	Spain	Spanish
+Lleida (Lérida)	Spain	Spanish
+Le-Cap-Haïtien	Haiti	Haiti Creole
+La Ceiba	Honduras	Spanish
+Livorno	Italy	Italian
+Latina	Italy	Italian
+Lecce	Italy	Italian
+La Spezia	Italy	Italian
+Linz	Austria	German
+London	Canada	English
+Laval	Canada	English
+Longueuil	Canada	English
+Lanzhou	China	Chinese
+Luoyang	China	Chinese
+Liuzhou	China	Chinese
+Liaoyang	China	Chinese
+Liupanshui	China	Chinese
+Liaoyuan	China	Chinese
+Lianyungang	China	Chinese
+Leshan	China	Chinese
+Linyi	China	Chinese
+Luzhou	China	Chinese
+Laiwu	China	Chinese
+Liaocheng	China	Chinese
+Laizhou	China	Chinese
+Linfen	China	Chinese
+Liangcheng	China	Chinese
+Longkou	China	Chinese
+Langfang	China	Chinese
+Liu´an	China	Chinese
+Longjing	China	Chinese
+Lengshuijiang	China	Chinese
+Laiyang	China	Chinese
+Longyan	China	Chinese
+Linhe	China	Chinese
+Leiyang	China	Chinese
+Loudi	China	Chinese
+Luohe	China	Chinese
+Linqing	China	Chinese
+Laohekou	China	Chinese
+Linchuan	China	Chinese
+Lhasa	China	Chinese
+Lianyuan	China	Chinese
+Liyang	China	Chinese
+Liling	China	Chinese
+Linhai	China	Chinese
+Larisa	Greece	Greek
+La Habana	Cuba	Spanish
+Lilongwe	Malawi	Chichewa
+León	Mexico	Spanish
+La Paz	Mexico	Spanish
+La Paz	Mexico	Spanish
+Lázaro Cárdenas	Mexico	Spanish
+Lagos de Moreno	Mexico	Spanish
+Lerdo	Mexico	Spanish
+Los Cabos	Mexico	Spanish
+Lerma	Mexico	Spanish
+Las Margaritas	Mexico	Spanish
+Lashio (Lasho)	Myanmar	Burmese
+Lalitapur	Nepal	Nepali
+León	Nicaragua	Spanish
+Lambaré	Paraguay	Spanish
+Lima	Peru	Spanish
+Lisboa	Portugal	Portuguese
+Lódz	Poland	Polish
+Lublin	Poland	Polish
+Legnica	Poland	Polish
+Lyon	France	French
+Le Havre	France	French
+Lille	France	French
+Le Mans	France	French
+Limoges	France	French
+Linköping	Sweden	Swedish
+Lund	Sweden	Swedish
+Leipzig	Germany	German
+Lübeck	Germany	German
+Ludwigshafen am Rhein	Germany	German
+Leverkusen	Germany	German
+Lünen	Germany	German
+Lahti	Finland	Finnish
+Lausanne	Switzerland	German
+Latakia	Syria	Arabic
+Luchou	Taiwan	Min
+Lungtan	Taiwan	Min
+Liberec	Czech Republic	Czech
+Lviv	Ukraine	Ukrainian
+Lugansk	Ukraine	Ukrainian
+Lutsk	Ukraine	Ukrainian
+Lysyt?ansk	Ukraine	Ukrainian
+Lower Hutt	New Zealand	English
+Lida	Belarus	Belorussian
+Los Teques	Venezuela	Spanish
+Lipetsk	Russian Federation	Russian
+Ljubertsy	Russian Federation	Russian
+Leninsk-Kuznetski	Russian Federation	Russian
+Long Xuyen	Vietnam	Vietnamese
+Los Angeles	United States	English
+Las Vegas	United States	English
+Long Beach	United States	English
+Lexington-Fayette	United States	English
+Louisville	United States	English
+Lincoln	United States	English
+Lubbock	United States	English
+Little Rock	United States	English
+Laredo	United States	English
+Lakewood	United States	English
+Lansing	United States	English
+Lancaster	United States	English
+Lafayette	United States	English
+Lowell	United States	English
+Livonia	United States	English
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	Country	ALL	PRIMARY,Name	NULL	NULL	NULL	239	Using where
+1	PRIMARY	City	ref	Population,Country	Country	3	world.Country.Code	8	Using where; Using
join buffer
+Name
+Vientiane
+Riga
+Daugavpils
+Maseru
+Beirut
+Tripoli
+Monrovia
+Tripoli
+Bengasi
+Misrata
+Vilnius
+Kaunas
+Klaipeda
+?iauliai
+Panevezys
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
+1	SIMPLE	CountryLanguage	eq_ref	PRIMARY	PRIMARY	33	world.Country.Code,const	1	Using
where; Using join buffer
+Name	IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
+Afghanistan	NULL
+Netherlands	NULL
+Algeria	NULL
+Angola	NULL
+Australia	81.2
+Argentina	NULL
+Bangladesh	NULL
+Belgium	NULL
+United Kingdom	97.3
+Brazil	NULL
+Burkina Faso	NULL
+Chile	NULL
+South Africa	8.5
+Ecuador	NULL
+Egypt	NULL
+Spain	NULL
+Ethiopia	NULL
+Philippines	NULL
+Ghana	NULL
+Guatemala	NULL
+Indonesia	NULL
+India	NULL
+Iraq	NULL
+Iran	NULL
+Japan	0.1
+Italy	NULL
+Yemen	NULL
+Yugoslavia	NULL
+Cambodia	NULL
+Canada	60.4
+Cameroon	NULL
+Kazakstan	NULL
+Kenya	NULL
+China	NULL
+Colombia	NULL
+Congo, The Democratic Republic of the	NULL
+North Korea	NULL
+South Korea	NULL
+Greece	NULL
+Cuba	NULL
+Madagascar	NULL
+Malaysia	1.6
+Malawi	NULL
+Mali	NULL
+Morocco	NULL
+Mexico	NULL
+Mozambique	NULL
+Myanmar	NULL
+Nepal	NULL
+Niger	NULL
+Nigeria	NULL
+Côte d?Ivoire	NULL
+Pakistan	NULL
+Peru	NULL
+Poland	NULL
+France	NULL
+Romania	NULL
+Germany	NULL
+Saudi Arabia	NULL
+Somalia	NULL
+Sri Lanka	NULL
+Sudan	NULL
+Syria	NULL
+Taiwan	NULL
+Tanzania	NULL
+Thailand	NULL
+Czech Republic	NULL
+Turkey	NULL
+Uganda	NULL
+Ukraine	NULL
+Hungary	NULL
+Uzbekistan	NULL
+Belarus	NULL
+United States	86.2
+Venezuela	NULL
+Russian Federation	NULL
+Vietnam	NULL
+Zimbabwe	2.2
+Variable_name	Value
+join_cache_level	6
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	Country	range	PRIMARY,Name	Name	52	NULL	10	Using index condition; Using MRR
+1	SIMPLE	City	ref	Population,Country	Country	3	world.Country.Code	8	Using where; Using
join buffer
+Name	Name
+Vientiane	Laos
+Riga	Latvia
+Daugavpils	Latvia
+Maseru	Lesotho
+Beirut	Lebanon
+Tripoli	Lebanon
+Monrovia	Liberia
+Tripoli	Libyan Arab Jamahiriya
+Bengasi	Libyan Arab Jamahiriya
+Misrata	Libyan Arab Jamahiriya
+Vilnius	Lithuania
+Kaunas	Lithuania
+Klaipeda	Lithuania
+?iauliai	Lithuania
+Panevezys	Lithuania
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	CountryLanguage	ALL	PRIMARY,Percentage	NULL	NULL	NULL	984	Using where
+1	SIMPLE	Country	eq_ref	PRIMARY	PRIMARY	3	world.CountryLanguage.Country	1	Using where;
Using join buffer
+1	SIMPLE	City	ref	Country	Country	3	world.Country.Code	8	Using where; Using join buffer
+Name	Name	Language
+Leiden	Netherlands	Dutch
+La Matanza	Argentina	Spanish
+Lomas de Zamora	Argentina	Spanish
+La Plata	Argentina	Spanish
+Lanús	Argentina	Spanish
+Las Heras	Argentina	Spanish
+La Rioja	Argentina	Spanish
+Liège	Belgium	Dutch
+La Paz	Bolivia	Spanish
+Londrina	Brazil	Portuguese
+Limeira	Brazil	Portuguese
+Lages	Brazil	Portuguese
+Luziânia	Brazil	Portuguese
+Lauro de Freitas	Brazil	Portuguese
+Linhares	Brazil	Portuguese
+London	United Kingdom	English
+Liverpool	United Kingdom	English
+Leeds	United Kingdom	English
+Leicester	United Kingdom	English
+Luton	United Kingdom	English
+Los Angeles	Chile	Spanish
+La Serena	Chile	Spanish
+La Romana	Dominican Republic	Spanish
+Loja	Ecuador	Spanish
+Luxor	Egypt	Arabic
+Las Palmas de Gran Canaria	Spain	Spanish
+L´Hospitalet de Llobregat	Spain	Spanish
+Leganés	Spain	Spanish
+León	Spain	Spanish
+Logroño	Spain	Spanish
+Lleida (Lérida)	Spain	Spanish
+Le-Cap-Haïtien	Haiti	Haiti Creole
+La Ceiba	Honduras	Spanish
+Livorno	Italy	Italian
+Latina	Italy	Italian
+Lecce	Italy	Italian
+La Spezia	Italy	Italian
+Linz	Austria	German
+London	Canada	English
+Laval	Canada	English
+Longueuil	Canada	English
+Lanzhou	China	Chinese
+Luoyang	China	Chinese
+Liuzhou	China	Chinese
+Liaoyang	China	Chinese
+Liupanshui	China	Chinese
+Liaoyuan	China	Chinese
+Lianyungang	China	Chinese
+Leshan	China	Chinese
+Linyi	China	Chinese
+Luzhou	China	Chinese
+Laiwu	China	Chinese
+Liaocheng	China	Chinese
+Laizhou	China	Chinese
+Linfen	China	Chinese
+Liangcheng	China	Chinese
+Longkou	China	Chinese
+Langfang	China	Chinese
+Liu´an	China	Chinese
+Longjing	China	Chinese
+Lengshuijiang	China	Chinese
+Laiyang	China	Chinese
+Longyan	China	Chinese
+Linhe	China	Chinese
+Leiyang	China	Chinese
+Loudi	China	Chinese
+Luohe	China	Chinese
+Linqing	China	Chinese
+Laohekou	China	Chinese
+Linchuan	China	Chinese
+Lhasa	China	Chinese
+Lianyuan	China	Chinese
+Liyang	China	Chinese
+Liling	China	Chinese
+Linhai	China	Chinese
+Larisa	Greece	Greek
+La Habana	Cuba	Spanish
+Lilongwe	Malawi	Chichewa
+León	Mexico	Spanish
+La Paz	Mexico	Spanish
+La Paz	Mexico	Spanish
+Lázaro Cárdenas	Mexico	Spanish
+Lagos de Moreno	Mexico	Spanish
+Lerdo	Mexico	Spanish
+Los Cabos	Mexico	Spanish
+Lerma	Mexico	Spanish
+Las Margaritas	Mexico	Spanish
+Lashio (Lasho)	Myanmar	Burmese
+Lalitapur	Nepal	Nepali
+León	Nicaragua	Spanish
+Lambaré	Paraguay	Spanish
+Lima	Peru	Spanish
+Lisboa	Portugal	Portuguese
+Lódz	Poland	Polish
+Lublin	Poland	Polish
+Legnica	Poland	Polish
+Lyon	France	French
+Le Havre	France	French
+Lille	France	French
+Le Mans	France	French
+Limoges	France	French
+Linköping	Sweden	Swedish
+Lund	Sweden	Swedish
+Leipzig	Germany	German
+Lübeck	Germany	German
+Ludwigshafen am Rhein	Germany	German
+Leverkusen	Germany	German
+Lünen	Germany	German
+Lahti	Finland	Finnish
+Lausanne	Switzerland	German
+Latakia	Syria	Arabic
+Luchou	Taiwan	Min
+Lungtan	Taiwan	Min
+Liberec	Czech Republic	Czech
+Lviv	Ukraine	Ukrainian
+Lugansk	Ukraine	Ukrainian
+Lutsk	Ukraine	Ukrainian
+Lysyt?ansk	Ukraine	Ukrainian
+Lower Hutt	New Zealand	English
+Lida	Belarus	Belorussian
+Los Teques	Venezuela	Spanish
+Lipetsk	Russian Federation	Russian
+Ljubertsy	Russian Federation	Russian
+Leninsk-Kuznetski	Russian Federation	Russian
+Long Xuyen	Vietnam	Vietnamese
+Los Angeles	United States	English
+Las Vegas	United States	English
+Long Beach	United States	English
+Lexington-Fayette	United States	English
+Louisville	United States	English
+Lincoln	United States	English
+Lubbock	United States	English
+Little Rock	United States	English
+Laredo	United States	English
+Lakewood	United States	English
+Lansing	United States	English
+Lancaster	United States	English
+Lafayette	United States	English
+Lowell	United States	English
+Livonia	United States	English
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	PRIMARY	Country	ALL	PRIMARY,Name	NULL	NULL	NULL	239	Using where
+1	PRIMARY	City	ref	Population,Country	Country	3	world.Country.Code	8	Using where; Using
join buffer
+Name
+Vientiane
+Riga
+Daugavpils
+Maseru
+Beirut
+Tripoli
+Monrovia
+Tripoli
+Bengasi
+Misrata
+Vilnius
+Kaunas
+Klaipeda
+?iauliai
+Panevezys
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	Country	ALL	NULL	NULL	NULL	NULL	239	Using where
+1	SIMPLE	CountryLanguage	eq_ref	PRIMARY	PRIMARY	33	world.Country.Code,const	1	Using
where; Using join buffer
+Name	IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage)
+Afghanistan	NULL
+Netherlands	NULL
+Algeria	NULL
+Angola	NULL
+Australia	81.2
+Argentina	NULL
+Bangladesh	NULL
+Belgium	NULL
+United Kingdom	97.3
+Brazil	NULL
+Burkina Faso	NULL
+Chile	NULL
+South Africa	8.5
+Ecuador	NULL
+Egypt	NULL
+Spain	NULL
+Ethiopia	NULL
+Philippines	NULL
+Ghana	NULL
+Guatemala	NULL
+Indonesia	NULL
+India	NULL
+Iraq	NULL
+Iran	NULL
+Japan	0.1
+Italy	NULL
+Yemen	NULL
+Yugoslavia	NULL
+Cambodia	NULL
+Canada	60.4
+Cameroon	NULL
+Kazakstan	NULL
+Kenya	NULL
+China	NULL
+Colombia	NULL
+Congo, The Democratic Republic of the	NULL
+North Korea	NULL
+South Korea	NULL
+Greece	NULL
+Cuba	NULL
+Madagascar	NULL
+Malaysia	1.6
+Malawi	NULL
+Mali	NULL
+Morocco	NULL
+Mexico	NULL
+Mozambique	NULL
+Myanmar	NULL
+Nepal	NULL
+Niger	NULL
+Nigeria	NULL
+Côte d?Ivoire	NULL
+Pakistan	NULL
+Peru	NULL
+Poland	NULL
+France	NULL
+Romania	NULL
+Germany	NULL
+Saudi Arabia	NULL
+Somalia	NULL
+Sri Lanka	NULL
+Sudan	NULL
+Syria	NULL
+Taiwan	NULL
+Tanzania	NULL
+Thailand	NULL
+Czech Republic	NULL
+Turkey	NULL
+Uganda	NULL
+Ukraine	NULL
+Hungary	NULL
+Uzbekistan	NULL
+Belarus	NULL
+United States	86.2
+Venezuela	NULL
+Russian Federation	NULL
+Vietnam	NULL
+Zimbabwe	2.2
+Variable_name	Value
+join_buffer_size	131072
+Variable_name	Value
+join_cache_level	1
diff -Nrup a/mysql-test/r/join_nested_jcl6.result b/mysql-test/r/join_nested_jcl6.result
--- /dev/null	Wed Dec 31 16:00:00 196900
+++ b/mysql-test/r/join_nested_jcl6.result	2008-04-05 23:35:11 -07:00
@@ -0,0 +1,1756 @@
+set join_cache_level=6;
+show variables like 'join_cache_level';
+Variable_name	Value
+join_cache_level	6
+DROP TABLE IF EXISTS t0,t1,t2,t3,t4,t5,t6,t7,t8,t9;
+CREATE TABLE t0 (a int, b int, c int);
+CREATE TABLE t1 (a int, b int, c int);
+CREATE TABLE t2 (a int, b int, c int);
+CREATE TABLE t3 (a int, b int, c int);
+CREATE TABLE t4 (a int, b int, c int);
+CREATE TABLE t5 (a int, b int, c int);
+CREATE TABLE t6 (a int, b int, c int);
+CREATE TABLE t7 (a int, b int, c int);
+CREATE TABLE t8 (a int, b int, c int);
+CREATE TABLE t9 (a int, b int, c int);
+INSERT INTO t0 VALUES (1,1,0), (1,2,0), (2,2,0);
+INSERT INTO t1 VALUES (1,3,0), (2,2,0), (3,2,0);
+INSERT INTO t2 VALUES (3,3,0), (4,2,0), (5,3,0);
+INSERT INTO t3 VALUES (1,2,0), (2,2,0);
+INSERT INTO t4 VALUES (3,2,0), (4,2,0);
+INSERT INTO t5 VALUES (3,1,0), (2,2,0), (3,3,0);
+INSERT INTO t6 VALUES (3,2,0), (6,2,0), (6,1,0);
+INSERT INTO t7 VALUES (1,1,0), (2,2,0);
+INSERT INTO t8 VALUES (0,2,0), (1,2,0);
+INSERT INTO t9 VALUES (1,1,0), (1,2,0), (3,3,0);
+SELECT t2.a,t2.b
+FROM t2;
+a	b
+3	3
+4	2
+5	3
+SELECT t3.a,t3.b
+FROM t3;
+a	b
+1	2
+2	2
+SELECT t4.a,t4.b
+FROM t4;
+a	b
+3	2
+4	2
+SELECT t3.a,t3.b,t4.a,t4.b
+FROM t3,t4;
+a	b	a	b
+1	2	3	2
+2	2	3	2
+1	2	4	2
+2	2	4	2
+SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
+FROM t2
+LEFT JOIN              
+(t3, t4)
+ON t2.b=t4.b;
+a	b	a	b	a	b
+4	2	1	2	3	2
+4	2	2	2	3	2
+4	2	1	2	4	2
+4	2	2	2	4	2
+3	3	NULL	NULL	NULL	NULL
+5	3	NULL	NULL	NULL	NULL
+SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
+FROM t2
+LEFT JOIN              
+(t3, t4)
+ON t3.a=1 AND t2.b=t4.b;
+a	b	a	b	a	b
+4	2	1	2	3	2
+4	2	1	2	4	2
+3	3	NULL	NULL	NULL	NULL
+5	3	NULL	NULL	NULL	NULL
+EXPLAIN EXTENDED
+SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
+FROM t2
+LEFT JOIN              
+(t3, t4)
+ON t2.b=t4.b
+WHERE t3.a=1 OR t3.c IS NULL;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t4	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS
`a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t2`
left join (`test`.`t3` join `test`.`t4`) on((`test`.`t4`.`b` = `test`.`t2`.`b`)) where
((`test`.`t3`.`a` = 1) or isnull(`test`.`t3`.`c`))
+SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
+FROM t2
+LEFT JOIN              
+(t3, t4)
+ON t2.b=t4.b
+WHERE t3.a=1 OR t3.c IS NULL;
+a	b	a	b	a	b
+4	2	1	2	3	2
+4	2	1	2	4	2
+3	3	NULL	NULL	NULL	NULL
+5	3	NULL	NULL	NULL	NULL
+SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
+FROM t2
+LEFT JOIN              
+(t3, t4)
+ON t2.b=t4.b
+WHERE t3.a>1 OR t3.c IS NULL;
+a	b	a	b	a	b
+4	2	2	2	3	2
+4	2	2	2	4	2
+3	3	NULL	NULL	NULL	NULL
+5	3	NULL	NULL	NULL	NULL
+SELECT t5.a,t5.b
+FROM t5;
+a	b
+3	1
+2	2
+3	3
+SELECT t3.a,t3.b,t4.a,t4.b,t5.a,t5.b
+FROM t3,t4,t5;
+a	b	a	b	a	b
+1	2	3	2	3	1
+2	2	3	2	3	1
+1	2	4	2	3	1
+2	2	4	2	3	1
+1	2	3	2	2	2
+2	2	3	2	2	2
+1	2	4	2	2	2
+2	2	4	2	2	2
+1	2	3	2	3	3
+2	2	3	2	3	3
+1	2	4	2	3	3
+2	2	4	2	3	3
+SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,t5.a,t5.b
+FROM t2
+LEFT JOIN              
+(t3, t4, t5)
+ON t2.b=t4.b;
+a	b	a	b	a	b	a	b
+4	2	1	2	3	2	3	1
+4	2	2	2	3	2	3	1
+4	2	1	2	4	2	3	1
+4	2	2	2	4	2	3	1
+4	2	1	2	3	2	2	2
+4	2	2	2	3	2	2	2
+4	2	1	2	4	2	2	2
+4	2	2	2	4	2	2	2
+4	2	1	2	3	2	3	3
+4	2	2	2	3	2	3	3
+4	2	1	2	4	2	3	3
+4	2	2	2	4	2	3	3
+3	3	NULL	NULL	NULL	NULL	NULL	NULL
+5	3	NULL	NULL	NULL	NULL	NULL	NULL
+EXPLAIN EXTENDED
+SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,t5.a,t5.b
+FROM t2
+LEFT JOIN              
+(t3, t4, t5)
+ON t2.b=t4.b
+WHERE t3.a>1 OR t3.c IS NULL;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t4	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t5	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS
`a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t5`.`a`
AS `a`,`test`.`t5`.`b` AS `b` from `test`.`t2` left join (`test`.`t3` join `test`.`t4`
join `test`.`t5`) on((`test`.`t4`.`b` = `test`.`t2`.`b`)) where ((`test`.`t3`.`a` > 1)
or isnull(`test`.`t3`.`c`))
+SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,t5.a,t5.b
+FROM t2
+LEFT JOIN              
+(t3, t4, t5)
+ON t2.b=t4.b
+WHERE t3.a>1 OR t3.c IS NULL;
+a	b	a	b	a	b	a	b
+4	2	2	2	3	2	3	1
+4	2	2	2	4	2	3	1
+4	2	2	2	3	2	2	2
+4	2	2	2	4	2	2	2
+4	2	2	2	3	2	3	3
+4	2	2	2	4	2	3	3
+3	3	NULL	NULL	NULL	NULL	NULL	NULL
+5	3	NULL	NULL	NULL	NULL	NULL	NULL
+EXPLAIN EXTENDED
+SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,t5.a,t5.b
+FROM t2
+LEFT JOIN              
+(t3, t4, t5)
+ON t2.b=t4.b
+WHERE (t3.a>1 OR t3.c IS NULL) AND 
+(t5.a<3 OR t5.c IS NULL);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	
+1	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t4	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t5	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS
`a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t5`.`a`
AS `a`,`test`.`t5`.`b` AS `b` from `test`.`t2` left join (`test`.`t3` join `test`.`t4`
join `test`.`t5`) on((`test`.`t4`.`b` = `test`.`t2`.`b`)) where (((`test`.`t3`.`a` >
1) or isnull(`test`.`t3`.`c`)) and ((`test`.`t5`.`a` < 3) or isnull(`test`.`t5`.`c`)))
+SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,t5.a,t5.b
+FROM t2
+LEFT JOIN              
+(t3, t4, t5)
+ON t2.b=t4.b
+WHERE (t3.a>1 OR t3.c IS NULL) AND 
+(t5.a<3 OR t5.c IS NULL);
+a	b	a	b	a	b	a	b
+4	2	2	2	3	2	2	2
+4	2	2	2	4	2	2	2
+3	3	NULL	NULL	NULL	NULL	NULL	NULL
+5	3	NULL	NULL	NULL	NULL	NULL	NULL
+SELECT t6.a,t6.b
+FROM t6;
+a	b
+3	2
+6	2
+6	1
+SELECT t7.a,t7.b
+FROM t7;
+a	b
+1	1
+2	2
+SELECT t6.a,t6.b,t7.a,t7.b
+FROM t6,t7;
+a	b	a	b
+3	2	1	1
+3	2	2	2
+6	2	1	1
+6	2	2	2
+6	1	1	1
+6	1	2	2
+SELECT t8.a,t8.b
+FROM t8;
+a	b
+0	2
+1	2
+EXPLAIN EXTENDED
+SELECT t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
+FROM (t6, t7)
+LEFT JOIN 
+t8
+ON t7.b=t8.b AND t6.b < 10;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t7	ALL	NULL	NULL	NULL	NULL	2	100.00	
+1	SIMPLE	t6	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer
+1	SIMPLE	t8	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+Warnings:
+Note	1003	select `test`.`t6`.`a` AS `a`,`test`.`t6`.`b` AS `b`,`test`.`t7`.`a` AS
`a`,`test`.`t7`.`b` AS `b`,`test`.`t8`.`a` AS `a`,`test`.`t8`.`b` AS `b` from `test`.`t6`
join `test`.`t7` left join `test`.`t8` on(((`test`.`t7`.`b` = `test`.`t8`.`b`) and
(`test`.`t6`.`b` < 10))) where 1
+SELECT t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
+FROM (t6, t7)
+LEFT JOIN 
+t8
+ON t7.b=t8.b AND t6.b < 10;
+a	b	a	b	a	b
+3	2	2	2	0	2
+6	2	2	2	0	2
+6	1	2	2	0	2
+3	2	2	2	1	2
+6	2	2	2	1	2
+6	1	2	2	1	2
+3	2	1	1	NULL	NULL
+6	2	1	1	NULL	NULL
+6	1	1	1	NULL	NULL
+SELECT t5.a,t5.b
+FROM t5;
+a	b
+3	1
+2	2
+3	3
+SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
+FROM t5 
+LEFT JOIN 
+( 
+(t6, t7)
+LEFT JOIN 
+t8
+ON t7.b=t8.b AND t6.b < 10
+)
+ON t6.b >= 2 AND t5.b=t7.b;
+a	b	a	b	a	b	a	b
+2	2	3	2	2	2	0	2
+2	2	6	2	2	2	0	2
+2	2	3	2	2	2	1	2
+2	2	6	2	2	2	1	2
+3	1	3	2	1	1	NULL	NULL
+3	1	6	2	1	1	NULL	NULL
+3	3	NULL	NULL	NULL	NULL	NULL	NULL
+SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
+FROM t5 
+LEFT JOIN 
+( 
+(t6, t7)
+LEFT JOIN 
+t8
+ON t7.b=t8.b AND t6.b < 10
+)
+ON t6.b >= 2 AND t5.b=t7.b AND
+(t8.a < 1 OR t8.c IS NULL);
+a	b	a	b	a	b	a	b
+2	2	3	2	2	2	0	2
+2	2	6	2	2	2	0	2
+3	1	3	2	1	1	NULL	NULL
+3	1	6	2	1	1	NULL	NULL
+3	3	NULL	NULL	NULL	NULL	NULL	NULL
+SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
+FROM t2
+LEFT JOIN              
+(t3, t4)
+ON t3.a=1 AND t2.b=t4.b;
+a	b	a	b	a	b
+4	2	1	2	3	2
+4	2	1	2	4	2
+3	3	NULL	NULL	NULL	NULL
+5	3	NULL	NULL	NULL	NULL
+SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
+t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
+FROM t2
+LEFT JOIN              
+(t3, t4)
+ON t3.a=1 AND t2.b=t4.b,
+t5 
+LEFT JOIN 
+( 
+(t6, t7)
+LEFT JOIN 
+t8
+ON t7.b=t8.b AND t6.b < 10
+)
+ON t6.b >= 2 AND t5.b=t7.b;
+a	b	a	b	a	b	a	b	a	b	a	b	a	b
+4	2	1	2	3	2	2	2	3	2	2	2	0	2
+4	2	1	2	4	2	2	2	3	2	2	2	0	2
+4	2	1	2	3	2	2	2	6	2	2	2	0	2
+4	2	1	2	4	2	2	2	6	2	2	2	0	2
+4	2	1	2	3	2	2	2	3	2	2	2	1	2
+4	2	1	2	4	2	2	2	3	2	2	2	1	2
+4	2	1	2	3	2	2	2	6	2	2	2	1	2
+4	2	1	2	4	2	2	2	6	2	2	2	1	2
+4	2	1	2	3	2	3	1	3	2	1	1	NULL	NULL
+4	2	1	2	4	2	3	1	3	2	1	1	NULL	NULL
+4	2	1	2	3	2	3	1	6	2	1	1	NULL	NULL
+4	2	1	2	4	2	3	1	6	2	1	1	NULL	NULL
+4	2	1	2	3	2	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+4	2	1	2	4	2	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+3	3	NULL	NULL	NULL	NULL	2	2	3	2	2	2	0	2
+5	3	NULL	NULL	NULL	NULL	2	2	3	2	2	2	0	2
+3	3	NULL	NULL	NULL	NULL	2	2	6	2	2	2	0	2
+5	3	NULL	NULL	NULL	NULL	2	2	6	2	2	2	0	2
+3	3	NULL	NULL	NULL	NULL	2	2	3	2	2	2	1	2
+5	3	NULL	NULL	NULL	NULL	2	2	3	2	2	2	1	2
+3	3	NULL	NULL	NULL	NULL	2	2	6	2	2	2	1	2
+5	3	NULL	NULL	NULL	NULL	2	2	6	2	2	2	1	2
+3	3	NULL	NULL	NULL	NULL	3	1	3	2	1	1	NULL	NULL
+5	3	NULL	NULL	NULL	NULL	3	1	3	2	1	1	NULL	NULL
+3	3	NULL	NULL	NULL	NULL	3	1	6	2	1	1	NULL	NULL
+5	3	NULL	NULL	NULL	NULL	3	1	6	2	1	1	NULL	NULL
+3	3	NULL	NULL	NULL	NULL	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+5	3	NULL	NULL	NULL	NULL	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
+t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
+FROM t2
+LEFT JOIN              
+(t3, t4)
+ON t3.a=1 AND t2.b=t4.b,
+t5 
+LEFT JOIN 
+( 
+(t6, t7)
+LEFT JOIN 
+t8
+ON t7.b=t8.b AND t6.b < 10
+)
+ON t6.b >= 2 AND t5.b=t7.b
+WHERE t2.a > 3 AND
+(t6.a < 6 OR t6.c IS NULL);
+a	b	a	b	a	b	a	b	a	b	a	b	a	b
+4	2	1	2	3	2	2	2	3	2	2	2	0	2
+4	2	1	2	4	2	2	2	3	2	2	2	0	2
+4	2	1	2	3	2	2	2	3	2	2	2	1	2
+4	2	1	2	4	2	2	2	3	2	2	2	1	2
+4	2	1	2	3	2	3	1	3	2	1	1	NULL	NULL
+4	2	1	2	4	2	3	1	3	2	1	1	NULL	NULL
+4	2	1	2	3	2	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+4	2	1	2	4	2	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+5	3	NULL	NULL	NULL	NULL	2	2	3	2	2	2	0	2
+5	3	NULL	NULL	NULL	NULL	2	2	3	2	2	2	1	2
+5	3	NULL	NULL	NULL	NULL	3	1	3	2	1	1	NULL	NULL
+5	3	NULL	NULL	NULL	NULL	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+SELECT t1.a,t1.b
+FROM t1;
+a	b
+1	3
+2	2
+3	2
+SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
+t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
+FROM t1
+LEFT JOIN                
+( 
+t2
+LEFT JOIN              
+(t3, t4)
+ON t3.a=1 AND t2.b=t4.b,
+t5 
+LEFT JOIN 
+( 
+(t6, t7)
+LEFT JOIN 
+t8
+ON t7.b=t8.b AND t6.b < 10
+)
+ON t6.b >= 2 AND t5.b=t7.b 
+)
+ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND
+(t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND
+(t1.a != 2);
+a	b	a	b	a	b	a	b	a	b	a	b	a	b	a	b
+3	2	4	2	1	2	3	2	2	2	3	2	2	2	0	2
+3	2	4	2	1	2	4	2	2	2	3	2	2	2	0	2
+3	2	4	2	1	2	3	2	2	2	6	2	2	2	0	2
+3	2	4	2	1	2	4	2	2	2	6	2	2	2	0	2
+3	2	4	2	1	2	3	2	2	2	3	2	2	2	1	2
+3	2	4	2	1	2	4	2	2	2	3	2	2	2	1	2
+3	2	4	2	1	2	3	2	2	2	6	2	2	2	1	2
+3	2	4	2	1	2	4	2	2	2	6	2	2	2	1	2
+1	3	4	2	1	2	3	2	3	1	3	2	1	1	NULL	NULL
+3	2	4	2	1	2	3	2	3	1	3	2	1	1	NULL	NULL
+1	3	4	2	1	2	4	2	3	1	3	2	1	1	NULL	NULL
+3	2	4	2	1	2	4	2	3	1	3	2	1	1	NULL	NULL
+1	3	4	2	1	2	3	2	3	1	6	2	1	1	NULL	NULL
+3	2	4	2	1	2	3	2	3	1	6	2	1	1	NULL	NULL
+1	3	4	2	1	2	4	2	3	1	6	2	1	1	NULL	NULL
+3	2	4	2	1	2	4	2	3	1	6	2	1	1	NULL	NULL
+1	3	4	2	1	2	3	2	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+3	2	4	2	1	2	3	2	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+1	3	4	2	1	2	4	2	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+3	2	4	2	1	2	4	2	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+1	3	3	3	NULL	NULL	NULL	NULL	2	2	3	2	2	2	0	2
+3	2	3	3	NULL	NULL	NULL	NULL	2	2	3	2	2	2	0	2
+1	3	5	3	NULL	NULL	NULL	NULL	2	2	3	2	2	2	0	2
+3	2	5	3	NULL	NULL	NULL	NULL	2	2	3	2	2	2	0	2
+1	3	3	3	NULL	NULL	NULL	NULL	2	2	6	2	2	2	0	2
+3	2	3	3	NULL	NULL	NULL	NULL	2	2	6	2	2	2	0	2
+1	3	5	3	NULL	NULL	NULL	NULL	2	2	6	2	2	2	0	2
+3	2	5	3	NULL	NULL	NULL	NULL	2	2	6	2	2	2	0	2
+1	3	3	3	NULL	NULL	NULL	NULL	2	2	3	2	2	2	1	2
+3	2	3	3	NULL	NULL	NULL	NULL	2	2	3	2	2	2	1	2
+1	3	5	3	NULL	NULL	NULL	NULL	2	2	3	2	2	2	1	2
+3	2	5	3	NULL	NULL	NULL	NULL	2	2	3	2	2	2	1	2
+1	3	3	3	NULL	NULL	NULL	NULL	2	2	6	2	2	2	1	2
+3	2	3	3	NULL	NULL	NULL	NULL	2	2	6	2	2	2	1	2
+1	3	5	3	NULL	NULL	NULL	NULL	2	2	6	2	2	2	1	2
+3	2	5	3	NULL	NULL	NULL	NULL	2	2	6	2	2	2	1	2
+1	3	3	3	NULL	NULL	NULL	NULL	3	1	3	2	1	1	NULL	NULL
+3	2	3	3	NULL	NULL	NULL	NULL	3	1	3	2	1	1	NULL	NULL
+1	3	5	3	NULL	NULL	NULL	NULL	3	1	3	2	1	1	NULL	NULL
+3	2	5	3	NULL	NULL	NULL	NULL	3	1	3	2	1	1	NULL	NULL
+1	3	3	3	NULL	NULL	NULL	NULL	3	1	6	2	1	1	NULL	NULL
+3	2	3	3	NULL	NULL	NULL	NULL	3	1	6	2	1	1	NULL	NULL
+1	3	5	3	NULL	NULL	NULL	NULL	3	1	6	2	1	1	NULL	NULL
+3	2	5	3	NULL	NULL	NULL	NULL	3	1	6	2	1	1	NULL	NULL
+1	3	3	3	NULL	NULL	NULL	NULL	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+3	2	3	3	NULL	NULL	NULL	NULL	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+1	3	5	3	NULL	NULL	NULL	NULL	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+3	2	5	3	NULL	NULL	NULL	NULL	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+2	2	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL
+SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
+t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
+FROM t1
+LEFT JOIN                
+( 
+t2
+LEFT JOIN              
+(t3, t4)
+ON t3.a=1 AND t2.b=t4.b,
+t5 
+LEFT JOIN 
+( 
+(t6, t7)
+LEFT JOIN 
+t8
+ON t7.b=t8.b AND t6.b < 10
+)
+ON t6.b >= 2 AND t5.b=t7.b 
+)
+ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND
+(t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND
+(t1.a != 2)
+WHERE (t2.a >= 4 OR t2.c IS NULL);
+a	b	a	b	a	b	a	b	a	b	a	b	a	b	a	b
+3	2	4	2	1	2	3	2	2	2	3	2	2	2	0	2
+3	2	4	2	1	2	4	2	2	2	3	2	2	2	0	2
+3	2	4	2	1	2	3	2	2	2	6	2	2	2	0	2
+3	2	4	2	1	2	4	2	2	2	6	2	2	2	0	2
+3	2	4	2	1	2	3	2	2	2	3	2	2	2	1	2
+3	2	4	2	1	2	4	2	2	2	3	2	2	2	1	2
+3	2	4	2	1	2	3	2	2	2	6	2	2	2	1	2
+3	2	4	2	1	2	4	2	2	2	6	2	2	2	1	2
+1	3	4	2	1	2	3	2	3	1	3	2	1	1	NULL	NULL
+3	2	4	2	1	2	3	2	3	1	3	2	1	1	NULL	NULL
+1	3	4	2	1	2	4	2	3	1	3	2	1	1	NULL	NULL
+3	2	4	2	1	2	4	2	3	1	3	2	1	1	NULL	NULL
+1	3	4	2	1	2	3	2	3	1	6	2	1	1	NULL	NULL
+3	2	4	2	1	2	3	2	3	1	6	2	1	1	NULL	NULL
+1	3	4	2	1	2	4	2	3	1	6	2	1	1	NULL	NULL
+3	2	4	2	1	2	4	2	3	1	6	2	1	1	NULL	NULL
+1	3	4	2	1	2	3	2	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+3	2	4	2	1	2	3	2	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+1	3	4	2	1	2	4	2	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+3	2	4	2	1	2	4	2	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+1	3	5	3	NULL	NULL	NULL	NULL	2	2	3	2	2	2	0	2
+3	2	5	3	NULL	NULL	NULL	NULL	2	2	3	2	2	2	0	2
+1	3	5	3	NULL	NULL	NULL	NULL	2	2	6	2	2	2	0	2
+3	2	5	3	NULL	NULL	NULL	NULL	2	2	6	2	2	2	0	2
+1	3	5	3	NULL	NULL	NULL	NULL	2	2	3	2	2	2	1	2
+3	2	5	3	NULL	NULL	NULL	NULL	2	2	3	2	2	2	1	2
+1	3	5	3	NULL	NULL	NULL	NULL	2	2	6	2	2	2	1	2
+3	2	5	3	NULL	NULL	NULL	NULL	2	2	6	2	2	2	1	2
+1	3	5	3	NULL	NULL	NULL	NULL	3	1	3	2	1	1	NULL	NULL
+3	2	5	3	NULL	NULL	NULL	NULL	3	1	3	2	1	1	NULL	NULL
+1	3	5	3	NULL	NULL	NULL	NULL	3	1	6	2	1	1	NULL	NULL
+3	2	5	3	NULL	NULL	NULL	NULL	3	1	6	2	1	1	NULL	NULL
+1	3	5	3	NULL	NULL	NULL	NULL	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+3	2	5	3	NULL	NULL	NULL	NULL	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+2	2	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL
+SELECT t0.a,t0.b
+FROM t0;
+a	b
+1	1
+1	2
+2	2
+EXPLAIN EXTENDED
+SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
+t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
+FROM t0,t1
+LEFT JOIN                
+( 
+t2
+LEFT JOIN              
+(t3, t4)
+ON t3.a=1 AND t2.b=t4.b,
+t5 
+LEFT JOIN 
+( 
+(t6, t7)
+LEFT JOIN 
+t8
+ON t7.b=t8.b AND t6.b < 10
+)
+ON t6.b >= 2 AND t5.b=t7.b 
+)
+ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND
+(t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND
+(t1.a != 2)
+WHERE t0.a=1 AND
+t0.b=t1.b AND          
+(t2.a >= 4 OR t2.c IS NULL);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t0	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+1	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t4	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t5	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer
+1	SIMPLE	t7	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t6	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+1	SIMPLE	t8	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+Warnings:
+Note	1003	select `test`.`t0`.`a` AS `a`,`test`.`t0`.`b` AS `b`,`test`.`t1`.`a` AS
`a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a`
AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS
`b`,`test`.`t5`.`a` AS `a`,`test`.`t5`.`b` AS `b`,`test`.`t6`.`a` AS `a`,`test`.`t6`.`b`
AS `b`,`test`.`t7`.`a` AS `a`,`test`.`t7`.`b` AS `b`,`test`.`t8`.`a` AS
`a`,`test`.`t8`.`b` AS `b` from `test`.`t0` join `test`.`t1` left join (`test`.`t2` left
join (`test`.`t3` join `test`.`t4`) on(((`test`.`t4`.`b` = `test`.`t2`.`b`) and
(`test`.`t3`.`a` = 1))) join `test`.`t5` left join (`test`.`t6` join `test`.`t7` left
join `test`.`t8` on(((`test`.`t8`.`b` = `test`.`t5`.`b`) and (`test`.`t6`.`b` < 10))))
on(((`test`.`t7`.`b` = `test`.`t5`.`b`) and (`test`.`t6`.`b` >= 2))))
on((((`test`.`t3`.`b` = 2) or isnull(`test`.`t3`.`c`)) and ((`test`.`t6`.`b` = 2) or
isnull(`test`.`t6`.`c`)) and ((`test`.`t5`.`b` = `test`.`t0`.`b`) or isnull(`test`.`t3`.
 `c`) or isnull(`test`.`t6`.`c`) or isnull(`test`.`t8`.`c`)) and (`test`.`t1`.`a` <>
2))) where ((`test`.`t1`.`b` = `test`.`t0`.`b`) and (`test`.`t0`.`a` = 1) and
((`test`.`t2`.`a` >= 4) or isnull(`test`.`t2`.`c`)))
+SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
+t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
+FROM t0,t1
+LEFT JOIN                
+( 
+t2
+LEFT JOIN              
+(t3, t4)
+ON t3.a=1 AND t2.b=t4.b,
+t5 
+LEFT JOIN 
+( 
+(t6, t7)
+LEFT JOIN 
+t8
+ON t7.b=t8.b AND t6.b < 10
+)
+ON t6.b >= 2 AND t5.b=t7.b 
+)
+ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND
+(t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND
+(t1.a != 2)
+WHERE t0.a=1 AND
+t0.b=t1.b AND          
+(t2.a >= 4 OR t2.c IS NULL);
+a	b	a	b	a	b	a	b	a	b	a	b	a	b	a	b	a	b
+1	2	3	2	4	2	1	2	3	2	2	2	3	2	2	2	0	2
+1	2	3	2	4	2	1	2	4	2	2	2	3	2	2	2	0	2
+1	2	3	2	4	2	1	2	3	2	2	2	6	2	2	2	0	2
+1	2	3	2	4	2	1	2	4	2	2	2	6	2	2	2	0	2
+1	2	3	2	4	2	1	2	3	2	2	2	3	2	2	2	1	2
+1	2	3	2	4	2	1	2	4	2	2	2	3	2	2	2	1	2
+1	2	3	2	4	2	1	2	3	2	2	2	6	2	2	2	1	2
+1	2	3	2	4	2	1	2	4	2	2	2	6	2	2	2	1	2
+1	2	3	2	4	2	1	2	3	2	3	1	3	2	1	1	NULL	NULL
+1	2	3	2	4	2	1	2	4	2	3	1	3	2	1	1	NULL	NULL
+1	2	3	2	4	2	1	2	3	2	3	1	6	2	1	1	NULL	NULL
+1	2	3	2	4	2	1	2	4	2	3	1	6	2	1	1	NULL	NULL
+1	2	3	2	4	2	1	2	3	2	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+1	2	3	2	4	2	1	2	4	2	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+1	2	3	2	5	3	NULL	NULL	NULL	NULL	2	2	3	2	2	2	0	2
+1	2	3	2	5	3	NULL	NULL	NULL	NULL	2	2	6	2	2	2	0	2
+1	2	3	2	5	3	NULL	NULL	NULL	NULL	2	2	3	2	2	2	1	2
+1	2	3	2	5	3	NULL	NULL	NULL	NULL	2	2	6	2	2	2	1	2
+1	2	3	2	5	3	NULL	NULL	NULL	NULL	3	1	3	2	1	1	NULL	NULL
+1	2	3	2	5	3	NULL	NULL	NULL	NULL	3	1	6	2	1	1	NULL	NULL
+1	2	3	2	5	3	NULL	NULL	NULL	NULL	3	3	NULL	NULL	NULL	NULL	NULL	NULL
+1	2	2	2	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL
+EXPLAIN EXTENDED
+SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
+t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b,t9.a,t9.b
+FROM t0,t1
+LEFT JOIN                
+( 
+t2
+LEFT JOIN              
+(t3, t4)
+ON t3.a=1 AND t2.b=t4.b,
+t5 
+LEFT JOIN 
+( 
+(t6, t7)
+LEFT JOIN 
+t8
+ON t7.b=t8.b AND t6.b < 10
+)
+ON t6.b >= 2 AND t5.b=t7.b 
+)
+ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND
+(t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND
+(t1.a != 2),
+t9
+WHERE t0.a=1 AND
+t0.b=t1.b AND          
+(t2.a >= 4 OR t2.c IS NULL) AND
+(t3.a < 5 OR t3.c IS NULL) AND
+(t3.b=t4.b OR t3.c IS NULL OR t4.c IS NULL) AND
+(t5.a >=2 OR t5.c IS NULL) AND
+(t6.a >=4 OR t6.c IS NULL) AND
+(t7.a <= 2 OR t7.c IS NULL) AND
+(t8.a < 1 OR t8.c IS NULL) AND
+(t8.b=t9.b OR t8.c IS NULL) AND
+(t9.a=1);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t0	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+1	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t4	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t5	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+1	SIMPLE	t7	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t6	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+1	SIMPLE	t8	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t9	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+Warnings:
+Note	1003	select `test`.`t0`.`a` AS `a`,`test`.`t0`.`b` AS `b`,`test`.`t1`.`a` AS
`a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a`
AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS
`b`,`test`.`t5`.`a` AS `a`,`test`.`t5`.`b` AS `b`,`test`.`t6`.`a` AS `a`,`test`.`t6`.`b`
AS `b`,`test`.`t7`.`a` AS `a`,`test`.`t7`.`b` AS `b`,`test`.`t8`.`a` AS
`a`,`test`.`t8`.`b` AS `b`,`test`.`t9`.`a` AS `a`,`test`.`t9`.`b` AS `b` from `test`.`t0`
join `test`.`t1` left join (`test`.`t2` left join (`test`.`t3` join `test`.`t4`)
on(((`test`.`t4`.`b` = `test`.`t2`.`b`) and (`test`.`t3`.`a` = 1))) join `test`.`t5` left
join (`test`.`t6` join `test`.`t7` left join `test`.`t8` on(((`test`.`t8`.`b` =
`test`.`t5`.`b`) and (`test`.`t6`.`b` < 10)))) on(((`test`.`t7`.`b` = `test`.`t5`.`b`)
and (`test`.`t6`.`b` >= 2)))) on((((`test`.`t3`.`b` = 2) or isnull(`test`.`t3`.`c`))
and ((`test`.`t6`.`b` = 2) or isnull(`test`.`t6`.`c`)) and ((`test`.`t5`
 .`b` = `test`.`t0`.`b`) or isnull(`test`.`t3`.`c`) or isnull(`test`.`t6`.`c`) or
isnull(`test`.`t8`.`c`)) and (`test`.`t1`.`a` <> 2))) join `test`.`t9` where
((`test`.`t9`.`a` = 1) and (`test`.`t1`.`b` = `test`.`t0`.`b`) and (`test`.`t0`.`a` = 1)
and ((`test`.`t2`.`a` >= 4) or isnull(`test`.`t2`.`c`)) and ((`test`.`t3`.`a` < 5)
or isnull(`test`.`t3`.`c`)) and ((`test`.`t4`.`b` = `test`.`t3`.`b`) or
isnull(`test`.`t3`.`c`) or isnull(`test`.`t4`.`c`)) and ((`test`.`t5`.`a` >= 2) or
isnull(`test`.`t5`.`c`)) and ((`test`.`t6`.`a` >= 4) or isnull(`test`.`t6`.`c`)) and
((`test`.`t7`.`a` <= 2) or isnull(`test`.`t7`.`c`)) and ((`test`.`t8`.`a` < 1) or
isnull(`test`.`t8`.`c`)) and ((`test`.`t9`.`b` = `test`.`t8`.`b`) or
isnull(`test`.`t8`.`c`)))
+SELECT t9.a,t9.b
+FROM t9;
+a	b
+1	1
+1	2
+3	3
+SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
+t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b,t9.a,t9.b
+FROM t0,t1
+LEFT JOIN                
+( 
+t2
+LEFT JOIN              
+(t3, t4)
+ON t3.a=1 AND t2.b=t4.b,
+t5 
+LEFT JOIN 
+( 
+(t6, t7)
+LEFT JOIN 
+t8
+ON t7.b=t8.b AND t6.b < 10
+)
+ON t6.b >= 2 AND t5.b=t7.b 
+)
+ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND
+(t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND
+(t1.a != 2),
+t9
+WHERE t0.a=1 AND
+t0.b=t1.b AND          
+(t2.a >= 4 OR t2.c IS NULL) AND
+(t3.a < 5 OR t3.c IS NULL) AND
+(t3.b=t4.b OR t3.c IS NULL OR t4.c IS NULL) AND
+(t5.a >=2 OR t5.c IS NULL) AND
+(t6.a >=4 OR t6.c IS NULL) AND
+(t7.a <= 2 OR t7.c IS NULL) AND
+(t8.a < 1 OR t8.c IS NULL) AND
+(t8.b=t9.b OR t8.c IS NULL) AND
+(t9.a=1);
+a	b	a	b	a	b	a	b	a	b	a	b	a	b	a	b	a	b	a	b
+1	2	3	2	4	2	1	2	3	2	2	2	6	2	2	2	0	2	1	2
+1	2	3	2	4	2	1	2	4	2	2	2	6	2	2	2	0	2	1	2
+1	2	3	2	4	2	1	2	3	2	3	1	6	2	1	1	NULL	NULL	1	1
+1	2	3	2	4	2	1	2	4	2	3	1	6	2	1	1	NULL	NULL	1	1
+1	2	3	2	4	2	1	2	3	2	3	1	6	2	1	1	NULL	NULL	1	2
+1	2	3	2	4	2	1	2	4	2	3	1	6	2	1	1	NULL	NULL	1	2
+1	2	3	2	4	2	1	2	3	2	3	3	NULL	NULL	NULL	NULL	NULL	NULL	1	1
+1	2	3	2	4	2	1	2	4	2	3	3	NULL	NULL	NULL	NULL	NULL	NULL	1	1
+1	2	3	2	4	2	1	2	3	2	3	3	NULL	NULL	NULL	NULL	NULL	NULL	1	2
+1	2	3	2	4	2	1	2	4	2	3	3	NULL	NULL	NULL	NULL	NULL	NULL	1	2
+1	2	3	2	5	3	NULL	NULL	NULL	NULL	2	2	6	2	2	2	0	2	1	2
+1	2	3	2	5	3	NULL	NULL	NULL	NULL	3	1	6	2	1	1	NULL	NULL	1	1
+1	2	3	2	5	3	NULL	NULL	NULL	NULL	3	1	6	2	1	1	NULL	NULL	1	2
+1	2	3	2	5	3	NULL	NULL	NULL	NULL	3	3	NULL	NULL	NULL	NULL	NULL	NULL	1	1
+1	2	3	2	5	3	NULL	NULL	NULL	NULL	3	3	NULL	NULL	NULL	NULL	NULL	NULL	1	2
+1	2	2	2	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	1	1
+1	2	2	2	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	1	2
+SELECT t1.a,t1.b
+FROM t1;
+a	b
+1	3
+2	2
+3	2
+SELECT t2.a,t2.b
+FROM t2;
+a	b
+3	3
+4	2
+5	3
+SELECT t3.a,t3.b
+FROM t3;
+a	b
+1	2
+2	2
+SELECT t2.a,t2.b,t3.a,t3.b
+FROM t2 
+LEFT JOIN              
+t3
+ON t2.b=t3.b;
+a	b	a	b
+4	2	1	2
+4	2	2	2
+3	3	NULL	NULL
+5	3	NULL	NULL
+SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b
+FROM t1, t2 
+LEFT JOIN              
+t3
+ON t2.b=t3.b
+WHERE t1.a <= 2;
+a	b	a	b	a	b
+1	3	4	2	1	2
+2	2	4	2	1	2
+1	3	4	2	2	2
+2	2	4	2	2	2
+1	3	3	3	NULL	NULL
+2	2	3	3	NULL	NULL
+1	3	5	3	NULL	NULL
+2	2	5	3	NULL	NULL
+SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b
+FROM t1, t3 
+RIGHT JOIN              
+t2
+ON t2.b=t3.b
+WHERE t1.a <= 2;
+a	b	a	b	a	b
+1	3	4	2	1	2
+2	2	4	2	1	2
+1	3	4	2	2	2
+2	2	4	2	2	2
+1	3	3	3	NULL	NULL
+2	2	3	3	NULL	NULL
+1	3	5	3	NULL	NULL
+2	2	5	3	NULL	NULL
+SELECT t3.a,t3.b,t4.a,t4.b
+FROM t3,t4;
+a	b	a	b
+1	2	3	2
+2	2	3	2
+1	2	4	2
+2	2	4	2
+SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
+FROM t2 
+LEFT JOIN              
+(t3, t4)
+ON t3.a=1 AND t2.b=t4.b;
+a	b	a	b	a	b
+4	2	1	2	3	2
+4	2	1	2	4	2
+3	3	NULL	NULL	NULL	NULL
+5	3	NULL	NULL	NULL	NULL
+SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
+FROM t1, t2 
+LEFT JOIN              
+(t3, t4)
+ON t3.a=1 AND t2.b=t4.b
+WHERE t1.a <= 2;
+a	b	a	b	a	b	a	b
+1	3	4	2	1	2	3	2
+2	2	4	2	1	2	3	2
+1	3	4	2	1	2	4	2
+2	2	4	2	1	2	4	2
+1	3	3	3	NULL	NULL	NULL	NULL
+2	2	3	3	NULL	NULL	NULL	NULL
+1	3	5	3	NULL	NULL	NULL	NULL
+2	2	5	3	NULL	NULL	NULL	NULL
+SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
+FROM t1, (t3, t4) 
+RIGHT JOIN              
+t2
+ON t3.a=1 AND t2.b=t4.b
+WHERE t1.a <= 2;
+a	b	a	b	a	b	a	b
+1	3	4	2	1	2	3	2
+2	2	4	2	1	2	3	2
+1	3	4	2	1	2	4	2
+2	2	4	2	1	2	4	2
+1	3	3	3	NULL	NULL	NULL	NULL
+2	2	3	3	NULL	NULL	NULL	NULL
+1	3	5	3	NULL	NULL	NULL	NULL
+2	2	5	3	NULL	NULL	NULL	NULL
+SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
+FROM t1, (t3, t4)
+RIGHT JOIN              
+t2
+ON t3.a=1 AND t2.b=t4.b
+WHERE t1.a <= 2;
+a	b	a	b	a	b	a	b
+1	3	4	2	1	2	3	2
+2	2	4	2	1	2	3	2
+1	3	4	2	1	2	4	2
+2	2	4	2	1	2	4	2
+1	3	3	3	NULL	NULL	NULL	NULL
+2	2	3	3	NULL	NULL	NULL	NULL
+1	3	5	3	NULL	NULL	NULL	NULL
+2	2	5	3	NULL	NULL	NULL	NULL
+EXPLAIN EXTENDED
+SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
+FROM t1, (t3, t4)
+RIGHT JOIN
+t2
+ON t3.a=1 AND t2.b=t4.b
+WHERE t1.a <= 2;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer
+1	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t4	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+Warnings:
+Note	1003	select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS
`a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a`
AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t1` join `test`.`t2` left join (`test`.`t3`
join `test`.`t4`) on(((`test`.`t4`.`b` = `test`.`t2`.`b`) and (`test`.`t3`.`a` = 1)))
where (`test`.`t1`.`a` <= 2)
+CREATE INDEX idx_b ON t2(b);
+EXPLAIN EXTENDED
+SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
+FROM (t3,t4)
+LEFT JOIN              
+(t1,t2)
+ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	2	100.00	
+1	SIMPLE	t4	ALL	NULL	NULL	NULL	NULL	2	100.00	Using join buffer
+1	SIMPLE	t2	ref	idx_b	idx_b	5	test.t3.b	2	100.00	Using where; Using join buffer
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using join buffer
+Warnings:
+Note	1003	select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS
`a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t3`
join `test`.`t4` left join (`test`.`t1` join `test`.`t2`) on(((`test`.`t3`.`a` = 1) and
(`test`.`t3`.`b` = `test`.`t2`.`b`) and (`test`.`t2`.`b` = `test`.`t4`.`b`))) where 1
+SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
+FROM (t3,t4)
+LEFT JOIN              
+(t1,t2)
+ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b;
+a	b	a	b	a	b
+4	2	1	2	3	2
+4	2	1	2	4	2
+4	2	1	2	3	2
+4	2	1	2	4	2
+4	2	1	2	3	2
+4	2	1	2	4	2
+NULL	NULL	2	2	3	2
+NULL	NULL	2	2	4	2
+EXPLAIN EXTENDED
+SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
+t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b,t9.a,t9.b
+FROM t0,t1
+LEFT JOIN                
+( 
+t2
+LEFT JOIN              
+(t3, t4)
+ON t3.a=1 AND t2.b=t4.b,
+t5 
+LEFT JOIN 
+( 
+(t6, t7)
+LEFT JOIN 
+t8
+ON t7.b=t8.b AND t6.b < 10
+)
+ON t6.b >= 2 AND t5.b=t7.b 
+)
+ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND
+(t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND
+(t1.a != 2),
+t9
+WHERE t0.a=1 AND
+t0.b=t1.b AND          
+(t2.a >= 4 OR t2.c IS NULL) AND
+(t3.a < 5 OR t3.c IS NULL) AND
+(t3.b=t4.b OR t3.c IS NULL OR t4.c IS NULL) AND
+(t5.a >=2 OR t5.c IS NULL) AND
+(t6.a >=4 OR t6.c IS NULL) AND
+(t7.a <= 2 OR t7.c IS NULL) AND
+(t8.a < 1 OR t8.c IS NULL) AND
+(t8.b=t9.b OR t8.c IS NULL) AND
+(t9.a=1);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t0	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+1	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t4	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t5	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+1	SIMPLE	t7	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t6	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+1	SIMPLE	t8	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t9	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+Warnings:
+Note	1003	select `test`.`t0`.`a` AS `a`,`test`.`t0`.`b` AS `b`,`test`.`t1`.`a` AS
`a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a`
AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS
`b`,`test`.`t5`.`a` AS `a`,`test`.`t5`.`b` AS `b`,`test`.`t6`.`a` AS `a`,`test`.`t6`.`b`
AS `b`,`test`.`t7`.`a` AS `a`,`test`.`t7`.`b` AS `b`,`test`.`t8`.`a` AS
`a`,`test`.`t8`.`b` AS `b`,`test`.`t9`.`a` AS `a`,`test`.`t9`.`b` AS `b` from `test`.`t0`
join `test`.`t1` left join (`test`.`t2` left join (`test`.`t3` join `test`.`t4`)
on(((`test`.`t4`.`b` = `test`.`t2`.`b`) and (`test`.`t3`.`a` = 1))) join `test`.`t5` left
join (`test`.`t6` join `test`.`t7` left join `test`.`t8` on(((`test`.`t8`.`b` =
`test`.`t5`.`b`) and (`test`.`t6`.`b` < 10)))) on(((`test`.`t7`.`b` = `test`.`t5`.`b`)
and (`test`.`t6`.`b` >= 2)))) on((((`test`.`t3`.`b` = 2) or isnull(`test`.`t3`.`c`))
and ((`test`.`t6`.`b` = 2) or isnull(`test`.`t6`.`c`)) and ((`test`.`t5`
 .`b` = `test`.`t0`.`b`) or isnull(`test`.`t3`.`c`) or isnull(`test`.`t6`.`c`) or
isnull(`test`.`t8`.`c`)) and (`test`.`t1`.`a` <> 2))) join `test`.`t9` where
((`test`.`t9`.`a` = 1) and (`test`.`t1`.`b` = `test`.`t0`.`b`) and (`test`.`t0`.`a` = 1)
and ((`test`.`t2`.`a` >= 4) or isnull(`test`.`t2`.`c`)) and ((`test`.`t3`.`a` < 5)
or isnull(`test`.`t3`.`c`)) and ((`test`.`t4`.`b` = `test`.`t3`.`b`) or
isnull(`test`.`t3`.`c`) or isnull(`test`.`t4`.`c`)) and ((`test`.`t5`.`a` >= 2) or
isnull(`test`.`t5`.`c`)) and ((`test`.`t6`.`a` >= 4) or isnull(`test`.`t6`.`c`)) and
((`test`.`t7`.`a` <= 2) or isnull(`test`.`t7`.`c`)) and ((`test`.`t8`.`a` < 1) or
isnull(`test`.`t8`.`c`)) and ((`test`.`t9`.`b` = `test`.`t8`.`b`) or
isnull(`test`.`t8`.`c`)))
+CREATE INDEX idx_b ON t4(b);
+CREATE INDEX idx_b ON t5(b);
+EXPLAIN EXTENDED
+SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
+t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b,t9.a,t9.b
+FROM t0,t1
+LEFT JOIN                
+( 
+t2
+LEFT JOIN              
+(t3, t4)
+ON t3.a=1 AND t2.b=t4.b,
+t5 
+LEFT JOIN 
+( 
+(t6, t7)
+LEFT JOIN 
+t8
+ON t7.b=t8.b AND t6.b < 10
+)
+ON t6.b >= 2 AND t5.b=t7.b 
+)
+ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND
+(t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND
+(t1.a != 2),
+t9
+WHERE t0.a=1 AND
+t0.b=t1.b AND          
+(t2.a >= 4 OR t2.c IS NULL) AND
+(t3.a < 5 OR t3.c IS NULL) AND
+(t3.b=t4.b OR t3.c IS NULL OR t4.c IS NULL) AND
+(t5.a >=2 OR t5.c IS NULL) AND
+(t6.a >=4 OR t6.c IS NULL) AND
+(t7.a <= 2 OR t7.c IS NULL) AND
+(t8.a < 1 OR t8.c IS NULL) AND
+(t8.b=t9.b OR t8.c IS NULL) AND
+(t9.a=1);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t0	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+1	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t4	ref	idx_b	idx_b	5	test.t2.b	2	100.00	Using where; Using join buffer
+1	SIMPLE	t5	ALL	idx_b	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+1	SIMPLE	t7	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t6	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+1	SIMPLE	t8	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t9	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+Warnings:
+Note	1003	select `test`.`t0`.`a` AS `a`,`test`.`t0`.`b` AS `b`,`test`.`t1`.`a` AS
`a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a`
AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS
`b`,`test`.`t5`.`a` AS `a`,`test`.`t5`.`b` AS `b`,`test`.`t6`.`a` AS `a`,`test`.`t6`.`b`
AS `b`,`test`.`t7`.`a` AS `a`,`test`.`t7`.`b` AS `b`,`test`.`t8`.`a` AS
`a`,`test`.`t8`.`b` AS `b`,`test`.`t9`.`a` AS `a`,`test`.`t9`.`b` AS `b` from `test`.`t0`
join `test`.`t1` left join (`test`.`t2` left join (`test`.`t3` join `test`.`t4`)
on(((`test`.`t4`.`b` = `test`.`t2`.`b`) and (`test`.`t3`.`a` = 1))) join `test`.`t5` left
join (`test`.`t6` join `test`.`t7` left join `test`.`t8` on(((`test`.`t8`.`b` =
`test`.`t5`.`b`) and (`test`.`t6`.`b` < 10)))) on(((`test`.`t7`.`b` = `test`.`t5`.`b`)
and (`test`.`t6`.`b` >= 2)))) on((((`test`.`t3`.`b` = 2) or isnull(`test`.`t3`.`c`))
and ((`test`.`t6`.`b` = 2) or isnull(`test`.`t6`.`c`)) and ((`test`.`t5`
 .`b` = `test`.`t0`.`b`) or isnull(`test`.`t3`.`c`) or isnull(`test`.`t6`.`c`) or
isnull(`test`.`t8`.`c`)) and (`test`.`t1`.`a` <> 2))) join `test`.`t9` where
((`test`.`t9`.`a` = 1) and (`test`.`t1`.`b` = `test`.`t0`.`b`) and (`test`.`t0`.`a` = 1)
and ((`test`.`t2`.`a` >= 4) or isnull(`test`.`t2`.`c`)) and ((`test`.`t3`.`a` < 5)
or isnull(`test`.`t3`.`c`)) and ((`test`.`t4`.`b` = `test`.`t3`.`b`) or
isnull(`test`.`t3`.`c`) or isnull(`test`.`t4`.`c`)) and ((`test`.`t5`.`a` >= 2) or
isnull(`test`.`t5`.`c`)) and ((`test`.`t6`.`a` >= 4) or isnull(`test`.`t6`.`c`)) and
((`test`.`t7`.`a` <= 2) or isnull(`test`.`t7`.`c`)) and ((`test`.`t8`.`a` < 1) or
isnull(`test`.`t8`.`c`)) and ((`test`.`t9`.`b` = `test`.`t8`.`b`) or
isnull(`test`.`t8`.`c`)))
+CREATE INDEX idx_b ON t8(b);
+EXPLAIN EXTENDED
+SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
+t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b,t9.a,t9.b
+FROM t0,t1
+LEFT JOIN                
+( 
+t2
+LEFT JOIN              
+(t3, t4)
+ON t3.a=1 AND t2.b=t4.b,
+t5 
+LEFT JOIN 
+( 
+(t6, t7)
+LEFT JOIN 
+t8
+ON t7.b=t8.b AND t6.b < 10
+)
+ON t6.b >= 2 AND t5.b=t7.b 
+)
+ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND
+(t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND
+(t1.a != 2),
+t9
+WHERE t0.a=1 AND
+t0.b=t1.b AND          
+(t2.a >= 4 OR t2.c IS NULL) AND
+(t3.a < 5 OR t3.c IS NULL) AND
+(t3.b=t4.b OR t3.c IS NULL OR t4.c IS NULL) AND
+(t5.a >=2 OR t5.c IS NULL) AND
+(t6.a >=4 OR t6.c IS NULL) AND
+(t7.a <= 2 OR t7.c IS NULL) AND
+(t8.a < 1 OR t8.c IS NULL) AND
+(t8.b=t9.b OR t8.c IS NULL) AND
+(t9.a=1);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t0	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+1	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t4	ref	idx_b	idx_b	5	test.t2.b	2	100.00	Using where; Using join buffer
+1	SIMPLE	t5	ALL	idx_b	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+1	SIMPLE	t7	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t6	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+1	SIMPLE	t8	ref	idx_b	idx_b	5	test.t5.b	2	100.00	Using where; Using join buffer
+1	SIMPLE	t9	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+Warnings:
+Note	1003	select `test`.`t0`.`a` AS `a`,`test`.`t0`.`b` AS `b`,`test`.`t1`.`a` AS
`a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a`
AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS
`b`,`test`.`t5`.`a` AS `a`,`test`.`t5`.`b` AS `b`,`test`.`t6`.`a` AS `a`,`test`.`t6`.`b`
AS `b`,`test`.`t7`.`a` AS `a`,`test`.`t7`.`b` AS `b`,`test`.`t8`.`a` AS
`a`,`test`.`t8`.`b` AS `b`,`test`.`t9`.`a` AS `a`,`test`.`t9`.`b` AS `b` from `test`.`t0`
join `test`.`t1` left join (`test`.`t2` left join (`test`.`t3` join `test`.`t4`)
on(((`test`.`t4`.`b` = `test`.`t2`.`b`) and (`test`.`t3`.`a` = 1))) join `test`.`t5` left
join (`test`.`t6` join `test`.`t7` left join `test`.`t8` on(((`test`.`t8`.`b` =
`test`.`t5`.`b`) and (`test`.`t6`.`b` < 10)))) on(((`test`.`t7`.`b` = `test`.`t5`.`b`)
and (`test`.`t6`.`b` >= 2)))) on((((`test`.`t3`.`b` = 2) or isnull(`test`.`t3`.`c`))
and ((`test`.`t6`.`b` = 2) or isnull(`test`.`t6`.`c`)) and ((`test`.`t5`
 .`b` = `test`.`t0`.`b`) or isnull(`test`.`t3`.`c`) or isnull(`test`.`t6`.`c`) or
isnull(`test`.`t8`.`c`)) and (`test`.`t1`.`a` <> 2))) join `test`.`t9` where
((`test`.`t9`.`a` = 1) and (`test`.`t1`.`b` = `test`.`t0`.`b`) and (`test`.`t0`.`a` = 1)
and ((`test`.`t2`.`a` >= 4) or isnull(`test`.`t2`.`c`)) and ((`test`.`t3`.`a` < 5)
or isnull(`test`.`t3`.`c`)) and ((`test`.`t4`.`b` = `test`.`t3`.`b`) or
isnull(`test`.`t3`.`c`) or isnull(`test`.`t4`.`c`)) and ((`test`.`t5`.`a` >= 2) or
isnull(`test`.`t5`.`c`)) and ((`test`.`t6`.`a` >= 4) or isnull(`test`.`t6`.`c`)) and
((`test`.`t7`.`a` <= 2) or isnull(`test`.`t7`.`c`)) and ((`test`.`t8`.`a` < 1) or
isnull(`test`.`t8`.`c`)) and ((`test`.`t9`.`b` = `test`.`t8`.`b`) or
isnull(`test`.`t8`.`c`)))
+CREATE INDEX idx_b ON t1(b);
+CREATE INDEX idx_a ON t0(a);
+EXPLAIN EXTENDED
+SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
+t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b,t9.a,t9.b
+FROM t0,t1
+LEFT JOIN                
+( 
+t2
+LEFT JOIN              
+(t3, t4)
+ON t3.a=1 AND t2.b=t4.b,
+t5 
+LEFT JOIN 
+( 
+(t6, t7)
+LEFT JOIN 
+t8
+ON t7.b=t8.b AND t6.b < 10
+)
+ON t6.b >= 2 AND t5.b=t7.b 
+)
+ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND
+(t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND
+(t1.a != 2),
+t9
+WHERE t0.a=1 AND
+t0.b=t1.b AND          
+(t2.a >= 4 OR t2.c IS NULL) AND
+(t3.a < 5 OR t3.c IS NULL) AND
+(t3.b=t4.b OR t3.c IS NULL OR t4.c IS NULL) AND
+(t5.a >=2 OR t5.c IS NULL) AND
+(t6.a >=4 OR t6.c IS NULL) AND
+(t7.a <= 2 OR t7.c IS NULL) AND
+(t8.a < 1 OR t8.c IS NULL) AND
+(t8.b=t9.b OR t8.c IS NULL) AND
+(t9.a=1);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
+1	SIMPLE	t0	ref	idx_a	idx_a	5	const	1	100.00	
+1	SIMPLE	t1	ref	idx_b	idx_b	5	test.t0.b	2	100.00	Using join buffer
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+1	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t4	ref	idx_b	idx_b	5	test.t2.b	2	100.00	Using where; Using join buffer
+1	SIMPLE	t5	ALL	idx_b	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+1	SIMPLE	t7	ALL	NULL	NULL	NULL	NULL	2	100.00	Using where; Using join buffer
+1	SIMPLE	t6	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+1	SIMPLE	t8	ref	idx_b	idx_b	5	test.t5.b	2	100.00	Using where; Using join buffer
+1	SIMPLE	t9	ALL	NULL	NULL	NULL	NULL	3	100.00	Using where; Using join buffer
+Warnings:
+Note	1003	select `test`.`t0`.`a` AS `a`,`test`.`t0`.`b` AS `b`,`test`.`t1`.`a` AS
`a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a`
AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS
`b`,`test`.`t5`.`a` AS `a`,`test`.`t5`.`b` AS `b`,`test`.`t6`.`a` AS `a`,`test`.`t6`.`b`
AS `b`,`test`.`t7`.`a` AS `a`,`test`.`t7`.`b` AS `b`,`test`.`t8`.`a` AS
`a`,`test`.`t8`.`b` AS `b`,`test`.`t9`.`a` AS `a`,`test`.`t9`.`b` AS `b` from `test`.`t0`
join `test`.`t1` left join (`test`.`t2` left join (`test`.`t3` join `test`.`t4`)
on(((`test`.`t4`.`b` = `test`.`t2`.`b`) and (`test`.`t3`.`a` = 1))) join `test`.`t5` left
join (`test`.`t6` join `test`.`t7` left join `test`.`t8` on(((`test`.`t8`.`b` =
`test`.`t5`.`b`) and (`test`.`t6`.`b` < 10)))) on(((`test`.`t7`.`b` = `test`.`t5`.`b`)
and (`test`.`t6`.`b` >= 2)))) on((((`test`.`t3`.`b` = 2) or isnull(`test`.`t3`.`c`))
and ((`test`.`t6`.`b` = 2) or isnull(`test`.`t6`.`c`)) and ((`test`.`t5`
 .`b` = `test`.`t0`.`b`) or isnull(`test`.`t3`.`c`) or isnull(`test`.`t6`.`c`) or
isnull(`test`.`t8`.`c`)) and (`test`.`t1`.`a` <> 2))) join `test`.`t9` where
((`test`.`t9`.`a` = 1) and (`test`.`t1`.`b` = `test`.`t0`.`b`) and (`test`.`t0`.`a` = 1)
and ((`test`.`t2`.`a` >= 4) or isnull(`test`.`t2`.`c`)) and ((`test`.`t3`.`a` < 5)
or isnull(`test`.`t3`.`c`)) and ((`test`.`t4`.`b` = `test`.`t3`.`b`) or
isnull(`test`.`t3`.`c`) or isnull(`test`.`t4`.`c`)) and ((`test`.`t5`.`a` >= 2) or
isnull(`test`.`t5`.`c`)) and ((`test`.`t6`.`a` >= 4) or isnull(`test`.`t6`.`c`)) and
((`test`.`t7`.`a` <= 2) or isnull(`test`.`t7`.`c`)) and ((`test`.`t8`.`a` < 1) or
isnull(`test`.`t8`.`c`)) and ((`test`.`t9`.`b` = `test`.`t8`.`b`) or
isnull(`test`.`t8`.`c`)))
+SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
+t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b,t9.a,t9.b
+FROM t0,t1
+LEFT JOIN                
+( 
+t2
+LEFT JOIN              
+(t3, t4)
+ON t3.a=1 AND t2.b=t4.b,
+t5 
+LEFT JOIN 
+( 
+(t6, t7)
+LEFT JOIN 
+t8
+ON t7.b=t8.b AND t6.b < 10
+)
+ON t6.b >= 2 AND t5.b=t7.b 
+)
+ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND
+(t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND
+(t1.a != 2),
+t9
+WHERE t0.a=1 AND
+t0.b=t1.b AND          
+(t2.a >= 4 OR t2.c IS NULL) AND
+(t3.a < 5 OR t3.c IS NULL) AND
+(t3.b=t4.b OR t3.c IS NULL OR t4.c IS NULL) AND
+(t5.a >=2 OR t5.c IS NULL) AND
+(t6.a >=4 OR t6.c IS NULL) AND
+(t7.a <= 2 OR t7.c IS NULL) AND
+(t8.a < 1 OR t8.c IS NULL) AND
+(t8.b=t9.b OR t8.c IS NULL) AND
+(t9.a=1);
+a	b	a	b	a	b	a	b	a	b	a	b	a	b	a	b	a	b	a	b
+1	2	3	2	4	2	1	2	3	2	2	2	6	2	2	2	0	2	1	2
+1	2	3	2	4	2	1	2	4	2	2	2	6	2	2	2	0	2	1	2
+1	2	3	2	4	2	1	2	3	2	3	1	6	2	1	1	NULL	NULL	1	1
+1	2	3	2	4	2	1	2	4	2	3	1	6	2	1	1	NULL	NULL	1	1
+1	2	3	2	4	2	1	2	3	2	3	1	6	2	1	1	NULL	NULL	1	2
+1	2	3	2	4	2	1	2	4	2	3	1	6	2	1	1	NULL	NULL	1	2
+1	2	3	2	4	2	1	2	3	2	3	3	NULL	NULL	NULL	NULL	NULL	NULL	1	1
+1	2	3	2	4	2	1	2	4	2	3	3	NULL	NULL	NULL	NULL	NULL	NULL	1	1
+1	2	3	2	4	2	1	2	3	2	3	3	NULL	NULL	NULL	NULL	NULL	NULL	1	2
+1	2	3	2	4	2	1	2	4	2	3	3	NULL	NULL	NULL	NULL	NULL	NULL	1	2
+1	2	3	2	5	3	NULL	NULL	NULL	NULL	2	2	6	2	2	2	0	2	1	2
+1	2	3	2	5	3	NULL	NULL	NULL	NULL	3	1	6	2	1	1	NULL	NULL	1	1
+1	2	3	2	5	3	NULL	NULL	NULL	NULL	3	1	6	2	1	1	NULL	NULL	1	2
+1	2	3	2	5	3	NULL	NULL	NULL	NULL	3	3	NULL	NULL	NULL	NULL	NULL	NULL	1	1
+1	2	3	2	5	3	NULL	NULL	NULL	NULL	3	3	NULL	NULL	NULL	NULL	NULL	NULL	1	2
+1	2	2	2	NULL	NULL	1	2	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	1	1
+1	2	2	2	NULL	NULL	1	2	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	1	2
+1	2	2	2	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	1	1
+1	2	2	2	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	1	2
+SELECT t2.a,t2.b
+FROM t2;
+a	b
+3	3
+4	2
+5	3
+SELECT t3.a,t3.b
+FROM t3;
+a	b
+1	2
+2	2
+SELECT t2.a,t2.b,t3.a,t3.b
+FROM t2 LEFT JOIN t3 ON t2.b=t3.b
+WHERE t2.a = 4 OR (t2.a > 4 AND t3.a IS NULL);
+a	b	a	b
+4	2	1	2
+4	2	2	2
+5	3	NULL	NULL
+SELECT t2.a,t2.b,t3.a,t3.b
+FROM t2 LEFT JOIN (t3) ON t2.b=t3.b
+WHERE t2.a = 4 OR (t2.a > 4 AND t3.a IS NULL);
+a	b	a	b
+4	2	1	2
+4	2	2	2
+5	3	NULL	NULL
+ALTER TABLE t3
+CHANGE COLUMN a a1 int,
+CHANGE COLUMN c c1 int;
+SELECT t2.a,t2.b,t3.a1,t3.b
+FROM t2 LEFT JOIN t3 ON t2.b=t3.b
+WHERE t2.a = 4 OR (t2.a > 4 AND t3.a1 IS NULL);
+a	b	a1	b
+4	2	1	2
+4	2	2	2
+5	3	NULL	NULL
+SELECT t2.a,t2.b,t3.a1,t3.b
+FROM t2 NATURAL LEFT JOIN t3
+WHERE t2.a = 4 OR (t2.a > 4 AND t3.a1 IS NULL);
+a	b	a1	b
+4	2	1	2
+4	2	2	2
+5	3	NULL	NULL
+DROP TABLE t0,t1,t2,t3,t4,t5,t6,t7,t8,t9;
+CREATE TABLE t1 (a int);
+CREATE TABLE t2 (a int);
+CREATE TABLE t3 (a int);
+INSERT INTO t1 VALUES (1);
+INSERT INTO t2 VALUES (2);
+INSERT INTO t3 VALUES (2);
+INSERT INTO t1 VALUES (2);
+SELECT * FROM t1 LEFT JOIN (t2 LEFT JOIN t3 ON t2.a=t3.a) ON t1.a=t3.a;
+a	a	a
+2	2	2
+1	NULL	NULL
+SELECT * FROM t1 LEFT JOIN t2 LEFT JOIN t3 ON t2.a=t3.a ON t1.a=t3.a;
+a	a	a
+2	2	2
+1	NULL	NULL
+DELETE FROM t1 WHERE a=2;
+SELECT * FROM t1 LEFT JOIN t2 LEFT JOIN t3 ON t2.a=t3.a ON t1.a=t3.a;
+a	a	a
+1	NULL	NULL
+DELETE FROM t2;
+SELECT * FROM t1 LEFT JOIN t2 LEFT JOIN t3 ON t2.a=t3.a ON t1.a=t3.a;
+a	a	a
+1	NULL	NULL
+DROP TABLE t1,t2,t3;
+CREATE TABLE t1(a int, key (a));
+CREATE TABLE t2(b int, key (b));
+CREATE TABLE t3(c int, key (c));
+INSERT INTO t1 VALUES (NULL), (0), (1), (2), (3), (4), (5), (6), (7), (8), (9),
+(10), (11), (12), (13), (14), (15), (16), (17), (18), (19);
+INSERT INTO t2 VALUES (NULL), (0), (1), (2), (3), (4), (5), (6), (7), (8), (9),
+(10), (11), (12), (13), (14), (15), (16), (17), (18), (19);
+INSERT INTO t3 VALUES (0), (1), (2), (3), (4), (5);
+EXPLAIN SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON c < 3 and b = c;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	index	NULL	a	5	NULL	21	Using index
+1	SIMPLE	t3	index	c	c	5	NULL	6	Using where; Using index
+1	SIMPLE	t2	ref	b	b	5	test.t3.c	2	Using index
+EXPLAIN SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON b < 3 and b = c;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	index	NULL	a	5	NULL	21	Using index
+1	SIMPLE	t3	index	c	c	5	NULL	6	Using index
+1	SIMPLE	t2	ref	b	b	5	test.t3.c	2	Using where; Using index
+SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON b < 3 and b = c;
+a	b	c
+NULL	0	0
+NULL	1	1
+NULL	2	2
+0	0	0
+0	1	1
+0	2	2
+1	0	0
+1	1	1
+1	2	2
+2	0	0
+2	1	1
+2	2	2
+3	0	0
+3	1	1
+3	2	2
+4	0	0
+4	1	1
+4	2	2
+5	0	0
+5	1	1
+5	2	2
+6	0	0
+6	1	1
+6	2	2
+7	0	0
+7	1	1
+7	2	2
+8	0	0
+8	1	1
+8	2	2
+9	0	0
+9	1	1
+9	2	2
+10	0	0
+10	1	1
+10	2	2
+11	0	0
+11	1	1
+11	2	2
+12	0	0
+12	1	1
+12	2	2
+13	0	0
+13	1	1
+13	2	2
+14	0	0
+14	1	1
+14	2	2
+15	0	0
+15	1	1
+15	2	2
+16	0	0
+16	1	1
+16	2	2
+17	0	0
+17	1	1
+17	2	2
+18	0	0
+18	1	1
+18	2	2
+19	0	0
+19	1	1
+19	2	2
+DELETE FROM t3;
+EXPLAIN SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON b < 3 and b = c;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	index	NULL	a	5	NULL	21	Using index
+1	SIMPLE	t3	index	c	c	5	NULL	0	Using index
+1	SIMPLE	t2	ref	b	b	5	test.t3.c	2	Using where; Using index
+SELECT a, b, c FROM t1 LEFT JOIN (t2, t3) ON b < 3 and b = c;
+a	b	c
+NULL	NULL	NULL
+0	NULL	NULL
+1	NULL	NULL
+2	NULL	NULL
+3	NULL	NULL
+4	NULL	NULL
+5	NULL	NULL
+6	NULL	NULL
+7	NULL	NULL
+8	NULL	NULL
+9	NULL	NULL
+10	NULL	NULL
+11	NULL	NULL
+12	NULL	NULL
+13	NULL	NULL
+14	NULL	NULL
+15	NULL	NULL
+16	NULL	NULL
+17	NULL	NULL
+18	NULL	NULL
+19	NULL	NULL
+DROP TABLE t1,t2,t3;
+CREATE TABLE t1 (c11 int);
+CREATE TABLE t2 (c21 int);
+CREATE TABLE t3 (c31 int);
+INSERT INTO t1 VALUES (4), (5);
+SELECT * FROM t1 LEFT JOIN t2 ON c11=c21;
+c11	c21
+4	NULL
+5	NULL
+EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON c11=c21;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	system	NULL	NULL	NULL	NULL	0	const row not found
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	
+SELECT * FROM t1 LEFT JOIN (t2 LEFT JOIN t3 ON c21=c31) ON c11=c21;
+c11	c21	c31
+4	NULL	NULL
+5	NULL	NULL
+EXPLAIN SELECT * FROM t1 LEFT JOIN (t2 LEFT JOIN t3 ON c21=c31) ON c11=c21;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	0	Using where; Using join buffer
+1	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	0	Using where; Using join buffer
+DROP TABLE t1,t2,t3;
+CREATE TABLE t1 (goods int(12) NOT NULL, price varchar(128) NOT NULL);
+INSERT INTO t1 VALUES (23, 2340), (26, 9900);
+CREATE TABLE t2 (goods int(12), name varchar(50), shop char(2));
+INSERT INTO t2 VALUES (23, 'as300', 'fr'), (26, 'as600', 'fr');
+create table t3 (groupid int(12) NOT NULL, goodsid int(12) NOT NULL);
+INSERT INTO t3 VALUES (3,23), (6,26);
+CREATE TABLE t4 (groupid int(12));
+INSERT INTO t4 VALUES (1), (2), (3), (4), (5), (6);
+SELECT * FROM
+(SELECT DISTINCT gl.groupid, gp.price
+FROM t4 gl 
+LEFT JOIN
+(t3 g INNER JOIN t2 p ON g.goodsid = p.goods 
+INNER JOIN t1 gp ON p.goods = gp.goods)
+ON gl.groupid = g.groupid and p.shop = 'fr') t;
+groupid	price
+3	2340
+6	9900
+1	NULL
+2	NULL
+4	NULL
+5	NULL
+CREATE VIEW v1 AS
+SELECT g.groupid groupid, p.goods goods,  
+p.name name, p.shop shop, 
+gp.price price
+FROM t3 g INNER JOIN t2 p ON g.goodsid = p.goods
+INNER JOIN t1 gp on p.goods = gp.goods;
+CREATE VIEW v2 AS
+SELECT DISTINCT g.groupid, fr.price
+FROM t4 g
+LEFT JOIN
+v1 fr on g.groupid = fr.groupid and fr.shop = 'fr';
+SELECT * FROM v2;
+groupid	price
+3	2340
+6	9900
+1	NULL
+2	NULL
+4	NULL
+5	NULL
+SELECT * FROM 
+(SELECT DISTINCT g.groupid, fr.price
+FROM t4 g
+LEFT JOIN
+v1 fr on g.groupid = fr.groupid and fr.shop = 'fr') t;
+groupid	price
+3	2340
+6	9900
+1	NULL
+2	NULL
+4	NULL
+5	NULL
+DROP VIEW v1,v2;
+DROP TABLE t1,t2,t3,t4;
+CREATE TABLE t1(a int);
+CREATE TABLE t2(b int);
+CREATE TABLE t3(c int, d int);
+CREATE TABLE t4(d int);
+CREATE TABLE t5(e int, f int);
+CREATE TABLE t6(f int);
+CREATE VIEW v1 AS 
+SELECT e FROM t5 JOIN t6 ON t5.e=t6.f;
+CREATE VIEW v2 AS 
+SELECT e FROM t5 NATURAL JOIN t6;
+SELECT t1.a FROM t1 JOIN t2 ON a=b JOIN t3 ON a=c JOIN t4 USING(d);
+a
+SELECT t1.x FROM t1 JOIN t2 ON a=b JOIN t3 ON a=c JOIN t4 USING(d);
+ERROR 42S22: Unknown column 't1.x' in 'field list'
+SELECT t1.a FROM t1 JOIN t2 ON a=b JOIN t3 ON a=c NATURAL JOIN t4;
+a
+SELECT t1.x FROM t1 JOIN t2 ON a=b JOIN t3 ON a=c NATURAL JOIN t4;
+ERROR 42S22: Unknown column 't1.x' in 'field list'
+SELECT v1.e FROM v1 JOIN t2 ON e=b JOIN t3 ON e=c JOIN t4 USING(d);
+e
+SELECT v1.x FROM v1 JOIN t2 ON e=b JOIN t3 ON e=c JOIN t4 USING(d);
+ERROR 42S22: Unknown column 'v1.x' in 'field list'
+SELECT v2.e FROM v2 JOIN t2 ON e=b JOIN t3 ON e=c JOIN t4 USING(d);
+e
+SELECT v2.x FROM v2 JOIN t2 ON e=b JOIN t3 ON e=c JOIN t4 USING(d);
+ERROR 42S22: Unknown column 'v2.x' in 'field list'
+DROP VIEW v1, v2;
+DROP TABLE t1, t2, t3, t4, t5, t6;
+create table t1 (id1 int(11) not null);
+insert into t1 values (1),(2);
+create table t2 (id2 int(11) not null);
+insert into t2 values (1),(2),(3),(4);
+create table t3 (id3 char(16) not null);
+insert into t3 values ('100');
+create table t4 (id2 int(11) not null, id3 char(16));
+create table t5 (id1 int(11) not null, key (id1));
+insert into t5 values (1),(2),(1);
+create view v1 as
+select t4.id3 from t4 join t2 on t4.id2 = t2.id2;
+select t1.id1 from t1 inner join (t3 left join v1 on t3.id3 = v1.id3);
+id1
+1
+2
+drop view v1;
+drop table t1, t2, t3, t4, t5;
+create table t0 (a int);
+insert into t0 values (0),(1),(2),(3);
+create table t1(a int);
+insert into t1 select A.a + 10*(B.a) from t0 A, t0 B;
+create table t2 (a int, b int);
+insert into t2 values (1,1), (2,2), (3,3);
+create table t3(a int, b int, filler char(200), key(a));
+insert into t3 select a,a,'filler' from t1;
+insert into t3 select a,a,'filler' from t1;
+create table t4 like t3;
+insert into t4 select * from t3;
+insert into t4 select * from t3;
+create table t5 like t4;
+insert into t5 select * from t4;
+insert into t5 select * from t4;
+create table t6 like t5;
+insert into t6 select * from t5;
+insert into t6 select * from t5;
+create table t7 like t6;
+insert into t7 select * from t6;
+insert into t7 select * from t6;
+explain select * from t4 join 
+t2 left join (t3 join t5 on t5.a=t3.b) on t3.a=t2.b where t4.a<=>t3.b;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	X	
+1	SIMPLE	t3	ref	a	a	5	test.t2.b	X	Using join buffer
+1	SIMPLE	t5	ref	a	a	5	test.t3.b	X	Using join buffer
+1	SIMPLE	t4	ref	a	a	5	test.t3.b	X	Using where; Using join buffer
+explain select * from (t4 join t6 on t6.a=t4.b) right join t3 on t4.a=t3.b
+join t2 left join (t5 join t7 on t7.a=t5.b) on t5.a=t2.b where t3.a<=>t2.b;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	X	
+1	SIMPLE	t3	ref	a	a	5	test.t2.b	X	Using where; Using join buffer
+1	SIMPLE	t4	ref	a	a	5	test.t3.b	X	Using join buffer
+1	SIMPLE	t6	ref	a	a	5	test.t4.b	X	Using join buffer
+1	SIMPLE	t5	ref	a	a	5	test.t2.b	X	Using join buffer
+1	SIMPLE	t7	ref	a	a	5	test.t5.b	X	Using join buffer
+explain select * from t2 left join
+(t3 left join (t4 join t6 on t6.a=t4.b) on t4.a=t3.b 
+join t5 on t5.a=t3.b) on t3.a=t2.b;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	X	
+1	SIMPLE	t3	ref	a	a	5	test.t2.b	X	Using join buffer
+1	SIMPLE	t4	ref	a	a	5	test.t3.b	X	Using join buffer
+1	SIMPLE	t6	ref	a	a	5	test.t4.b	X	Using join buffer
+1	SIMPLE	t5	ref	a	a	5	test.t3.b	X	Using join buffer
+drop table t0, t1, t2, t3, t4, t5, t6, t7;
+create table t1 (a int);
+insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
+create table t2 (a int, filler char(100), key(a));
+insert into t2 select A.a + 10*B.a, '' from t1 A, t1 B;
+create table t3 like t2;
+insert into t3 select * from t2;
+explain select * from t1 left join 
+(t2 left join t3 on (t2.a = t3.a)) 
+on (t1.a = t2.a);
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	10	
+1	SIMPLE	t2	ref	a	a	5	test.t1.a	1	Using join buffer
+1	SIMPLE	t3	ref	a	a	5	test.t2.a	1	Using join buffer
+drop table t1, t2, t3;
+CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, type varchar(10));
+CREATE TABLE t2 (pid int NOT NULL PRIMARY KEY, type varchar(10));
+CREATE TABLE t3 (cid int NOT NULL PRIMARY KEY,
+id int NOT NULL,
+pid int NOT NULL);
+INSERT INTO t1 VALUES (1, 'A'), (3, 'C');
+INSERT INTO t2 VALUES (1, 'A'), (3, 'C');
+INSERT INTO t3 VALUES (1, 1, 1), (3, 3, 3);
+SELECT * FROM t1 p LEFT JOIN (t3 JOIN t1)
+ON (t1.id=t3.id AND t1.type='B' AND p.id=t3.id)
+LEFT JOIN t2 ON (t3.pid=t2.pid)
+WHERE p.id=1;
+id	type	cid	id	pid	id	type	pid	type
+1	A	NULL	NULL	NULL	NULL	NULL	NULL	NULL
+CREATE VIEW v1 AS
+SELECT t3.* FROM t3 JOIN t1 ON t1.id=t3.id AND t1.type='B';
+SELECT * FROM t1 p LEFT JOIN v1 ON p.id=v1.id
+LEFT JOIN t2 ON v1.pid=t2.pid
+WHERE p.id=1;
+id	type	cid	id	pid	pid	type
+1	A	NULL	NULL	NULL	NULL	NULL
+DROP VIEW v1;
+DROP TABLE t1,t2,t3;
+CREATE TABLE t1 (id1 int PRIMARY KEY, id2 int);
+CREATE TABLE t2 (id1 int PRIMARY KEY, id2 int);
+CREATE TABLE t3 (id1 int PRIMARY KEY, id2 int);
+CREATE TABLE t4 (id1 int PRIMARY KEY, id2 int);
+CREATE TABLE t5 (id1 int PRIMARY KEY, id2 int);
+SELECT t1.id1 AS id, t5.id1 AS ngroupbynsa
+FROM t1 INNER JOIN t2 ON t2.id2 = t1.id1
+LEFT OUTER JOIN
+(t3 INNER JOIN t4 ON t4.id1 = t3.id2 INNER JOIN t5 ON t4.id2 = t5.id1)
+ON t3.id2 IS NOT NULL
+WHERE t1.id1=2;
+id	ngroupbynsa
+PREPARE stmt FROM
+"SELECT t1.id1 AS id, t5.id1 AS ngroupbynsa
+  FROM t1 INNER JOIN t2 ON t2.id2 = t1.id1
+       LEFT OUTER JOIN
+       (t3 INNER JOIN t4 ON t4.id1 = t3.id2 INNER JOIN t5 ON t4.id2 = t5.id1)
+       ON t3.id2 IS NOT NULL
+    WHERE t1.id1=2";
+EXECUTE stmt;
+id	ngroupbynsa
+EXECUTE stmt;
+id	ngroupbynsa
+EXECUTE stmt;
+id	ngroupbynsa
+EXECUTE stmt;
+id	ngroupbynsa
+INSERT INTO t1 VALUES (1,1), (2,1), (3,2);
+INSERT INTO t2 VALUES (2,1), (3,2), (4,3);
+INSERT INTO t3 VALUES (1,1), (3,2), (2,NULL);
+INSERT INTO t4 VALUES (1,1), (2,1), (3,3);
+INSERT INTO t5 VALUES (1,1), (2,2), (3,3), (4,3);
+EXECUTE stmt;
+id	ngroupbynsa
+2	1
+2	1
+EXECUTE stmt;
+id	ngroupbynsa
+2	1
+2	1
+EXECUTE stmt;
+id	ngroupbynsa
+2	1
+2	1
+EXECUTE stmt;
+id	ngroupbynsa
+2	1
+2	1
+SELECT t1.id1 AS id, t5.id1 AS ngroupbynsa
+FROM t1 INNER JOIN t2 ON t2.id2 = t1.id1
+LEFT OUTER JOIN
+(t3 INNER JOIN t4 ON t4.id1 = t3.id2 INNER JOIN t5 ON t4.id2 = t5.id1)
+ON t3.id2 IS NOT NULL
+WHERE t1.id1=2;
+id	ngroupbynsa
+2	1
+2	1
+DROP TABLE t1,t2,t3,t4,t5;
+CREATE TABLE t1 (
+id int NOT NULL PRIMARY KEY,
+ct int DEFAULT NULL,
+pc int DEFAULT NULL,
+INDEX idx_ct (ct),
+INDEX idx_pc (pc)
+);
+INSERT INTO t1 VALUES  
+(1,NULL,NULL),(2,NULL,NULL),(3,NULL,NULL),(4,NULL,NULL),(5,NULL,NULL);
+CREATE TABLE t2 (
+id int NOT NULL PRIMARY KEY,
+sr int NOT NULL,
+nm varchar(255) NOT NULL,
+INDEX idx_sr (sr)
+);
+INSERT INTO t2 VALUES
+(2441905,4308,'LesAbymes'),(2441906,4308,'Anse-Bertrand');
+CREATE TABLE t3 (
+id int NOT NULL PRIMARY KEY,
+ct int NOT NULL,
+ln int NOT NULL,
+INDEX idx_ct (ct),
+INDEX idx_ln (ln)
+);
+CREATE TABLE t4 (
+id int NOT NULL PRIMARY KEY,
+nm varchar(255) NOT NULL
+);
+INSERT INTO t4 VALUES (4308,'Guadeloupe'),(4309,'Martinique');
+SELECT t1.*
+FROM t1 LEFT JOIN
+(t2 LEFT JOIN t3 ON t3.ct=t2.id AND t3.ln='5') ON t1.ct=t2.id
+WHERE t1.id='5';
+id	ct	pc
+5	NULL	NULL
+SELECT t1.*, t4.nm
+FROM t1 LEFT JOIN
+(t2 LEFT JOIN t3 ON t3.ct=t2.id AND t3.ln='5') ON t1.ct=t2.id
+LEFT JOIN t4 ON t2.sr=t4.id
+WHERE t1.id='5';
+id	ct	pc	nm
+5	NULL	NULL	NULL
+DROP TABLE t1,t2,t3,t4;
+CREATE TABLE t1 (a INT, b INT);
+CREATE TABLE t2 (a INT);
+CREATE TABLE t3 (a INT, c INT);
+CREATE TABLE t4 (a INT, c INT);
+CREATE TABLE t5 (a INT, c INT);
+SELECT b FROM t1 JOIN (t2 LEFT JOIN t3 USING (a) LEFT JOIN t4 USING (a)
+LEFT JOIN t5 USING (a)) USING (a);
+b
+SELECT c FROM t1 JOIN (t2 LEFT JOIN t3 USING (a) LEFT JOIN t4 USING (a)
+LEFT JOIN t5 USING (a)) USING (a);
+ERROR 23000: Column 'c' in field list is ambiguous
+SELECT b FROM t1 JOIN (t2 JOIN t3 USING (a) JOIN t4 USING (a)
+JOIN t5 USING (a)) USING (a);
+b
+SELECT c FROM t1 JOIN (t2 JOIN t3 USING (a) JOIN t4 USING (a)
+JOIN t5 USING (a)) USING (a);
+ERROR 23000: Column 'c' in field list is ambiguous
+DROP TABLE t1,t2,t3,t4,t5;
+CREATE TABLE t1 (a INT, b INT);
+CREATE TABLE t2 (a INT, b INT);
+CREATE TABLE t3 (a INT, b INT);
+INSERT INTO t1 VALUES (1,1);
+INSERT INTO t2 VALUES (1,1);
+INSERT INTO t3 VALUES (1,1);
+SELECT * FROM t1 JOIN (t2 JOIN t3 USING (b)) USING (a);
+ERROR 23000: Column 'a' in from clause is ambiguous
+DROP TABLE t1,t2,t3;
+CREATE TABLE t1 (
+carrier char(2) default NULL,
+id int NOT NULL auto_increment PRIMARY KEY
+);
+INSERT INTO t1 VALUES
+('CO',235371754),('CO',235376554),('CO',235376884),('CO',235377874),
+('CO',231060394),('CO',231059224),('CO',231059314),('CO',231060484),
+('CO',231060274),('CO',231060124),('CO',231060244),('CO',231058594),
+('CO',231058924),('CO',231058504),('CO',231059344),('CO',231060424),
+('CO',231059554),('CO',231060304),('CO',231059644),('CO',231059464),
+('CO',231059764),('CO',231058294),('CO',231058624),('CO',231058864),
+('CO',231059374),('CO',231059584),('CO',231059734),('CO',231059014),
+('CO',231059854),('CO',231059494),('CO',231059794),('CO',231058534),
+('CO',231058324),('CO',231058684),('CO',231059524),('CO',231059974);
+CREATE TABLE t2 (
+scan_date date default NULL,
+package_id int default NULL,
+INDEX scan_date(scan_date),
+INDEX package_id(package_id)
+);
+INSERT INTO t2 VALUES
+('2008-12-29',231062944),('2008-12-29',231065764),('2008-12-29',231066124),
+('2008-12-29',231060094),('2008-12-29',231061054),('2008-12-29',231065644),
+('2008-12-29',231064384),('2008-12-29',231064444),('2008-12-29',231073774),
+('2008-12-29',231058594),('2008-12-29',231059374),('2008-12-29',231066004),
+('2008-12-29',231068494),('2008-12-29',231070174),('2008-12-29',231071884),
+('2008-12-29',231063274),('2008-12-29',231063754),('2008-12-29',231064144),
+('2008-12-29',231069424),('2008-12-29',231073714),('2008-12-29',231058414),
+('2008-12-29',231060994),('2008-12-29',231069154),('2008-12-29',231068614),
+('2008-12-29',231071464),('2008-12-29',231074014),('2008-12-29',231059614),
+('2008-12-29',231059074),('2008-12-29',231059464),('2008-12-29',231069094),
+('2008-12-29',231067294),('2008-12-29',231070144),('2008-12-29',231073804),
+('2008-12-29',231072634),('2008-12-29',231058294),('2008-12-29',231065344),
+('2008-12-29',231066094),('2008-12-29',231069034),('2008-12-29',231058594),
+('2008-12-29',231059854),('2008-12-29',231059884),('2008-12-29',231059914),
+('2008-12-29',231063664),('2008-12-29',231063814),('2008-12-29',231063904);
+CREATE TABLE t3 (
+package_id int default NULL,
+INDEX package_id(package_id)
+);
+INSERT INTO t3 VALUES
+(231058294),(231058324),(231058354),(231058384),(231058414),(231058444),
+(231058474),(231058504),(231058534),(231058564),(231058594),(231058624),
+(231058684),(231058744),(231058804),(231058864),(231058924),(231058954),
+(231059014),(231059074),(231059104),(231059134),(231059164),(231059194),
+(231059224),(231059254),(231059284),(231059314),(231059344),(231059374),
+(231059404),(231059434),(231059464),(231059494),(231059524),(231059554),
+(231059584),(231059614),(231059644),(231059674),(231059704),(231059734),
+(231059764),(231059794),(231059824),(231059854),(231059884),(231059914),
+(231059944),(231059974),(231060004),(231060034),(231060064),(231060094),
+(231060124),(231060154),(231060184),(231060214),(231060244),(231060274),
+(231060304),(231060334),(231060364),(231060394),(231060424),(231060454),
+(231060484),(231060514),(231060544),(231060574),(231060604),(231060634),
+(231060664),(231060694),(231060724),(231060754),(231060784),(231060814),
+(231060844),(231060874),(231060904),(231060934),(231060964),(231060994),
+(231061024),(231061054),(231061084),(231061144),(231061174),(231061204),
+(231061234),(231061294),(231061354),(231061384),(231061414),(231061474),
+(231061564),(231061594),(231061624),(231061684),(231061714),(231061774),
+(231061804),(231061894),(231061984),(231062074),(231062134),(231062224),
+(231062254),(231062314),(231062374),(231062434),(231062494),(231062554),
+(231062584),(231062614),(231062644),(231062704),(231062734),(231062794),
+(231062854),(231062884),(231062944),(231063004),(231063034),(231063064),
+(231063124),(231063154),(231063184),(231063214),(231063274),(231063334),
+(231063394),(231063424),(231063454),(231063514),(231063574),(231063664);
+CREATE TABLE t4 (
+carrier char(2) NOT NULL default '' PRIMARY KEY,
+id int(11) default NULL,
+INDEX id(id)
+);
+INSERT INTO t4 VALUES
+('99',6),('SK',456),('UA',486),('AI',1081),('OS',1111),('VS',1510);
+CREATE TABLE t5 (
+carrier_id int default NULL,
+INDEX carrier_id(carrier_id)
+);
+INSERT INTO t5 VALUES
+(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),
+(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),
+(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),
+(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),
+(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),
+(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(6),(456),(456),(456),
+(456),(456),(456),(456),(456),(456),(456),(456),(456),(456),(456),(456),
+(456),(486),(1081),(1111),(1111),(1111),(1111),(1510);
+SELECT COUNT(*) 
+FROM((t2 JOIN t1 ON t2.package_id = t1.id) 
+JOIN t3 ON t3.package_id = t1.id);
+COUNT(*)
+6
+EXPLAIN
+SELECT COUNT(*) 
+FROM ((t2 JOIN t1 ON t2.package_id = t1.id) 
+JOIN t3 ON t3.package_id = t1.id)
+LEFT JOIN 
+(t5 JOIN t4 ON t5.carrier_id = t4.id)
+ON t4.carrier = t1.carrier;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t2	index	package_id	package_id	5	NULL	45	Using index
+1	SIMPLE	t1	eq_ref	PRIMARY	PRIMARY	4	test.t2.package_id	1	Using join buffer
+1	SIMPLE	t4	eq_ref	PRIMARY,id	PRIMARY	2	test.t1.carrier	1	
+1	SIMPLE	t5	ref	carrier_id	carrier_id	5	test.t4.id	22	Using index
+1	SIMPLE	t3	ref	package_id	package_id	5	test.t1.id	1	Using where; Using index
+SELECT COUNT(*) 
+FROM ((t2 JOIN t1 ON t2.package_id = t1.id) 
+JOIN t3 ON t3.package_id = t1.id)
+LEFT JOIN 
+(t5 JOIN t4 ON t5.carrier_id = t4.id)
+ON t4.carrier = t1.carrier;
+COUNT(*)
+6
+DROP TABLE t1,t2,t3,t4,t5;
+End of 5.0 tests
+set join_cache_level=default;
+show variables like 'join_cache_level';
+Variable_name	Value
+join_cache_level	1
diff -Nrup a/mysql-test/r/subselect_sj2.result b/mysql-test/r/subselect_sj2.result
--- a/mysql-test/r/subselect_sj2.result	2008-02-21 02:26:54 -08:00
+++ b/mysql-test/r/subselect_sj2.result	2008-04-06 00:20:37 -07:00
@@ -59,8 +59,6 @@ set @save_max_heap_table_size= @@max_hea
 set max_heap_table_size=16384;
 set @save_join_buffer_size = @@join_buffer_size;
 set join_buffer_size= 8000;
-Warnings:
-Warning	1292	Truncated incorrect join_buffer_size value: '8000'
 drop table t3;
 create table t3 (
 a int, 
@@ -111,8 +109,6 @@ a	b
 drop table t1, t2, t3;
 set @save_join_buffer_size = @@join_buffer_size;
 set join_buffer_size= 8000;
-Warnings:
-Warning	1292	Truncated incorrect join_buffer_size value: '8000'
 create table t1 (a int, filler1 binary(200), filler2 binary(200));
 insert into t1 select a, 'filler123456', 'filler123456' from t0;
 insert into t1 select a+10, 'filler123456', 'filler123456' from t0;
diff -Nrup a/mysql-test/suite/falcon/r/falcon_select.result
b/mysql-test/suite/falcon/r/falcon_select.result
--- a/mysql-test/suite/falcon/r/falcon_select.result	2008-02-14 07:45:49 -08:00
+++ b/mysql-test/suite/falcon/r/falcon_select.result	2008-04-06 00:20:37 -07:00
@@ -1331,15 +1331,15 @@ id	select_type	table	type	possible_keys	
 explain select companynr,companyname from t4 left join t2 using (companynr) where
companynr > 0;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t4	range	PRIMARY	PRIMARY	1	NULL	1	Using where
-1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
 explain select companynr,companyname from t4 left join t2 using (companynr) where
companynr > 0 or companynr < 0;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t4	range	PRIMARY	PRIMARY	1	NULL	13	Using where
-1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
 explain select companynr,companyname from t4 left join t2 using (companynr) where
companynr > 0 and companynr > 0;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t4	range	PRIMARY	PRIMARY	1	NULL	1	Using where
-1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
 explain select t2.companynr,companyname from t4 left join t2 using (companynr) where
t2.companynr > 0 or t2.companynr is null;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t4	ALL	NULL	NULL	NULL	NULL	12	
@@ -1355,15 +1355,15 @@ id	select_type	table	type	possible_keys	
 explain select companynr,companyname from t4 left join t2 using (companynr) where
companynr > 0 or companynr is null;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t4	range	PRIMARY	PRIMARY	1	NULL	1	Using where
-1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
 explain select companynr,companyname from t4 left join t2 using (companynr) where
companynr > 0 or companynr < 0 or companynr > 0;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t4	range	PRIMARY	PRIMARY	1	NULL	13	Using where
-1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
 explain select companynr,companyname from t4 left join t2 using (companynr) where
ifnull(companynr,1)>0;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t4	ALL	NULL	NULL	NULL	NULL	12	Using where
-1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1199	Using where
 select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1;
 companynr	companynr
 37	36
@@ -2268,8 +2268,8 @@ explain select * from t1 left join t2 on
 left join t4 on id3 = id4 where id2 = 1 or id4 = 1;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	t1	ALL	NULL	NULL	NULL	NULL	2	
-1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1	
-1	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	2	
+1	SIMPLE	t2	ALL	NULL	NULL	NULL	NULL	1	Using where
+1	SIMPLE	t3	ALL	NULL	NULL	NULL	NULL	2	Using where
 1	SIMPLE	t4	ref	id4	id4	4	test.t3.id3	2	Using where
 select * from t1 left join t2 on id1 = id2 left join t3 on id1 = id3
 left join t4 on id3 = id4 where id2 = 1 or id4 = 1;
@@ -2302,7 +2302,7 @@ insert into t1 values (1,2), (2,2), (3,2
 insert into t2 values (1,3), (2,3), (3,4), (4,4);
 explain select * from t1 left join t2 on a=c where d in (4);
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t2	ref	c,d	d	5	const	2	Using where
+1	SIMPLE	t2	ref	c,d	d	5	const	2	
 1	SIMPLE	t1	ref	a	a	5	test.t2.c	2	
 select * from t1 left join t2 on a=c where d in (4);
 a	b	c	d
@@ -2310,7 +2310,7 @@ a	b	c	d
 4	2	4	4
 explain select * from t1 left join t2 on a=c where d = 4;
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	t2	ref	c,d	d	5	const	2	Using where
+1	SIMPLE	t2	ref	c,d	d	5	const	2	
 1	SIMPLE	t1	ref	a	a	5	test.t2.c	2	
 select * from t1 left join t2 on a=c where d = 4;
 a	b	c	d
diff -Nrup a/mysql-test/suite/ndb/r/ndb_condition_pushdown.result
b/mysql-test/suite/ndb/r/ndb_condition_pushdown.result
--- a/mysql-test/suite/ndb/r/ndb_condition_pushdown.result	2008-03-20 02:20:04 -07:00
+++ b/mysql-test/suite/ndb/r/ndb_condition_pushdown.result	2008-04-06 00:20:37 -07:00
@@ -1910,7 +1910,7 @@ insert into NodeAlias VALUES(null, 8 , '
 12:22:26');
 explain select * from NodeAlias where (aliasKey LIKE '491803%');
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
-1	SIMPLE	NodeAlias	range	NodeAlias_KeyIndex	NodeAlias_KeyIndex	48	NULL	10	Using where
with pushed condition
+1	SIMPLE	NodeAlias	range	NodeAlias_KeyIndex	NodeAlias_KeyIndex	48	NULL	10	Using where
with pushed condition; Using MRR
 select * from NodeAlias where (aliasKey LIKE '491803%') order by id;
 id	nodeId	displayName	aliasKey	objectVersion	changed
 7	8	491803%	491803%	0	2008-03-10 12:22:26
diff -Nrup a/mysql-test/t/join_cache.test b/mysql-test/t/join_cache.test
--- a/mysql-test/t/join_cache.test	2008-03-31 22:22:37 -07:00
+++ b/mysql-test/t/join_cache.test	2008-04-06 00:20:37 -07:00
@@ -142,4 +142,223 @@ show variables like 'join_cache_level';
 DROP DATABASE world; 
 
 
+CREATE DATABASE world;
+
+use world;
+
+--source include/world_schema.inc
+
+--disable_query_log
+--disable_warnings
+--source include/world.inc
+--disable_warnings
+--disable_query_log
+
+show variables like 'join_buffer_size';
+set join_cache_level=5;
+show variables like 'join_cache_level';
+
+EXPLAIN
+SELECT City.Name, Country.Name FROM City,Country
+  WHERE City.Country=Country.Code AND 
+        Country.Name LIKE 'L%' AND City.Population > 100000;
+
+SELECT City.Name, Country.Name FROM City,Country
+  WHERE City.Country=Country.Code AND 
+        Country.Name LIKE 'L%' AND City.Population > 100000;
+
+EXPLAIN
+SELECT City.Name, Country.Name, CountryLanguage.Language
+  FROM City,Country,CountryLanguage
+  WHERE City.Country=Country.Code AND
+        CountryLanguage.Country=Country.Code AND
+        City.Name LIKE 'L%' AND Country.Population > 3000000 AND
+        CountryLanguage.Percentage > 50;
+
+SELECT City.Name, Country.Name, CountryLanguage.Language
+  FROM City,Country,CountryLanguage
+  WHERE City.Country=Country.Code AND
+        CountryLanguage.Country=Country.Code AND
+        City.Name LIKE 'L%' AND Country.Population > 3000000 AND
+        CountryLanguage.Percentage > 50;
+
+EXPLAIN
+SELECT Name FROM City
+  WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
+        City.Population > 100000;
+
+SELECT Name FROM City
+  WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
+        City.Population > 100000;
+
+EXPLAIN
+SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL,
CountryLanguage.Percentage)
+  FROM Country LEFT JOIN CountryLanguage ON
+       (CountryLanguage.Country=Country.Code AND Language='English')
+  WHERE 
+       Country.Population > 10000000;
+
+SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL,
CountryLanguage.Percentage)
+  FROM Country LEFT JOIN CountryLanguage ON
+       (CountryLanguage.Country=Country.Code AND Language='English')
+  WHERE 
+       Country.Population > 10000000;
+
+set join_cache_level=6;
+show variables like 'join_cache_level';
+
+EXPLAIN
+SELECT City.Name, Country.Name FROM City,Country
+  WHERE City.Country=Country.Code AND 
+        Country.Name LIKE 'L%' AND City.Population > 100000;
+
+SELECT City.Name, Country.Name FROM City,Country
+  WHERE City.Country=Country.Code AND 
+        Country.Name LIKE 'L%' AND City.Population > 100000;
+
+EXPLAIN
+SELECT City.Name, Country.Name, CountryLanguage.Language
+  FROM City,Country,CountryLanguage
+  WHERE City.Country=Country.Code AND
+        CountryLanguage.Country=Country.Code AND
+        City.Name LIKE 'L%' AND Country.Population > 3000000 AND
+        CountryLanguage.Percentage > 50;
+
+SELECT City.Name, Country.Name, CountryLanguage.Language
+  FROM City,Country,CountryLanguage
+  WHERE City.Country=Country.Code AND
+        CountryLanguage.Country=Country.Code AND
+        City.Name LIKE 'L%' AND Country.Population > 3000000 AND
+        CountryLanguage.Percentage > 50;
+
+EXPLAIN
+SELECT Name FROM City
+  WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
+        City.Population > 100000;
+
+SELECT Name FROM City
+  WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
+        City.Population > 100000;
+
+EXPLAIN
+SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL,
CountryLanguage.Percentage)
+  FROM Country LEFT JOIN CountryLanguage ON
+       (CountryLanguage.Country=Country.Code AND Language='English')
+  WHERE 
+       Country.Population > 10000000;
+
+SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL,
CountryLanguage.Percentage)
+  FROM Country LEFT JOIN CountryLanguage ON
+       (CountryLanguage.Country=Country.Code AND Language='English')
+  WHERE 
+       Country.Population > 10000000;
+
+set join_buffer_size=256;
+show variables like 'join_buffer_size';
+
+set join_cache_level=5;
+show variables like 'join_cache_level';
+
+EXPLAIN
+SELECT City.Name, Country.Name FROM City,Country
+  WHERE City.Country=Country.Code AND 
+        Country.Name LIKE 'L%' AND City.Population > 100000;
+
+SELECT City.Name, Country.Name FROM City,Country
+  WHERE City.Country=Country.Code AND 
+        Country.Name LIKE 'L%' AND City.Population > 100000;
+
+EXPLAIN
+SELECT City.Name, Country.Name, CountryLanguage.Language
+  FROM City,Country,CountryLanguage
+  WHERE City.Country=Country.Code AND
+        CountryLanguage.Country=Country.Code AND
+        City.Name LIKE 'L%' AND Country.Population > 3000000 AND
+        CountryLanguage.Percentage > 50;
+
+SELECT City.Name, Country.Name, CountryLanguage.Language
+  FROM City,Country,CountryLanguage
+  WHERE City.Country=Country.Code AND
+        CountryLanguage.Country=Country.Code AND
+        City.Name LIKE 'L%' AND Country.Population > 3000000 AND
+        CountryLanguage.Percentage > 50;
+
+EXPLAIN
+SELECT Name FROM City
+  WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
+        City.Population > 100000;
+
+SELECT Name FROM City
+  WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
+        City.Population > 100000;
+
+EXPLAIN
+SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL,
CountryLanguage.Percentage)
+  FROM Country LEFT JOIN CountryLanguage ON
+       (CountryLanguage.Country=Country.Code AND Language='English')
+  WHERE 
+       Country.Population > 10000000;
+
+SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL,
CountryLanguage.Percentage)
+  FROM Country LEFT JOIN CountryLanguage ON
+       (CountryLanguage.Country=Country.Code AND Language='English')
+  WHERE 
+       Country.Population > 10000000;
+
+set join_cache_level=6;
+show variables like 'join_cache_level';
+
+EXPLAIN
+SELECT City.Name, Country.Name FROM City,Country
+  WHERE City.Country=Country.Code AND 
+        Country.Name LIKE 'L%' AND City.Population > 100000;
+
+SELECT City.Name, Country.Name FROM City,Country
+  WHERE City.Country=Country.Code AND 
+        Country.Name LIKE 'L%' AND City.Population > 100000;
+
+EXPLAIN
+SELECT City.Name, Country.Name, CountryLanguage.Language
+  FROM City,Country,CountryLanguage
+  WHERE City.Country=Country.Code AND
+        CountryLanguage.Country=Country.Code AND
+        City.Name LIKE 'L%' AND Country.Population > 3000000 AND
+        CountryLanguage.Percentage > 50;
+
+SELECT City.Name, Country.Name, CountryLanguage.Language
+  FROM City,Country,CountryLanguage
+  WHERE City.Country=Country.Code AND
+        CountryLanguage.Country=Country.Code AND
+        City.Name LIKE 'L%' AND Country.Population > 3000000 AND
+        CountryLanguage.Percentage > 50;
+
+EXPLAIN
+SELECT Name FROM City
+  WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
+        City.Population > 100000;
+
+SELECT Name FROM City
+  WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND
+        City.Population > 100000;
+
+EXPLAIN
+SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL,
CountryLanguage.Percentage)
+  FROM Country LEFT JOIN CountryLanguage ON
+       (CountryLanguage.Country=Country.Code AND Language='English')
+  WHERE 
+       Country.Population > 10000000;
+
+SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL,
CountryLanguage.Percentage)
+  FROM Country LEFT JOIN CountryLanguage ON
+       (CountryLanguage.Country=Country.Code AND Language='English')
+  WHERE 
+       Country.Population > 10000000;
+
+set join_cache_level=default;
+set join_buffer_size=default;
+
+show variables like 'join_buffer_size';
+show variables like 'join_cache_level';
+
+DROP DATABASE world;
 
diff -Nrup a/mysql-test/t/join_nested_jcl6.test b/mysql-test/t/join_nested_jcl6.test
--- /dev/null	Wed Dec 31 16:00:00 196900
+++ b/mysql-test/t/join_nested_jcl6.test	2008-04-05 23:34:57 -07:00
@@ -0,0 +1,11 @@
+# 
+# Run join_nested.test with BKA enabled 
+#
+
+set join_cache_level=6;
+show variables like 'join_cache_level';
+
+--source t/join_nested.test
+
+set join_cache_level=default;
+show variables like 'join_cache_level';
diff -Nrup a/sql/handler.cc b/sql/handler.cc
--- a/sql/handler.cc	2008-03-23 06:35:02 -07:00
+++ b/sql/handler.cc	2008-04-06 00:20:37 -07:00
@@ -4290,7 +4290,7 @@ int DsMrr_impl::dsmrr_init(handler *h, K
   uint elem_size;
   uint keyno;
   Item *pushed_cond= NULL;
-  handler *new_h2;
+  handler *new_h2= 0;
   DBUG_ENTER("DsMrr_impl::dsmrr_init");
   keyno= h->active_index;
 
diff -Nrup a/sql/sql_select.cc b/sql/sql_select.cc
--- a/sql/sql_select.cc	2008-03-31 23:17:44 -07:00
+++ b/sql/sql_select.cc	2008-04-06 00:20:37 -07:00
@@ -138,8 +138,6 @@ evaluate_join_record(JOIN *join, JOIN_TA
 static enum_nested_loop_state
 evaluate_null_complemented_join_record(JOIN *join, JOIN_TAB *join_tab);
 static enum_nested_loop_state
-flush_cached_records(JOIN *join, JOIN_TAB *join_tab, bool skip_last);
-static enum_nested_loop_state
 end_send(JOIN *join, JOIN_TAB *join_tab, bool end_of_records);
 static enum_nested_loop_state
 end_write(JOIN *join, JOIN_TAB *join_tab, bool end_of_records);
@@ -8153,63 +8151,131 @@ uint make_join_orderinfo(JOIN *join)
   return i;
 }
 
+static
+void set_join_cache_denial(JOIN_TAB *join_tab)
+{
+  if (join_tab->cache)
+  {
+    join_tab->cache->free();
+    join_tab->cache= 0;
+  }
+  if (join_tab->use_join_cache)
+  {
+    join_tab->use_join_cache= FALSE;
+    join_tab[-1].next_select= sub_select;
+  }
+}
+
+static
+void revise_cache_usage(JOIN_TAB *join_tab)
+{
+  JOIN_TAB *tab;
+  JOIN_TAB *first_inner;
+
+  if (join_tab->first_inner)
+  {
+    JOIN_TAB *end_tab= join_tab;
+    JOIN_TAB *last_inner= join_tab->first_inner->last_inner;
+    for (first_inner= join_tab->first_inner; 
+         first_inner && first_inner->last_inner == last_inner;
+         first_inner= first_inner->first_upper)           
+    {
+      for (tab= end_tab-1; tab >= first_inner; tab--)
+      {
+        if (tab->first_inner->last_inner == last_inner)
+          set_join_cache_denial(tab);
+      }
+      end_tab= first_inner;
+    }
+  }
+  else if (tab->first_sj_inner_tab)
+  {
+    first_inner= tab->first_sj_inner_tab;
+    for (tab= join_tab-1; tab >= first_inner; tab--)
+    {
+      if (tab->first_sj_inner_tab == first_inner)
+        set_join_cache_denial(tab);
+    }
+  } 
+}
+
 
 static
 bool check_join_cache_usage(JOIN_TAB *tab,
                             JOIN *join, ulonglong options,
                             uint no_jbuf_after)
 {
+  uint flags;
+  COST_VECT cost;
+  uint bufsz= 4096;
+  JOIN_CACHE *prev_cache=0;
   uint cache_level= join->thd->variables.join_cache_level;
   bool force_unlinked_cache= test(cache_level & 1);
   uint i= tab-join->join_tab;
   
+  if (cache_level == 0)
+    return FALSE;
   if (i == join->const_tables)
     return FALSE;
   if (options & SELECT_NO_JOIN_CACHE)
-    return FALSE;
+    goto no_join_cache;
   if (tab->use_quick == 2)
-    return FALSE;
+    goto no_join_cache;
   if (force_unlinked_cache && 
-      (tab->first_inner && tab->first_inner != tab ||
-       tab->first_sj_inner_tab && tab->first_sj_inner_tab != tab)
&&
-      tab->get_first_inner_table()->cache)
-    return FALSE;
+      (tab->is_inner_table_of_semi_join_with_first_match() &&
+       !tab->is_single_inner_of_semi_join_with_first_match() ||
+       tab->is_inner_table_of_outer_join() &&
+       !tab->is_single_inner_of_outer_join()))
+    goto no_join_cache;
+  if (!(i <= no_jbuf_after) || tab->insideout_match_tab)
+    goto no_join_cache;
+  for (JOIN_TAB *first_inner= tab->first_inner; first_inner;
+       first_inner= first_inner->first_upper)
+  { 
+    if (first_inner != tab && !first_inner->use_join_cache)
+      goto no_join_cache;
+  }
+  if (tab->is_inner_table_of_semi_join_with_first_match() &&
+      !tab->is_single_inner_of_semi_join_with_first_match() &&
+      !tab->first_sj_inner_tab->use_join_cache)
+    goto no_join_cache;
 
-  JOIN_CACHE *prev_cache= force_unlinked_cache ? 0 : tab[-1].cache;
+  if (!force_unlinked_cache)
+    prev_cache= tab[-1].cache;
 
   switch (tab->type) {
   case JT_ALL:
-    if (tab->first_inner || !(i <= no_jbuf_after) || tab->insideout_match_tab)
-      return FALSE;
+    if (cache_level <= 2 && (tab->first_inner ||
tab->first_sj_inner_tab))
+      goto no_join_cache;
     if ((options & SELECT_DESCRIBE) ||
         (tab->cache || 
          (tab->cache= new JOIN_CACHE_BNL(join, tab, prev_cache))) &&
         !tab->cache->init())
       return TRUE;
-    return FALSE;
+    goto no_join_cache;
   case JT_REF:
   case JT_EQ_REF:
-  {
     if (cache_level <= 4)
       return FALSE;
-    uint flag= HA_MRR_NO_NULL_ENDPOINTS;
-    COST_VECT cost;
-    uint bufsz= 4096;
+    flags= HA_MRR_NO_NULL_ENDPOINTS;
+    if (tab->table->covering_keys.is_set(tab->ref.key))
+      flags|= HA_MRR_INDEX_ONLY;
     tab->table->file->multi_range_read_info(tab->ref.key, 10, 20,
-                                            &bufsz, &flag, &cost);
-    if (!(i <= no_jbuf_after))
-      return FALSE;  
-    if (!(flag & HA_MRR_USE_DEFAULT_IMPL) &&
+                                            &bufsz, &flags, &cost);
+    if (!(flags & HA_MRR_USE_DEFAULT_IMPL) &&
         ((options & SELECT_DESCRIBE) ||
          (tab->cache ||
-          (tab->cache= new JOIN_CACHE_BKA(join, tab, prev_cache))) &&
+          (tab->cache= new JOIN_CACHE_BKA(join, tab, flags, prev_cache))) &&
 	 !tab->cache->init()))
       return TRUE;
-    return FALSE;
-  }      
+    goto no_join_cache;
   default : ;
   }
-  return FALSE;            
+
+no_join_cache:
+  if (cache_level>2)
+    revise_cache_usage(tab); 
+  return FALSE;          
 }
 
 /*
@@ -8244,6 +8310,7 @@ make_join_readinfo(JOIN *join, ulonglong
 
   for (i=join->const_tables ; i < join->tables ; i++)
   {
+    JOIN_TAB *first_revised;
     JOIN_TAB *tab=join->join_tab+i;
     TABLE *table=tab->table;
     bool using_join_cache;
@@ -8327,7 +8394,7 @@ make_join_readinfo(JOIN *join, ulonglong
         {
           using_join_cache= TRUE;
 	  tab[-1].next_select=sub_select_cache;
-        }        
+        } 
       }
       else
       {
@@ -8489,7 +8556,10 @@ void JOIN_TAB::cleanup()
   delete quick;
   quick= 0;
   if (cache)
+  {
     cache->free();
+    cache= 0;
+  }
   limit= 0;
   if (table)
   {
@@ -16826,8 +16896,11 @@ void JOIN_CACHE::set_constants()
     If some of the fields are referenced from other caches then
     the record length allows us to easily reach the saved offsets for
     these fields since the offsets are stored at the very end of the record.
+    However at this moment we don't know whether we have referenced fields for
+    the cache or not. Later when a referenced field is registered for the cache
+    we adjust the value of the flag 'with_length'.
   */        
-  with_length= is_key_access() || with_match_flag || referenced_fields;
+  with_length= is_key_access() || with_match_flag;
   /* 
      At this moment we don't know yet the value of 'referenced_fields',
      but in any case it can't be greater than the value of 'fields'.
@@ -17026,14 +17099,15 @@ int JOIN_CACHE_BKA::init()
           {
             /* 
               Register the referenced field 'copy': 
-              - set the offset number in copy->referenced_field_no
-              - adjust the values of 'pack_length' and 'pack_last_length'
+              - set the offset number in copy->referenced_field_no,
+              - adjust the value of the flag 'with_length',
+              - adjust the values of 'pack_length' and 'pack_last_length'.
 	    */
-            copy->referenced_field_no= ++referenced_fields;
+            copy->referenced_field_no= ++cache->referenced_fields;
+            cache->with_length= TRUE;
 	    cache->pack_length+= cache->get_size_of_fld_offset();
             cache->pack_last_length+= cache->get_size_of_fld_offset();
-          }
-        }
+          }        }
       }
     } 
   }
@@ -17041,7 +17115,7 @@ int JOIN_CACHE_BKA::init()
   blob_ptr= copy_ptr;
   
   /* Now create local fields that are used to build ref for this key access */
-  copy= field_descr;
+  copy= field_descr+flag_fields;
   for (tab= join_tab-tables; tab < join_tab ; tab++)
   {
     length+= add_table_data_fields_to_join_cache(tab, &tab->table->tmp_set,
@@ -17049,16 +17123,19 @@ int JOIN_CACHE_BKA::init()
                                                  &copy, &copy_ptr);
   }
 
-  check_emb_key_usage();
+  use_emb_key= check_emb_key_usage();
 
   create_remaining_fields(FALSE);
 
   set_constants();
 
+  if (join_tab->is_single_inner_of_semi_join_with_first_match())
+    mrr_mode|= HA_MRR_SEMI_JOIN;
+
   if (alloc_buffer())
     DBUG_RETURN(1); 
 
-  reset(TRUE); 
+  reset(TRUE);
 
   DBUG_RETURN(0);
 }  
@@ -17104,6 +17181,7 @@ bool JOIN_CACHE_BKA::check_emb_key_usage
   Item *item; 
   KEY_PART_INFO *key_part;
   CACHE_FIELD *copy;
+  CACHE_FIELD *copy_end;
   uint len= 0;
   TABLE *table= join_tab->table;
   TABLE_REF *ref= &join_tab->ref;
@@ -17150,9 +17228,9 @@ bool JOIN_CACHE_BKA::check_emb_key_usage
     is not considered as embedded.
   */
   
-  for (copy= field_descr+flag_fields;
-       i < local_key_arg_fields;
-       i++, copy++)
+  copy= field_descr+flag_fields;
+  copy_end= copy+local_key_arg_fields;
+  for ( ; copy < copy_end; copy++)
   {
     if (copy->type != 0)
       return FALSE;
@@ -17187,7 +17265,7 @@ bool JOIN_CACHE_BKA::check_emb_key_usage
     }
   }
 
-  return ((use_emb_key= TRUE));
+  return TRUE;
 }    
 
 
@@ -17270,7 +17348,7 @@ uint JOIN_CACHE::write_record_data(uchar
   bool last_record;
   CACHE_FIELD *copy;
   CACHE_FIELD *copy_end;
-  uchar *cp= this->pos;
+  uchar *cp= pos;
   uchar *init_pos= cp;
   uchar *rec_len_ptr= 0;
  
@@ -17368,7 +17446,7 @@ uint JOIN_CACHE::write_record_data(uchar
     }
     /* Save the offset of the field to put it later at the end of the record */ 
     if (copy->referenced_field_no)
-      copy->offset= pos-curr_rec_pos;
+      copy->offset= cp-curr_rec_pos;
 
     if (copy->type == CACHE_BLOB)
     {
@@ -17484,6 +17562,7 @@ uint JOIN_CACHE::write_record_data(uchar
 void JOIN_CACHE::reset(bool for_writing)
 {
   pos= buff;
+  curr_rec_link= 0;
   if (for_writing)
   {
     records= 0;
@@ -17504,8 +17583,8 @@ void JOIN_CACHE::reset(bool for_writing)
     This default implementation of the virtual function put_record
     links the record that it written into the join buffer with
     the matching record in the previous cache if there is any.
-    The implementation assumes that prev_cache get_curr_rec() 
-    returns exactly the pointer to this matching record.
+    The implementation assumes that the function get_curr_link() 
+    will return exactly the pointer to this matching record.
 
   RETURN
     TRUE    if it has been decided that it should be the last record
@@ -17516,7 +17595,9 @@ void JOIN_CACHE::reset(bool for_writing)
 bool JOIN_CACHE::put_record()
 {
   bool is_full;
-  uchar *link = prev_cache ? prev_cache->get_curr_rec() : 0;
+  uchar *link= 0;
+  if (prev_cache)
+    link= prev_cache->get_curr_rec_link();
   write_record_data(link, &is_full);
   return is_full;
 }
@@ -17550,19 +17631,19 @@ bool JOIN_CACHE::put_record()
 bool JOIN_CACHE::get_record()
 { 
   bool res;
-  uchar *prev_rec_ptr= 0;
+  uchar *prev_rec_ptr;
   if (with_length)
     pos+= size_of_rec_len;
   if (prev_cache)
   {
-    prev_rec_ptr= prev_cache->get_rec_ref(pos);
     pos+= prev_cache->get_size_of_rec_offset();
-  }    
+    prev_rec_ptr= prev_cache->get_rec_ref(pos);
+  }
   curr_rec_pos= pos;
   if (!(res= read_all_record_fields() == 0))
   {
     pos+= referenced_fields*size_of_fld_ofs;
-    if (prev_rec_ptr)
+    if (prev_cache)
       prev_cache->get_record_by_pos(prev_rec_ptr);
   } 
   return res; 
@@ -17595,8 +17676,7 @@ void JOIN_CACHE::get_record_by_pos(uchar
   pos= save_pos;
   if (prev_cache)
   {
-    uchar *prev_rec_ptr= 
-      prev_cache->get_rec_ref(rec_ptr-prev_cache->get_size_of_rec_offset());
+    uchar *prev_rec_ptr= prev_cache->get_rec_ref(rec_ptr);
     prev_cache->get_record_by_pos(prev_rec_ptr);
   }
 }
@@ -17836,7 +17916,7 @@ bool JOIN_CACHE::skip_record_if_match()
   /* Check whether the match flag is on */
   if (test(*(pos+offset)))
   {
-    pos+= get_rec_length(pos);
+    pos+= size_of_rec_len + get_rec_length(pos);
     return TRUE;
   }
   return FALSE;
@@ -17887,7 +17967,7 @@ enum_nested_loop_state JOIN_CACHE::join_
   if (outer_join_first_inner)
     join_tab->not_null_compl= TRUE;
 
-  if (!outer_join_first_inner || join_tab->first_inner->not_null_compl)
+  if (!join_tab->first_inner || join_tab->first_inner->not_null_compl)
   {
     /* Find all records from join_tab that match records from join buffer */
     rc= join_matching_records(skip_last);   
@@ -18445,7 +18525,7 @@ enum_nested_loop_state JOIN_CACHE_BKA::j
   JOIN_TAB *tab;
   handler *file= join_tab->table->file;
   enum_nested_loop_state rc= NESTED_LOOP_OK;
-  uchar *rec_ptr;
+  uchar *rec_ptr= 0;
   bool check_only_first_match= join_tab->check_only_first_match();
 
   join_tab->table->null_row= 0;
@@ -18514,6 +18594,7 @@ enum_nested_loop_state JOIN_CACHE_BKA::j
             !(res= do_sj_dups_weedout(join->thd,
                                         join_tab->check_weed_out_table)))
         {
+          set_curr_rec_link(rec_ptr);
           rc= (join_tab->next_select)(join, join_tab+1, 0);
           if (rc != NESTED_LOOP_OK && rc != NESTED_LOOP_NO_MORE_ROWS)
           {
@@ -18575,7 +18656,6 @@ uint JOIN_CACHE_BKA::get_next_key(uchar 
   uint len;
   uint32 rec_len;
   uchar *init_pos;
-  uchar *rec_ptr;
   JOIN_CACHE *cache;
   
   if (pos > last_rec_pos)
@@ -18609,6 +18689,7 @@ uint JOIN_CACHE_BKA::get_next_key(uchar 
     /* Read key arguments from previous caches if there are any such fields */
     if (external_key_arg_fields)
     {
+      uchar *rec_ptr= curr_rec_pos;
       uint key_arg_count= external_key_arg_fields;
       CACHE_FIELD **copy_ptr= blob_ptr-key_arg_count;
       for (cache= prev_cache; key_arg_count; cache= cache->prev_cache)
@@ -18635,10 +18716,11 @@ uint JOIN_CACHE_BKA::get_next_key(uchar 
       Read the other key arguments from the current record. The fields for
       these arguments are always first in the sequence of the record's fields.
     */     
-    CACHE_FIELD *copy= field_descr;
+    CACHE_FIELD *copy= field_descr+flag_fields;
     CACHE_FIELD *copy_end= copy+local_key_arg_fields;
+    bool blob_in_rec_buff= blob_data_is_in_rec_buff(curr_rec_pos);
     for ( ; copy < copy_end; copy++)
-      read_record_field(copy, blob_data_is_in_rec_buff(curr_rec_pos));
+      read_record_field(copy, blob_in_rec_buff);
     
     /* Build the key over the fields read into the record buffers */ 
     TABLE_REF *ref= &join_tab->ref;
diff -Nrup a/sql/sql_select.h b/sql/sql_select.h
--- a/sql/sql_select.h	2008-03-31 23:17:45 -07:00
+++ b/sql/sql_select.h	2008-04-06 00:20:37 -07:00
@@ -284,13 +284,21 @@ typedef struct st_join_table {
     }
     return test(used_rowid_fields);
   }
+  bool is_inner_table_of_semi_join_with_first_match()
+  {
+    return first_sj_inner_tab != NULL;
+  }
+  bool is_inner_table_of_outer_join()
+  {
+    return first_inner != NULL;
+  }
   bool is_single_inner_of_semi_join_with_first_match()
   {
     return first_sj_inner_tab == this && last_sj_inner_tab == this;            
   }
   bool is_single_inner_of_outer_join()
   {
-    return first_inner && first_inner == last_inner;
+    return first_inner == this && first_inner->last_inner == this;
   }
   bool is_first_inner_for_outer_join()
   {
@@ -537,7 +545,19 @@ protected:
     Flag is set on if the blob data for the last record in the join buffer
     is in record buffers rather than in the join cache.
   */
-  bool last_rec_blob_data_is_in_rec_buff; 
+  bool last_rec_blob_data_is_in_rec_buff;
+
+  /* 
+    Pointer to the position to the current record link. 
+    Record links are used only with linked caches. Record links allow to set
+    connections between parts of one join record that are stored in different
+    join buffers.
+    In the simplest case a record link is just a pointer to the beginning of
+    the record stored in the buffer.
+    In a more general case a link could be a reference to an array of pointers
+    to records in the buffer. 
+  */
+  uchar *curr_rec_link;
 
   void calc_record_fields();     
   int alloc_fields(uint external_fields);
@@ -551,7 +571,7 @@ protected:
 
   uchar *get_rec_ref(uchar *ptr)
   {
-    return buff+get_offset(size_of_rec_ofs, ptr);
+    return buff+get_offset(size_of_rec_ofs, ptr-get_size_of_rec_offset());
   }
   ulong get_rec_length(uchar *ptr)
   { 
@@ -664,6 +684,15 @@ public:
 
   /* Shall return the position of the current record */
   virtual uchar *get_curr_rec() { return curr_rec_pos; }
+
+  /* Shall set the current record link */
+  virtual void set_curr_rec_link(uchar *link) { curr_rec_link= link; }
+
+  /* Shall return the current record link */
+  virtual uchar *get_curr_rec_link()
+  { 
+    return (curr_rec_link ? curr_rec_link : get_curr_rec());
+  }
      
   /* Join records from the join buffer with records from the next join table */    
   enum_nested_loop_state join_records(bool skip_last);
@@ -780,12 +809,14 @@ public:
     This constructor creates an unlinked BKA join cache. The cache is to be
     used to join table 'tab' to the result of joining the previous tables 
     specified by the 'j' parameter.
+    The MRR mode initially is set to 'flags'.
   */   
-  JOIN_CACHE_BKA(JOIN *j, JOIN_TAB *tab)
+  JOIN_CACHE_BKA(JOIN *j, JOIN_TAB *tab, uint flags)
   { 
     join= j;
     join_tab= tab;
     prev_cache= next_cache= 0;
+    mrr_mode= flags;    
   }
 
   /* 
@@ -793,8 +824,9 @@ public:
     used to join table 'tab' to the result of joining the previous tables 
     specified by the 'j' parameter. The parameter 'prev' specifies the cache
     object to which this cache is linked.
+    The MRR mode initially is set to 'flags'.
   */   
-  JOIN_CACHE_BKA(JOIN *j, JOIN_TAB *tab, JOIN_CACHE* prev)
+  JOIN_CACHE_BKA(JOIN *j, JOIN_TAB *tab, uint flags,  JOIN_CACHE* prev)
   { 
     join= j;
     join_tab= tab;
@@ -802,6 +834,7 @@ public:
     next_cache= 0;
     if (prev)
       prev->next_cache= this;
+    mrr_mode= flags;
   }
 
   /* Initialize the BNL cache */       
Thread
bk commit into 6.0 tree (igor:1.2608)igor6 Apr