diff options
author | Oystein Grovlen <oystein.grovlen@oracle.com> | 2011-01-12 11:27:31 +0100 |
---|---|---|
committer | Oystein Grovlen <oystein.grovlen@oracle.com> | 2011-01-12 11:27:31 +0100 |
commit | a648063319ad782c4845fc95d3ae9f20d5e3088c (patch) | |
tree | 3d3660184c4d2907cdd9c1985a9fd0183f10ba48 | |
parent | c04979b84127ef8aa435368d1281bfb4322e0054 (diff) | |
parent | 541e0fa8bf7ffaf7f443cdc2cc69721032aeefcf (diff) | |
download | mariadb-git-a648063319ad782c4845fc95d3ae9f20d5e3088c.tar.gz |
Merge fix for Bug#59211 to mysql-5.5-security
-rw-r--r-- | mysql-test/r/type_year.result | 14 | ||||
-rw-r--r-- | mysql-test/t/type_year.test | 10 | ||||
-rw-r--r-- | sql/item.h | 13 | ||||
-rw-r--r-- | sql/item_cmpfunc.cc | 9 |
4 files changed, 40 insertions, 6 deletions
diff --git a/mysql-test/r/type_year.result b/mysql-test/r/type_year.result index 8948214f565..2dc491c6166 100644 --- a/mysql-test/r/type_year.result +++ b/mysql-test/r/type_year.result @@ -341,4 +341,18 @@ ta_y s tb_y s 2001 2001 2001 2001 DROP TABLE t1; # +# Bug #59211: Select Returns Different Value for min(year) Function +# +CREATE TABLE t1(c1 YEAR(4)); +INSERT INTO t1 VALUES (1901),(2155),(0000); +SELECT * FROM t1; +c1 +1901 +2155 +0000 +SELECT COUNT(*) AS total_rows, MIN(c1) AS min_value, MAX(c1) FROM t1; +total_rows min_value MAX(c1) +3 0 2155 +DROP TABLE t1; +# End of 5.1 tests diff --git a/mysql-test/t/type_year.test b/mysql-test/t/type_year.test index d8da4ccc82c..1a9e66478e1 100644 --- a/mysql-test/t/type_year.test +++ b/mysql-test/t/type_year.test @@ -150,5 +150,15 @@ SELECT ta.y AS ta_y, ta.s, tb.y AS tb_y, tb.s FROM t1 ta, t1 tb HAVING ta_y = tb DROP TABLE t1; --echo # +--echo # Bug #59211: Select Returns Different Value for min(year) Function +--echo # + +CREATE TABLE t1(c1 YEAR(4)); +INSERT INTO t1 VALUES (1901),(2155),(0000); +SELECT * FROM t1; +SELECT COUNT(*) AS total_rows, MIN(c1) AS min_value, MAX(c1) FROM t1; +DROP TABLE t1; + +--echo # --echo End of 5.1 tests diff --git a/sql/item.h b/sql/item.h index 3fa11cfd8dd..a5d973be9e6 100644 --- a/sql/item.h +++ b/sql/item.h @@ -3203,11 +3203,10 @@ class Item_cache: public Item_basic_constant protected: Item *example; table_map used_table_map; - /* - Field that this object will get value from. This is set/used by + /** + Field that this object will get value from. This is used by index-based subquery engines to detect and remove the equality injected by IN->EXISTS transformation. - For all other uses of Item_cache, cached_field doesn't matter. */ Field *cached_field; enum enum_field_types cached_field_type; @@ -3275,6 +3274,14 @@ public: { return (value_cached || cache_value()) && !null_value; } + + /** + If this item caches a field value, return pointer to underlying field. + + @return Pointer to field, or NULL if this is not a cache for a field value. + */ + Field* field() { return cached_field; } + virtual void store(Item *item); virtual bool cache_value()= 0; bool basic_const_item() const diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index fe8ff3a74d0..0e989b310fa 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -1208,9 +1208,12 @@ get_year_value(THD *thd, Item ***item_arg, Item **cache_arg, value of 2000. */ Item *real_item= item->real_item(); - if (!(real_item->type() == Item::FIELD_ITEM && - ((Item_field *)real_item)->field->type() == MYSQL_TYPE_YEAR && - ((Item_field *)real_item)->field->field_length == 4)) + Field *field= NULL; + if (real_item->type() == Item::FIELD_ITEM) + field= ((Item_field *)real_item)->field; + else if (real_item->type() == Item::CACHE_ITEM) + field= ((Item_cache *)real_item)->field(); + if (!(field && field->type() == MYSQL_TYPE_YEAR && field->field_length == 4)) { if (value < 70) value+= 100; |