From ac6653aacc71b7b48dc1cd6f52124cd5382ae198 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 10 Feb 2011 22:53:30 +0200 Subject: [PATCH] Fix LP BUG#714999 Analysis: The crash in EXPLAIN resulted from an attempt to print the name of the internal temporary table created to compute distinct for the innermost subquery of the test case. Such tables do not have a corresponding TABLE_LIST (table reference), hence the crash. The reason for this was that the subquery was executed as part of constant condition evaluation before EXPLAIN attempts to print the table name. During the subquery execution, the subquery JOIN_TAB and its table are substituted by a temporary table in make_simple_join. Solution: Similar to the analogous case for other Items than the IS NULL function, do not evaluate expensive constant conditions. --- mysql-test/r/subselect_mat_cost.result | 20 ++++++++++++++++++++ mysql-test/t/subselect_mat_cost.test | 22 ++++++++++++++++++++++ sql/sql_select.cc | 2 +- 3 files changed, 43 insertions(+), 1 deletion(-) 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;