Commit 650d3266 authored by Igor Babaev's avatar Igor Babaev

Fixed bug mdev-4952

When in function remove_eq_conds() a sub-formula of the processed condition
is replaced for another formula we should ensure that in the resulting
formula AND/OR levels must alternate.
parent 901737c9
...@@ -1848,4 +1848,18 @@ INSERT INTO t2 VALUES (3,'2000-03-06'), (4,'2007-09-25'); ...@@ -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; SELECT * FROM t1 LEFT JOIN t2 ON i1 = i2 WHERE d1 IS NULL AND d2 IS NULL;
i1 d1 i2 d2 i1 d1 i2 d2
DROP TABLE t1,t2; 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 optimizer_switch=@save_optimizer_switch;
...@@ -1859,6 +1859,20 @@ INSERT INTO t2 VALUES (3,'2000-03-06'), (4,'2007-09-25'); ...@@ -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; SELECT * FROM t1 LEFT JOIN t2 ON i1 = i2 WHERE d1 IS NULL AND d2 IS NULL;
i1 d1 i2 d2 i1 d1 i2 d2
DROP TABLE t1,t2; 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 optimizer_switch=@save_optimizer_switch;
set join_cache_level=default; set join_cache_level=default;
show variables like 'join_cache_level'; show variables like 'join_cache_level';
......
...@@ -1392,4 +1392,22 @@ SELECT * FROM t1 LEFT JOIN t2 ON i1 = i2 WHERE d1 IS NULL AND d2 IS NULL; ...@@ -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; 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; SET optimizer_switch=@save_optimizer_switch;
...@@ -13407,7 +13407,20 @@ remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value) ...@@ -13407,7 +13407,20 @@ remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value)
} }
else 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; should_fix_fields= 1;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment