From dbc84ff96c021f9d8b5968812a416bc6890d015a Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Fri, 23 Aug 2013 22:17:02 -0700 Subject: [PATCH] Fixed bug mdev-4942. Made sure that degenerate conjunctions/disjunctions are obtained from AND/OR conditions. --- mysql-test/r/join_outer.result | 12 ++++++++++++ mysql-test/r/join_outer_jcl6.result | 12 ++++++++++++ mysql-test/t/join_outer.test | 16 ++++++++++++++++ sql/sql_select.cc | 3 ++- 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/join_outer.result b/mysql-test/r/join_outer.result index 684bfb3836e..b73edc8c52e 100644 --- a/mysql-test/r/join_outer.result +++ b/mysql-test/r/join_outer.result @@ -1836,4 +1836,16 @@ SELECT a.* FROM t1 a LEFT JOIN t1 b ON a.id = b.id WHERE a.modified > b.modified or b.modified IS NULL; id modified DROP TABLE t1; +# +# Bug mdev-4942: LEFT JOIN with conjunctive +# IS NULL in WHERE +# causes an assert failure +# +CREATE TABLE t1 ( i1 int, d1 date ); +INSERT INTO t1 VALUES (1,'2001-06-26'), (2,'2000-11-16'); +CREATE TABLE t2 ( i2 int, d2 date NOT NULL ); +INSERT INTO t2 VALUES (3,'2000-03-06'), (4,'2007-09-25'); +SELECT * FROM t1 LEFT JOIN t2 ON i1 = i2 WHERE d1 IS NULL AND d2 IS NULL; +i1 d1 i2 d2 +DROP TABLE t1,t2; SET optimizer_switch=@save_optimizer_switch; diff --git a/mysql-test/r/join_outer_jcl6.result b/mysql-test/r/join_outer_jcl6.result index 4f4c16199e9..a588767d754 100644 --- a/mysql-test/r/join_outer_jcl6.result +++ b/mysql-test/r/join_outer_jcl6.result @@ -1847,6 +1847,18 @@ SELECT a.* FROM t1 a LEFT JOIN t1 b ON a.id = b.id WHERE a.modified > b.modified or b.modified IS NULL; id modified DROP TABLE t1; +# +# Bug mdev-4942: LEFT JOIN with conjunctive +# IS NULL in WHERE +# causes an assert failure +# +CREATE TABLE t1 ( i1 int, d1 date ); +INSERT INTO t1 VALUES (1,'2001-06-26'), (2,'2000-11-16'); +CREATE TABLE t2 ( i2 int, d2 date NOT NULL ); +INSERT INTO t2 VALUES (3,'2000-03-06'), (4,'2007-09-25'); +SELECT * FROM t1 LEFT JOIN t2 ON i1 = i2 WHERE d1 IS NULL AND d2 IS NULL; +i1 d1 i2 d2 +DROP TABLE t1,t2; SET optimizer_switch=@save_optimizer_switch; set join_cache_level=default; show variables like 'join_cache_level'; diff --git a/mysql-test/t/join_outer.test b/mysql-test/t/join_outer.test index 8c0ee82e1fa..99f4b1e1315 100644 --- a/mysql-test/t/join_outer.test +++ b/mysql-test/t/join_outer.test @@ -1376,4 +1376,20 @@ SELECT a.* FROM t1 a LEFT JOIN t1 b ON a.id = b.id DROP TABLE t1; +--echo # +--echo # Bug mdev-4942: LEFT JOIN with conjunctive +--echo # IS NULL in WHERE +--echo # causes an assert failure +--echo # + +CREATE TABLE t1 ( i1 int, d1 date ); +INSERT INTO t1 VALUES (1,'2001-06-26'), (2,'2000-11-16'); + +CREATE TABLE t2 ( i2 int, d2 date NOT NULL ); +INSERT INTO t2 VALUES (3,'2000-03-06'), (4,'2007-09-25'); + +SELECT * FROM t1 LEFT JOIN t2 ON i1 = i2 WHERE d1 IS NULL AND d2 IS NULL; + +DROP TABLE t1,t2; + SET optimizer_switch=@save_optimizer_switch; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 6b4fc70a353..52c7283b2d9 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -13350,7 +13350,8 @@ remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value) In these cases the disjunct/conjunct must be merged into the argument list of cond. */ - if (new_item->type() == Item::COND_ITEM) + if (new_item->type() == Item::COND_ITEM && + item->type() == Item::COND_ITEM) { DBUG_ASSERT(((Item_cond *) cond)->functype() == ((Item_cond *) new_item)->functype());