Commit 926b0f54 authored by Igor Babaev's avatar Igor Babaev

Fixed bug mdev-4250.

This is a bug in the legacy code. It did not manifest itself because
it was masked by other bugs that were fixed by the patches for
mdev-4172 and mdev-4177.
parent 888db0ec
......@@ -5112,4 +5112,24 @@ INSERT INTO t2 VALUES (3),(4);
SELECT * FROM t1, t2 WHERE a=3 AND a=b;
a b
drop table t1,t2;
#
# Bug mdev-4250: wrong transformation of WHERE condition with OR
#
CREATE TABLE t1 (pk int PRIMARY KEY, a int);
INSERT INTO t1 VALUES (3,0), (2,0), (4,1), (5,0), (1,0);
SELECT * FROM t1 WHERE (1=2 OR t1.pk=2) AND t1.a <> 0;
pk a
EXPLAIN EXTENDED
SELECT * FROM t1 WHERE (1=2 OR t1.pk=2) AND t1.a <> 0;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
Warnings:
Note 1003 select 2 AS `pk`,0 AS `a` from `test`.`t1` where ((0 <> 0))
DROP TABLE t1;
SELECT * FROM mysql.time_zone
WHERE ( NOT (Use_leap_seconds <= Use_leap_seconds AND Time_zone_id != 1)
AND Time_zone_id = Time_zone_id
OR Time_zone_id <> Time_zone_id )
AND Use_leap_seconds <> 'N';
Time_zone_id Use_leap_seconds
End of 5.3 tests
......@@ -5123,6 +5123,26 @@ INSERT INTO t2 VALUES (3),(4);
SELECT * FROM t1, t2 WHERE a=3 AND a=b;
a b
drop table t1,t2;
#
# Bug mdev-4250: wrong transformation of WHERE condition with OR
#
CREATE TABLE t1 (pk int PRIMARY KEY, a int);
INSERT INTO t1 VALUES (3,0), (2,0), (4,1), (5,0), (1,0);
SELECT * FROM t1 WHERE (1=2 OR t1.pk=2) AND t1.a <> 0;
pk a
EXPLAIN EXTENDED
SELECT * FROM t1 WHERE (1=2 OR t1.pk=2) AND t1.a <> 0;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
Warnings:
Note 1003 select 2 AS `pk`,0 AS `a` from `test`.`t1` where ((0 <> 0))
DROP TABLE t1;
SELECT * FROM mysql.time_zone
WHERE ( NOT (Use_leap_seconds <= Use_leap_seconds AND Time_zone_id != 1)
AND Time_zone_id = Time_zone_id
OR Time_zone_id <> Time_zone_id )
AND Use_leap_seconds <> 'N';
Time_zone_id Use_leap_seconds
End of 5.3 tests
set join_cache_level=default;
show variables like 'join_cache_level';
......
......@@ -5112,4 +5112,24 @@ INSERT INTO t2 VALUES (3),(4);
SELECT * FROM t1, t2 WHERE a=3 AND a=b;
a b
drop table t1,t2;
#
# Bug mdev-4250: wrong transformation of WHERE condition with OR
#
CREATE TABLE t1 (pk int PRIMARY KEY, a int);
INSERT INTO t1 VALUES (3,0), (2,0), (4,1), (5,0), (1,0);
SELECT * FROM t1 WHERE (1=2 OR t1.pk=2) AND t1.a <> 0;
pk a
EXPLAIN EXTENDED
SELECT * FROM t1 WHERE (1=2 OR t1.pk=2) AND t1.a <> 0;
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
Warnings:
Note 1003 select 2 AS `pk`,0 AS `a` from `test`.`t1` where ((0 <> 0))
DROP TABLE t1;
SELECT * FROM mysql.time_zone
WHERE ( NOT (Use_leap_seconds <= Use_leap_seconds AND Time_zone_id != 1)
AND Time_zone_id = Time_zone_id
OR Time_zone_id <> Time_zone_id )
AND Use_leap_seconds <> 'N';
Time_zone_id Use_leap_seconds
End of 5.3 tests
......@@ -4286,4 +4286,23 @@ INSERT INTO t2 VALUES (3),(4);
SELECT * FROM t1, t2 WHERE a=3 AND a=b;
drop table t1,t2;
--echo #
--echo # Bug mdev-4250: wrong transformation of WHERE condition with OR
--echo #
CREATE TABLE t1 (pk int PRIMARY KEY, a int);
INSERT INTO t1 VALUES (3,0), (2,0), (4,1), (5,0), (1,0);
SELECT * FROM t1 WHERE (1=2 OR t1.pk=2) AND t1.a <> 0;
EXPLAIN EXTENDED
SELECT * FROM t1 WHERE (1=2 OR t1.pk=2) AND t1.a <> 0;
DROP TABLE t1;
SELECT * FROM mysql.time_zone
WHERE ( NOT (Use_leap_seconds <= Use_leap_seconds AND Time_zone_id != 1)
AND Time_zone_id = Time_zone_id
OR Time_zone_id <> Time_zone_id )
AND Use_leap_seconds <> 'N';
--echo End of 5.3 tests
......@@ -1798,6 +1798,15 @@ public:
{
upper_levels= 0;
}
void copy(COND_EQUAL &cond_equal)
{
max_members= cond_equal.max_members;
upper_levels= cond_equal.upper_levels;
if (cond_equal.current_level.is_empty())
current_level.empty();
else
current_level= cond_equal.current_level;
}
};
......
......@@ -11383,7 +11383,9 @@ static COND *build_equal_items_for_cond(THD *thd, COND *cond,
item_equal->n_field_items());
}
((Item_cond_and*)cond)->cond_equal= cond_equal;
((Item_cond_and*)cond)->cond_equal.copy(cond_equal);
cond_equal.current_level=
((Item_cond_and*)cond)->cond_equal.current_level;
inherited= &(((Item_cond_and*)cond)->cond_equal);
}
/*
......@@ -11461,7 +11463,8 @@ static COND *build_equal_items_for_cond(THD *thd, COND *cond,
set_if_bigger(thd->lex->current_select->max_equal_elems,
item_equal->n_field_items());
}
and_cond->cond_equal= cond_equal;
and_cond->cond_equal.copy(cond_equal);
cond_equal.current_level= and_cond->cond_equal.current_level;
args->concat((List<Item> *)&cond_equal.current_level);
return and_cond;
......
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