diff --git a/mysql-test/r/subselect4.result b/mysql-test/r/subselect4.result index e8b43758753..0929657173f 100644 --- a/mysql-test/r/subselect4.result +++ b/mysql-test/r/subselect4.result @@ -1219,7 +1219,7 @@ EXPLAIN SELECT * FROM (t2 LEFT JOIN t1 ON t1.c1) LEFT JOIN t3 on t3.c1 WHERE 's' IN (SELECT c1 FROM t2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found -1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; FirstMatch(t1) +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Start temporary; End temporary 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) 1 PRIMARY t3 ALL NULL NULL NULL NULL 3 Using where SELECT * FROM (t2 LEFT JOIN t1 ON t1.c1) LEFT JOIN t3 on t3.c1 WHERE 's' IN (SELECT c1 FROM t2); @@ -1227,7 +1227,7 @@ c1 c1 c1 EXPLAIN SELECT * FROM t4 LEFT JOIN t2 ON t4.c1 WHERE 's' IN (SELECT c1 FROM t2); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; FirstMatch +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Start temporary; End temporary 1 PRIMARY t4 index NULL PRIMARY 3 NULL 2 Using index; Using join buffer (flat, BNL join) 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where SELECT * FROM t4 LEFT JOIN t2 ON t4.c1 WHERE 's' IN (SELECT c1 FROM t2); diff --git a/mysql-test/r/subselect_sj.result b/mysql-test/r/subselect_sj.result index e6e09efde13..084bc515625 100644 --- a/mysql-test/r/subselect_sj.result +++ b/mysql-test/r/subselect_sj.result @@ -1457,8 +1457,8 @@ explain select * from t0 where a in (select t1.a from t1 left join t2 on t1.a=t2.a); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t0 ALL NULL NULL NULL NULL 2 -1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where -1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where; FirstMatch(t0) +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where; Start temporary +1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where; End temporary select * from t0 where a in (select t1.a from t1 left join t2 on t1.a=t2.a); a 1 diff --git a/mysql-test/r/subselect_sj2.result b/mysql-test/r/subselect_sj2.result index f942f48e207..e71486ab4a8 100644 --- a/mysql-test/r/subselect_sj2.result +++ b/mysql-test/r/subselect_sj2.result @@ -267,10 +267,10 @@ explain select * from t0 where a in (select t2.a+t3.a from t1 left join (t2 join t3) on t2.a=t1.a and t3.a=t1.a); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t0 ALL NULL NULL NULL NULL 10 -1 PRIMARY t1 index NULL a 5 NULL 10 Using index +1 PRIMARY t0 ALL NULL NULL NULL NULL 10 Start temporary +1 PRIMARY t1 index NULL a 5 NULL 10 Using index; Using join buffer (flat, BNL join) 1 PRIMARY t2 ref a a 5 test.t1.a 1 Using where; Using index -1 PRIMARY t3 ref a a 5 test.t1.a 1 Using where; Using index; FirstMatch(t0) +1 PRIMARY t3 ref a a 5 test.t1.a 1 Using where; Using index; End temporary drop table t0, t1,t2,t3; CREATE TABLE t1 ( ID int(11) NOT NULL auto_increment, diff --git a/mysql-test/r/subselect_sj2_jcl6.result b/mysql-test/r/subselect_sj2_jcl6.result index 53aeff190b0..ef3d7700704 100644 --- a/mysql-test/r/subselect_sj2_jcl6.result +++ b/mysql-test/r/subselect_sj2_jcl6.result @@ -275,10 +275,10 @@ explain select * from t0 where a in (select t2.a+t3.a from t1 left join (t2 join t3) on t2.a=t1.a and t3.a=t1.a); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t0 ALL NULL NULL NULL NULL 10 +1 PRIMARY t0 ALL NULL NULL NULL NULL 10 Start temporary 1 PRIMARY t1 index NULL a 5 NULL 10 Using index; Using join buffer (flat, BNL join) 1 PRIMARY t2 ref a a 5 test.t1.a 1 Using where; Using index -1 PRIMARY t3 ref a a 5 test.t1.a 1 Using where; Using index; FirstMatch(t0) +1 PRIMARY t3 ref a a 5 test.t1.a 1 Using where; Using index; End temporary drop table t0, t1,t2,t3; CREATE TABLE t1 ( ID int(11) NOT NULL auto_increment, diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index 057a70cc22e..9fb392c20f4 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -2160,7 +2160,8 @@ void advance_sj_state(JOIN *join, table_map remaining_tables, table_map handled_by_fm_or_ls= 0; /* FirstMatch Strategy */ if (new_join_tab->emb_sj_nest && - optimizer_flag(join->thd, OPTIMIZER_SWITCH_FIRSTMATCH)) + optimizer_flag(join->thd, OPTIMIZER_SWITCH_FIRSTMATCH) && + !join->outer_join) { const table_map outer_corr_tables= new_join_tab->emb_sj_nest->nested_join->sj_corr_tables | @@ -2255,7 +2256,7 @@ void advance_sj_state(JOIN *join, table_map remaining_tables, If we got an option to use LooseScan for the current table, start considering using LooseScan strategy */ - if (loose_scan_pos->read_time != DBL_MAX) + if (loose_scan_pos->read_time != DBL_MAX && !join->outer_join) { pos->first_loosescan_table= idx; pos->loosescan_need_tables=