List:Commits« Previous MessageNext Message »
From:Sergey Glukhov Date:March 30 2011 9:32am
Subject:bzr commit into mysql-5.1 branch (sergey.glukhov:3644) Bug#11766270
View as plain text  
#At file:///home/gluh/MySQL/mysql-5.1/ based on revid:sergey.glukhov@stripped

 3644 Sergey Glukhov	2011-03-30
      Bug#11766270 59343: YEAR(4): INCORRECT RESULT AND VALGRIND WARNINGS WITH MIN/MAX, UNION
      When we create temporary result table for UNION
      incorrect max_length for YEAR field is used and
      it leads to incorrect field value and incorrect
      result string length as YEAR field value calculation
      depends on field length.
      Fix: for YEAR field use Field_year::max_length for
      Item_sum_hybrid::max_length intialization.
     @ mysql-test/r/func_group.result
        test case
     @ mysql-test/t/func_group.test
        test case
     @ sql/item_sum.cc
        for YEAR field use Field_year::max_length for
        Item_sum_hybrid::max_length intialization.

    modified:
      mysql-test/r/func_group.result
      mysql-test/t/func_group.test
      sql/item_sum.cc
=== modified file 'mysql-test/r/func_group.result'
--- a/mysql-test/r/func_group.result	2010-12-21 12:30:07 +0000
+++ b/mysql-test/r/func_group.result	2011-03-30 09:31:58 +0000
@@ -1737,4 +1737,13 @@ SELECT MIN(GET_LOCK('aaaaaaaaaaaaaaaaa',
 SELECT MIN(GET_LOCK('aaaaaaaaaaaaaaaaa',0) / '0b1111111111111111111111111111111111111111111111111111111111111111111111111' ^ (RAND()));
 SELECT RELEASE_LOCK('aaaaaaaaaaaaaaaaa');
 #
+# Bug #11766270  59343: YEAR(4): INCORRECT RESULT AND VALGRIND WARNINGS WITH MIN/MAX, UNION
+#
+CREATE TABLE t1(f1 YEAR(4));
+INSERT INTO t1 VALUES (0000),(2001);
+(SELECT MAX(f1) FROM t1) UNION (SELECT MAX(f1) FROM t1);
+MAX(f1)
+2001
+DROP TABLE t1;
+#
 End of 5.1 tests

=== modified file 'mysql-test/t/func_group.test'
--- a/mysql-test/t/func_group.test	2010-12-21 12:30:07 +0000
+++ b/mysql-test/t/func_group.test	2011-03-30 09:31:58 +0000
@@ -1118,5 +1118,14 @@ SELECT RELEASE_LOCK('aaaaaaaaaaaaaaaaa')
 --enable_result_log
 
 --echo #
+--echo # Bug #11766270  59343: YEAR(4): INCORRECT RESULT AND VALGRIND WARNINGS WITH MIN/MAX, UNION
+--echo #
+
+CREATE TABLE t1(f1 YEAR(4));
+INSERT INTO t1 VALUES (0000),(2001);
+(SELECT MAX(f1) FROM t1) UNION (SELECT MAX(f1) FROM t1);
+DROP TABLE t1;
+
+--echo #
 --echo End of 5.1 tests
 

=== modified file 'sql/item_sum.cc'
--- a/sql/item_sum.cc	2011-02-22 21:03:32 +0000
+++ b/sql/item_sum.cc	2011-03-30 09:31:58 +0000
@@ -640,6 +640,19 @@ Item_sum_hybrid::fix_fields(THD *thd, It
   else
     hybrid_field_type= Item::field_type();
 
+  /*
+    We have to use original max_length for YEAR fields
+    as YEAR field value calculation depends on
+    field length and if this Item_sum_hybrid is
+    used as prototype for temporary table field with
+    max_length == 20 then we can get incorrect value
+    and incorrect result string length
+    (see Field_year::val_str()).
+  */
+  if (hybrid_field_type == MYSQL_TYPE_YEAR &&
+      hybrid_type == INT_RESULT)
+    max_length= item->max_length;
+
   if (check_sum_func(thd, ref))
     return TRUE;
 


Attachment: [text/bzr-bundle] bzr/sergey.glukhov@oracle.com-20110330093158-7ediaz6fsldjp11w.bundle
Thread
bzr commit into mysql-5.1 branch (sergey.glukhov:3644) Bug#11766270Sergey Glukhov30 Mar