Pantek Library
Hosting Provided By
CybrHost
High Speed Hosting

bk commit into 5.0 tree (ramil:1.2542) BUG#30782

From: <ramil(at)mysql.com>
Date: Mon Oct 22 2007 - 08:11:44 EDT


Below is the list of changes that have just been committed into a local 5.0 repository of ram. When ram does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository.
For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@1.2542, 2007-10-22 17:11:40+05:00, ramil@mysql.com +4 -0   Fix for bug #30782: Truncated UNSIGNED BIGINT columns only in SELECT w/ CASE,   JOIN, and ORDER BY   

  Problem: improper maximum length calculation of the CASE function leads to   decimal value truncation (storing/retrieving decimal field values).   

  Fix: accurately calculate maximum length/unsigned flag/decimals parameters   of the CASE function.

  mysql-test/r/case.result@1.29, 2007-10-22 17:11:39+05:00, ramil@mysql.com +19 -1     Fix for bug #30782: Truncated UNSIGNED BIGINT columns only in SELECT w/ CASE,     JOIN, and ORDER BY

  • test result.

  mysql-test/t/case.test@1.22, 2007-10-22 17:11:39+05:00, ramil@mysql.com +19 -2     Fix for bug #30782: Truncated UNSIGNED BIGINT columns only in SELECT w/ CASE,     JOIN, and ORDER BY

  • test case.

  sql/item_cmpfunc.cc@1.264, 2007-10-22 17:11:39+05:00, ramil@mysql.com +28 -6     Fix for bug #30782: Truncated UNSIGNED BIGINT columns only in SELECT w/ CASE,     JOIN, and ORDER BY

  • accurately calculate Item_func_case::max_length/unsigned_flag/decimals.

  sql/item_cmpfunc.h@1.156, 2007-10-22 17:11:39+05:00, ramil@mysql.com +2 -0     Fix for bug #30782: Truncated UNSIGNED BIGINT columns only in SELECT w/ CASE,     JOIN, and ORDER BY

  • accurately calculate Item_func_case::max_length/unsigned_flag/decimals.
Do you need help?X

diff -Nrup a/mysql-test/r/case.result b/mysql-test/r/case.result

--- a/mysql-test/r/case.result	2006-09-13 16:18:12 +05:00

+++ b/mysql-test/r/case.result 2007-10-22 17:11:39 +05:00
@@ -1,4 +1,4 @@
-drop table if exists t1;
+drop table if exists t1, t2;

 select CASE "b" when "a" then 1 when "b" then 2 END;  CASE "b" when "a" then 1 when "b" then 2 END  2
@@ -200,3 +200,21 @@ CEMPNUM	EMPMUM1	EMPNUM2
 0.00	0	0.00
 2.00	2	NULL

 DROP TABLE t1,t2;
+End of 4.1 tests
+create table t1 (a int, b bigint unsigned);
+create table t2 (c int);
+insert into t1 (a, b) values (1,4572794622775114594), (2,18196094287899841997),
+(3,11120436154190595086);
+insert into t2 (c) values (1), (2), (3);
+select t1.a, (case t1.a when 0 then 0 else t1.b end) d from t1
+join t2 on t1.a=t2.c order by d;
+a d
+1 4572794622775114594
+3 11120436154190595086
+2 18196094287899841997
+select t1.a, (case t1.a when 0 then 0 else t1.b end) d from t1
+join t2 on t1.a=t2.c where b=11120436154190595086 order by d;
+a d
+3 11120436154190595086
+drop table t1, t2;
+End of 5.0 tests

diff -Nrup a/mysql-test/t/case.test b/mysql-test/t/case.test
--- a/mysql-test/t/case.test	2006-09-13 16:18:12 +05:00

+++ b/mysql-test/t/case.test 2007-10-22 17:11:39 +05:00
@@ -3,7 +3,7 @@
 #  

 --disable_warnings
-drop table if exists t1;
+drop table if exists t1, t2;

 --enable_warnings  

 select CASE "b" when "a" then 1 when "b" then 2 END; @@ -152,4 +152,21 @@ SELECT IFNULL(t2.EMPNUM,t1.EMPNUM) AS CE

   FROM t1 LEFT JOIN t2 ON t1.EMPNUM=t2.EMPNUM;  

 DROP TABLE t1,t2;
-# End of 4.1 tests
+
+--echo End of 4.1 tests
+
+#
+# #30782: Truncated UNSIGNED BIGINT columns
+#
+create table t1 (a int, b bigint unsigned);
+create table t2 (c int);
+insert into t1 (a, b) values (1,4572794622775114594), (2,18196094287899841997),
+ (3,11120436154190595086);
+insert into t2 (c) values (1), (2), (3);
+select t1.a, (case t1.a when 0 then 0 else t1.b end) d from t1
+ join t2 on t1.a=t2.c order by d;
+select t1.a, (case t1.a when 0 then 0 else t1.b end) d from t1
+ join t2 on t1.a=t2.c where b=11120436154190595086 order by d;
+drop table t1, t2;
+
+--echo End of 5.0 tests

diff -Nrup a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc

--- a/sql/item_cmpfunc.cc	2007-07-16 02:03:32 +05:00

+++ b/sql/item_cmpfunc.cc 2007-10-22 17:11:39 +05:00
@@ -2530,6 +2530,22 @@ bool Item_func_case::fix_fields(THD *thd }

+void Item_func_case::agg_str_lengths(Item* arg)
+{
+ set_if_bigger(max_length, arg->max_length);
+ set_if_bigger(decimals, arg->decimals);
+ unsigned_flag= unsigned_flag && arg->unsigned_flag;
+}
+
+
+void Item_func_case::agg_num_lengths(Item *arg)
+{
+ uint len= arg->max_length - arg->decimals - (arg->unsigned_flag ? 0 : 1);
+ set_if_bigger(max_length, len);
+ set_if_bigger(decimals, arg->decimals);
+ unsigned_flag= unsigned_flag && arg->unsigned_flag;
+}
+
 

 void Item_func_case::fix_length_and_dec()  {
@@ -2579,15 +2595,21 @@ void Item_func_case::fix_length_and_dec(    

   max_length=0;
   decimals=0;
- for (uint i=0 ; i < ncases ; i+=2)
+ unsigned_flag= TRUE;
+ if (cached_result_type == STRING_RESULT)

Do you need more help?X

   {
- set_if_bigger(max_length,args[i+1]->max_length); - set_if_bigger(decimals,args[i+1]->decimals);
+ for (uint i= 0; i < ncases; i+= 2)
+ agg_str_lengths(args[i + 1]);
+ if (else_expr_num != -1)
+ agg_str_lengths(args[else_expr_num]);

   }
- if (else_expr_num != -1)
+ else

   {
- set_if_bigger(max_length,args[else_expr_num]->max_length); - set_if_bigger(decimals,args[else_expr_num]->decimals);
+ for (uint i= 0; i < ncases; i+= 2)
+ agg_num_lengths(args[i + 1]);
+ if (else_expr_num != -1)
+ agg_num_lengths(args[else_expr_num]);
+ max_length+= decimals + (unsigned_flag ? 0 : 1);

   }
 }  

diff -Nrup a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h

--- a/sql/item_cmpfunc.h	2007-08-31 04:23:36 +05:00

+++ b/sql/item_cmpfunc.h 2007-10-22 17:11:39 +05:00
@@ -753,6 +753,8 @@ public:

   void print(String *str);
   Item *find_item(String *str);
   CHARSET_INFO *compare_collation() { return cmp_collation.collation; }
+ void agg_str_lengths(Item *arg);
+ void agg_num_lengths(Item *arg);

 };    

-- 
MySQL Code Commits Mailing List
For list archives: 
http://lists.mysql.com/commits
To unsubscribe:    
http://lists.mysql.com/commits?unsub=lists@pantek.com
Received on Mon Oct 22 08:12:03 2007

This archive was generated by hypermail 2.1.8 : Thu Jul 03 2008 - 10:21:27 EDT


Contact Us  Legal Notices  Order Services Online 
Pantek Home  Privacy Policy  IT news  Site Map  Pantek Library