From 20c9084deb6075f675ebabc5fd073f8ff93130e2 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Wed, 4 May 2011 18:08:44 -0700 Subject: [PATCH] Fixed LP bug #776295. If the value of the flag cond_false of an Item_equal object is true then the print method must return the string '0'. --- mysql-test/r/explain.result | 15 +++++++++++++++ mysql-test/r/join_outer.result | 2 +- mysql-test/r/join_outer_jcl6.result | 2 +- mysql-test/t/explain.test | 16 ++++++++++++++++ sql/item_cmpfunc.cc | 5 +++++ 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/explain.result b/mysql-test/r/explain.result index 25fc524bc9b..4bcdf7344a7 100644 --- a/mysql-test/r/explain.result +++ b/mysql-test/r/explain.result @@ -298,3 +298,18 @@ id select_type table type possible_keys key key_len ref rows Extra DEALLOCATE PREPARE stmt; DROP TABLE t1; End of 5.1 tests. +# +# Bug#776295: EXPLAIN EXTENDED with always false multiple equality +# in the WHERE condition of a derived table +# +CREATE TABLE t1 (a int) ; +CREATE TABLE t2 (a int) ; +INSERT INTO t2 VALUES (8); +EXPLAIN EXTENDED +SELECT * FROM ( SELECT t1.a FROM t1,t2 WHERE t2.a = t1.a ) AS t; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY system NULL NULL NULL NULL 0 0.00 const row not found +2 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL no matching row in const table +Warnings: +Note 1003 select NULL AS `a` from (select NULL AS `a` from `test`.`t1` join `test`.`t2` where 0) `t` +DROP TABLE t1,t2; diff --git a/mysql-test/r/join_outer.result b/mysql-test/r/join_outer.result index 691bedbe428..c1171570dca 100644 --- a/mysql-test/r/join_outer.result +++ b/mysql-test/r/join_outer.result @@ -1302,7 +1302,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 system NULL NULL NULL NULL 1 100.00 1 SIMPLE t2 system NULL NULL NULL NULL 1 100.00 Warnings: -Note 1003 select '1' AS `f1`,NULL AS `f2`,'3' AS `f3`,NULL AS `f1`,NULL AS `f2` from `test`.`t1` left join `test`.`t2` on(multiple equal(NULL)) where ((coalesce('1',NULL),'3') in ((1,3),(2,2))) +Note 1003 select '1' AS `f1`,NULL AS `f2`,'3' AS `f3`,NULL AS `f1`,NULL AS `f2` from `test`.`t1` left join `test`.`t2` on(0) where ((coalesce('1',NULL),'3') in ((1,3),(2,2))) SELECT * FROM t1 LEFT JOIN t2 ON t1.f2 = t2.f2 WHERE (COALESCE(t1.f1, t2.f1), f3) IN ((1, 3), (2, 2)); f1 f2 f3 f1 f2 diff --git a/mysql-test/r/join_outer_jcl6.result b/mysql-test/r/join_outer_jcl6.result index 7ca0b89df97..5b679b9b083 100644 --- a/mysql-test/r/join_outer_jcl6.result +++ b/mysql-test/r/join_outer_jcl6.result @@ -1309,7 +1309,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 system NULL NULL NULL NULL 1 100.00 1 SIMPLE t2 system NULL NULL NULL NULL 1 100.00 Warnings: -Note 1003 select '1' AS `f1`,NULL AS `f2`,'3' AS `f3`,NULL AS `f1`,NULL AS `f2` from `test`.`t1` left join `test`.`t2` on(multiple equal(NULL)) where ((coalesce('1',NULL),'3') in ((1,3),(2,2))) +Note 1003 select '1' AS `f1`,NULL AS `f2`,'3' AS `f3`,NULL AS `f1`,NULL AS `f2` from `test`.`t1` left join `test`.`t2` on(0) where ((coalesce('1',NULL),'3') in ((1,3),(2,2))) SELECT * FROM t1 LEFT JOIN t2 ON t1.f2 = t2.f2 WHERE (COALESCE(t1.f1, t2.f1), f3) IN ((1, 3), (2, 2)); f1 f2 f3 f1 f2 diff --git a/mysql-test/t/explain.test b/mysql-test/t/explain.test index c6c30b58341..8380aa668b0 100644 --- a/mysql-test/t/explain.test +++ b/mysql-test/t/explain.test @@ -265,3 +265,19 @@ DEALLOCATE PREPARE stmt; DROP TABLE t1; --echo End of 5.1 tests. + +--echo # +--echo # Bug#776295: EXPLAIN EXTENDED with always false multiple equality +--echo # in the WHERE condition of a derived table +--echo # + +CREATE TABLE t1 (a int) ; + +CREATE TABLE t2 (a int) ; +INSERT INTO t2 VALUES (8); + +EXPLAIN EXTENDED +SELECT * FROM ( SELECT t1.a FROM t1,t2 WHERE t2.a = t1.a ) AS t; + +DROP TABLE t1,t2; + diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 73191982b64..f4dd9b4de12 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -5923,6 +5923,11 @@ Item *Item_equal::transform(Item_transformer transformer, uchar *arg) void Item_equal::print(String *str, enum_query_type query_type) { + if (cond_false) + { + str->append('0'); + return; + } str->append(func_name()); str->append('('); List_iterator_fast it(equal_items);