diff options
-rw-r--r-- | mysql-test/r/select.result | 20 | ||||
-rw-r--r-- | mysql-test/r/select_jcl6.result | 20 | ||||
-rw-r--r-- | mysql-test/r/select_pkeycache.result | 20 | ||||
-rw-r--r-- | mysql-test/t/select.test | 19 | ||||
-rw-r--r-- | sql/item_cmpfunc.h | 9 | ||||
-rw-r--r-- | sql/sql_select.cc | 7 |
6 files changed, 93 insertions, 2 deletions
diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 5a234c17409..3d1dc5ec170 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -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 diff --git a/mysql-test/r/select_jcl6.result b/mysql-test/r/select_jcl6.result index b7f278a327f..e2e0db128b3 100644 --- a/mysql-test/r/select_jcl6.result +++ b/mysql-test/r/select_jcl6.result @@ -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'; diff --git a/mysql-test/r/select_pkeycache.result b/mysql-test/r/select_pkeycache.result index 5a234c17409..3d1dc5ec170 100644 --- a/mysql-test/r/select_pkeycache.result +++ b/mysql-test/r/select_pkeycache.result @@ -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 diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index 890da70caad..e202e013377 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -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 diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 33f147b7b0f..1b8687cfcfc 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -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; + } }; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 75f810598cd..24b0cb952a1 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -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; |