diff --git a/mysql-test/r/subselect_mat_cost.result b/mysql-test/r/subselect_mat_cost.result index 87b0ca405c0..fd2b6bbb143 100644 --- a/mysql-test/r/subselect_mat_cost.result +++ b/mysql-test/r/subselect_mat_cost.result @@ -3895,3 +3895,23 @@ FROM t3 RIGHT JOIN t1 ON t1.pk = t3.f1 WHERE t3.f3 OR ( 3 ) IN ( SELECT f2 FROM t2 ); pk drop table t1,t2,t3; +# +# LP BUG#714999 Second crash in select_describe() with nested subqueries +# +CREATE TABLE t1 ( pk int(11)) ; +INSERT INTO t1 VALUES (29); +CREATE TABLE t2 ( f1 varchar(1)) ; +INSERT INTO t2 VALUES ('f'),('d'); +CREATE TABLE t3 ( f2 varchar(1)) ; +EXPLAIN SELECT f2 FROM t3 WHERE ( +SELECT MAX( pk ) FROM t1 +WHERE EXISTS ( +SELECT DISTINCT f1 +FROM t2 +) +) IS NULL ; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 SUBQUERY t1 system NULL NULL NULL NULL 1 +3 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using temporary +drop table t1, t2; diff --git a/mysql-test/t/subselect_mat_cost.test b/mysql-test/t/subselect_mat_cost.test index 5631b533155..175dc39284b 100644 --- a/mysql-test/t/subselect_mat_cost.test +++ b/mysql-test/t/subselect_mat_cost.test @@ -345,3 +345,25 @@ FROM t3 RIGHT JOIN t1 ON t1.pk = t3.f1 WHERE t3.f3 OR ( 3 ) IN ( SELECT f2 FROM t2 ); drop table t1,t2,t3; + +--echo # +--echo # LP BUG#714999 Second crash in select_describe() with nested subqueries +--echo # + +CREATE TABLE t1 ( pk int(11)) ; +INSERT INTO t1 VALUES (29); + +CREATE TABLE t2 ( f1 varchar(1)) ; +INSERT INTO t2 VALUES ('f'),('d'); + +CREATE TABLE t3 ( f2 varchar(1)) ; + +EXPLAIN SELECT f2 FROM t3 WHERE ( + SELECT MAX( pk ) FROM t1 + WHERE EXISTS ( + SELECT DISTINCT f1 + FROM t2 + ) +) IS NULL ; + +drop table t1, t2; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 2e460c3d64a..f22934e3053 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -10966,7 +10966,7 @@ remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value) } } } - if (cond->const_item()) + if (cond->const_item() && !cond->is_expensive()) { *cond_value= eval_const_cond(cond) ? Item::COND_TRUE : Item::COND_FALSE; return (COND*) 0;