diff --git a/mysql-test/r/subselect_mat_cost_bugs.result b/mysql-test/r/subselect_mat_cost_bugs.result index 919a6c6d38d..1e69578dffd 100644 --- a/mysql-test/r/subselect_mat_cost_bugs.result +++ b/mysql-test/r/subselect_mat_cost_bugs.result @@ -295,3 +295,24 @@ id select_type table type possible_keys key key_len ref rows Extra select c1 from t1 where c1 in (select kp1 from t2 where kp2 = 10 and c2 = 4) or c1 > 7; c1 drop table t1, t2; +# +# LP BUG#800679: Assertion `outer_join->table_count > 0' failed in +# JOIN::choose_subquery_plan() with materialization=on,semijoin=off +# +CREATE TABLE t1 ( f1 int); +insert into t1 values (1),(2); +CREATE TABLE t2 ( f1 int); +insert into t2 values (1),(2); +SET @@optimizer_switch='materialization=on,semijoin=off'; +EXPLAIN +SELECT * FROM t1 +WHERE (f1) IN (SELECT f1 FROM t2) +LIMIT 0; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where +SELECT * FROM t1 +WHERE (f1) IN (SELECT f1 FROM t2) +LIMIT 0; +f1 +drop table t1, t2; diff --git a/mysql-test/t/subselect_mat_cost_bugs.test b/mysql-test/t/subselect_mat_cost_bugs.test index 0240c9203b3..37c7b617760 100644 --- a/mysql-test/t/subselect_mat_cost_bugs.test +++ b/mysql-test/t/subselect_mat_cost_bugs.test @@ -326,3 +326,26 @@ select c1 from t1 where c1 in (select kp1 from t2 where kp2 = 10 and c2 = 4) or select c1 from t1 where c1 in (select kp1 from t2 where kp2 = 10 and c2 = 4) or c1 > 7; drop table t1, t2; + +--echo # +--echo # LP BUG#800679: Assertion `outer_join->table_count > 0' failed in +--echo # JOIN::choose_subquery_plan() with materialization=on,semijoin=off +--echo # + +CREATE TABLE t1 ( f1 int); +insert into t1 values (1),(2); +CREATE TABLE t2 ( f1 int); +insert into t2 values (1),(2); + +SET @@optimizer_switch='materialization=on,semijoin=off'; + +EXPLAIN +SELECT * FROM t1 +WHERE (f1) IN (SELECT f1 FROM t2) +LIMIT 0; + +SELECT * FROM t1 +WHERE (f1) IN (SELECT f1 FROM t2) +LIMIT 0; + +drop table t1, t2; diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index db7290af662..51a18956c5d 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -4360,7 +4360,7 @@ bool JOIN::choose_subquery_plan(table_map join_tables) by the IN predicate. */ outer_join= unit->outer_select() ? unit->outer_select()->join : NULL; - if (outer_join) + if (outer_join && outer_join->table_count > 0) { /* The index of the last JOIN_TAB in the outer JOIN where in_subs is @@ -4373,7 +4373,6 @@ bool JOIN::choose_subquery_plan(table_map join_tables) JOIN_TAB, and their join_tab_idx remains MAX_TABLES. Such predicates are evaluated for each complete row of the outer join. */ - DBUG_ASSERT(outer_join->table_count > 0); max_outer_join_tab_idx= (in_subs->get_join_tab_idx() == MAX_TABLES) ? outer_join->table_count - 1: in_subs->get_join_tab_idx();