summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/join_outer.result14
-rw-r--r--mysql-test/r/join_outer_jcl6.result14
-rw-r--r--mysql-test/t/join_outer.test18
-rw-r--r--sql/sql_select.cc15
4 files changed, 60 insertions, 1 deletions
diff --git a/mysql-test/r/join_outer.result b/mysql-test/r/join_outer.result
index 6e92d47a145..c30f1584607 100644
--- a/mysql-test/r/join_outer.result
+++ b/mysql-test/r/join_outer.result
@@ -1848,4 +1848,18 @@ 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;
+#
+# Bug mdev-4952: LEFT JOIN with disjunctive
+# <non-nullable datetime field> IS NULL in WHERE
+# causes an assert failure
+#
+CREATE TABLE t1 (a1 int, b1 int NOT NULL) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1, 10), (2, 11);
+CREATE TABLE t2 (dt datetime NOT NULL, a2 int, b2 int) ENGINE=MyISAM;
+INSERT INTO t2 VALUES
+('2006-10-08 09:34:54', 1, 100), ('2001-01-19 01:04:43', 2, 200);
+SELECT * FROM t1 LEFT JOIN t2 ON a1 = a2
+WHERE ( dt IS NULL OR FALSE ) AND b2 IS NULL;
+a1 b1 dt a2 b2
+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 a78a7352f2d..ccb402a642c 100644
--- a/mysql-test/r/join_outer_jcl6.result
+++ b/mysql-test/r/join_outer_jcl6.result
@@ -1859,6 +1859,20 @@ 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;
+#
+# Bug mdev-4952: LEFT JOIN with disjunctive
+# <non-nullable datetime field> IS NULL in WHERE
+# causes an assert failure
+#
+CREATE TABLE t1 (a1 int, b1 int NOT NULL) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1, 10), (2, 11);
+CREATE TABLE t2 (dt datetime NOT NULL, a2 int, b2 int) ENGINE=MyISAM;
+INSERT INTO t2 VALUES
+('2006-10-08 09:34:54', 1, 100), ('2001-01-19 01:04:43', 2, 200);
+SELECT * FROM t1 LEFT JOIN t2 ON a1 = a2
+WHERE ( dt IS NULL OR FALSE ) AND b2 IS NULL;
+a1 b1 dt a2 b2
+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 99f4b1e1315..ec48818f57f 100644
--- a/mysql-test/t/join_outer.test
+++ b/mysql-test/t/join_outer.test
@@ -1392,4 +1392,22 @@ SELECT * FROM t1 LEFT JOIN t2 ON i1 = i2 WHERE d1 IS NULL AND d2 IS NULL;
DROP TABLE t1,t2;
+--echo #
+--echo # Bug mdev-4952: LEFT JOIN with disjunctive
+--echo # <non-nullable datetime field> IS NULL in WHERE
+--echo # causes an assert failure
+--echo #
+
+CREATE TABLE t1 (a1 int, b1 int NOT NULL) ENGINE=MyISAM;
+INSERT INTO t1 VALUES (1, 10), (2, 11);
+
+CREATE TABLE t2 (dt datetime NOT NULL, a2 int, b2 int) ENGINE=MyISAM;
+INSERT INTO t2 VALUES
+('2006-10-08 09:34:54', 1, 100), ('2001-01-19 01:04:43', 2, 200);
+
+SELECT * FROM t1 LEFT JOIN t2 ON a1 = a2
+ WHERE ( dt IS NULL OR FALSE ) AND b2 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 c35dea5bd20..79c7925dbcf 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -13407,7 +13407,20 @@ remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value)
}
else
{
- li.replace(new_item);
+ if (new_item->type() == Item::COND_ITEM &&
+ ((Item_cond*) new_item)->functype() ==
+ ((Item_cond*) cond)->functype())
+ {
+ List<Item> *new_item_arg_list=
+ ((Item_cond *) new_item)->argument_list();
+ uint cnt= new_item_arg_list->elements;
+ li.replace(*new_item_arg_list);
+ /* Make iterator li ignore new items */
+ for (cnt--; cnt; cnt--)
+ li++;
+ }
+ else
+ li.replace(new_item);
should_fix_fields= 1;
}
}