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/r/type_enum.result | 15 | ||||
-rw-r--r-- | mysql-test/t/select.test | 19 | ||||
-rw-r--r-- | mysql-test/t/type_enum.test | 15 | ||||
-rw-r--r-- | sql/field.h | 1 | ||||
-rw-r--r-- | sql/item_cmpfunc.h | 9 | ||||
-rw-r--r-- | sql/sql_join_cache.cc | 2 | ||||
-rw-r--r-- | sql/sql_select.cc | 7 | ||||
-rw-r--r-- | strings/decimal.c | 4 |
11 files changed, 128 insertions, 4 deletions
diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 378b20829f3..3d16d37c5f1 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -5302,4 +5302,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 b5c6f89b87b..467f940c85d 100644 --- a/mysql-test/r/select_jcl6.result +++ b/mysql-test/r/select_jcl6.result @@ -5313,6 +5313,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 378b20829f3..3d16d37c5f1 100644 --- a/mysql-test/r/select_pkeycache.result +++ b/mysql-test/r/select_pkeycache.result @@ -5302,4 +5302,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/type_enum.result b/mysql-test/r/type_enum.result index 813f912c5af..d373d14c089 100644 --- a/mysql-test/r/type_enum.result +++ b/mysql-test/r/type_enum.result @@ -1854,3 +1854,18 @@ a DROP TABLE t1; End of 5.1 tests +# +# MDEV-4241: Assertion failure: scale >= 0 && precision > 0 && +# scale <= precision in decimal_bin_size +# +CREATE TABLE t1 ( +f1 enum('1','2','3','4','5') +) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2); +SELECT AVG(f1) FROM t1; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def AVG(f1) 246 7 6 Y 32896 4 63 +AVG(f1) +1.5000 +drop table t1; +End of 5.3 tests diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index 44eaf7130a7..af507b1f7ef 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -4460,5 +4460,24 @@ 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/mysql-test/t/type_enum.test b/mysql-test/t/type_enum.test index 2043342e2c8..5b0b70631a5 100644 --- a/mysql-test/t/type_enum.test +++ b/mysql-test/t/type_enum.test @@ -221,3 +221,18 @@ SELECT a FROM t1 WHERE a=0; DROP TABLE t1; --echo End of 5.1 tests + +--echo # +--echo # MDEV-4241: Assertion failure: scale >= 0 && precision > 0 && +--echo # scale <= precision in decimal_bin_size +--echo # +CREATE TABLE t1 ( + f1 enum('1','2','3','4','5') +) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(2); +--enable_metadata +SELECT AVG(f1) FROM t1; +--disable_metadata +drop table t1; + +--echo End of 5.3 tests diff --git a/sql/field.h b/sql/field.h index a6382026d97..8df1c6572f4 100644 --- a/sql/field.h +++ b/sql/field.h @@ -1999,6 +1999,7 @@ public: bool has_charset(void) const { return TRUE; } /* enum and set are sorted as integers */ CHARSET_INFO *sort_charset(void) const { return &my_charset_bin; } + uint decimals() const { return 0; } virtual uchar *pack(uchar *to, const uchar *from, uint max_length); virtual const uchar *unpack(uchar *to, const uchar *from, diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index cad8d7d34ac..1f490d3b5fc 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -1791,6 +1791,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_join_cache.cc b/sql/sql_join_cache.cc index 8424dd00d93..e97f0e185c6 100644 --- a/sql/sql_join_cache.cc +++ b/sql/sql_join_cache.cc @@ -775,7 +775,7 @@ ulong JOIN_CACHE::get_min_join_buffer_size() tab= next_linear_tab(join, tab, WITHOUT_BUSH_ROOTS)) { len+= tab->get_max_used_fieldlength(); - len_last=+ tab->get_used_fieldlength(); + len_last+= tab->get_used_fieldlength(); } size_t len_addon= get_record_max_affix_length() + get_max_key_addon_space_per_record(); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 3ac1b03a69d..e1397b05bff 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -11659,7 +11659,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); } /* @@ -11737,7 +11739,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; diff --git a/strings/decimal.c b/strings/decimal.c index f318a234d3f..3245f224b44 100644 --- a/strings/decimal.c +++ b/strings/decimal.c @@ -1445,7 +1445,9 @@ int decimal_bin_size(int precision, int scale) intg0=intg/DIG_PER_DEC1, frac0=scale/DIG_PER_DEC1, intg0x=intg-intg0*DIG_PER_DEC1, frac0x=scale-frac0*DIG_PER_DEC1; - DBUG_ASSERT(scale >= 0 && precision > 0 && scale <= precision); + DBUG_ASSERT(scale >= 0); + DBUG_ASSERT(precision > 0); + DBUG_ASSERT(scale <= precision); return intg0*sizeof(dec1)+dig2bytes[intg0x]+ frac0*sizeof(dec1)+dig2bytes[frac0x]; } |