List:Commits« Previous MessageNext Message »
From:Alexey Kopytov Date:May 28 2007 7:40am
Subject:bk commit into 5.1 tree (kaa:1.2503)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of kaa. When kaa 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@stripped, 2007-05-28 11:40:50+04:00, kaa@stripped +8 -0
  Merge polly.local:/home/kaa/src/maint/bug28121/my50-bug28121
  into  polly.local:/home/kaa/src/maint/bug28121/my51-bug28121
  MERGE: 1.1810.2868.29

  include/m_string.h@stripped, 2007-05-28 11:37:14+04:00, kaa@stripped +0 -0
    Auto merged
    MERGE: 1.37.1.3

  mysql-test/r/type_float.result@stripped, 2007-05-28 11:37:14+04:00, kaa@stripped +0 -0
    Auto merged
    MERGE: 1.42.1.9

  mysql-test/t/type_float.test@stripped, 2007-05-28 11:37:14+04:00, kaa@stripped +0 -0
    Auto merged
    MERGE: 1.29.1.4

  sql/field.cc@stripped, 2007-05-28 11:40:47+04:00, kaa@stripped +2 -2
    Manual merge.
    MERGE: 1.256.1.92

  sql/field.h@stripped, 2007-05-28 11:40:47+04:00, kaa@stripped +5 -7
    Manual merge.
    MERGE: 1.153.12.17

  sql/init.cc@stripped, 2007-05-28 11:37:14+04:00, kaa@stripped +0 -0
    Auto merged
    MERGE: 1.16.1.4

  sql/mysql_priv.h@stripped, 2007-05-28 11:37:14+04:00, kaa@stripped +0 -0
    Auto merged
    MERGE: 1.290.1.158

  sql/mysqld.cc@stripped, 2007-05-28 11:37:14+04:00, kaa@stripped +0 -0
    Auto merged
    MERGE: 1.439.1.169

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	kaa
# Host:	polly.local
# Root:	/home/kaa/src/maint/bug28121/my51-bug28121/RESYNC

--- 1.46/include/m_string.h	2006-12-23 22:19:44 +03:00
+++ 1.47/include/m_string.h	2007-05-28 11:37:14 +04:00
@@ -92,6 +92,10 @@ extern char *stpcpy(char *, const char *
 extern char NEAR _dig_vec_upper[];
 extern char NEAR _dig_vec_lower[];
 
+/* Defined in strtod.c */
+extern const double log_10[310];
+extern const double log_01[310];
+
 #ifdef BAD_STRING_COMPILER
 #define strmov(A,B)  (memccpy(A,B,0,INT_MAX)-1)
 #else

--- 1.387/sql/field.cc	2007-04-29 17:47:35 +04:00
+++ 1.388/sql/field.cc	2007-05-28 11:40:47 +04:00
@@ -3769,56 +3769,9 @@ int Field_float::store(const char *from,
 int Field_float::store(double nr)
 {
   ASSERT_COLUMN_MARKED_FOR_WRITE;
-  float j;
-  int error= 0;
+  int error= truncate(&nr, FLT_MAX);
+  float j= nr;
 
-  if (isnan(nr))
-  {
-    j= 0;
-    set_null();
-    set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
-    error= 1;
-  }
-  else if (unsigned_flag && nr < 0)
-  {
-    j= 0;
-    set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
-    error= 1;
-  }
-  else
-  {
-    double max_value;
-    if (dec >= NOT_FIXED_DEC)
-    {
-      max_value= FLT_MAX;
-    }
-    else
-    {
-      uint tmp=min(field_length,array_elements(log_10)-1);
-      max_value= (log_10[tmp]-1)/log_10[dec];
-      /*
-	The following comparison is needed to not get an overflow if nr
-	is close to FLT_MAX
-      */
-      if (fabs(nr) < FLT_MAX/10.0e+32)
-	nr= floor(nr*log_10[dec]+0.5)/log_10[dec];
-    }
-    if (nr < -max_value)
-    {
-      j= (float)-max_value;
-      set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
-      error= 1;
-    }
-    else if (nr > max_value)
-    {
-      j= (float)max_value;
-      set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
-      error= 1;
-    }
-    else
-      j= (float) nr;
-  }
-  
 #ifdef WORDS_BIGENDIAN
   if (table->s->db_low_byte_first)
   {
@@ -4062,48 +4015,7 @@ int Field_double::store(const char *from
 int Field_double::store(double nr)
 {
   ASSERT_COLUMN_MARKED_FOR_WRITE;
-  int error= 0;
-
-  if (isnan(nr))
-  {
-    nr= 0;
-    set_null();
-    set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
-    error= 1;
-  }
-  else if (unsigned_flag && nr < 0)
-  {
-    nr= 0;
-    set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
-    error= 1;
-  }
-  else 
-  {
-    double max_value;
-    if (not_fixed)
-    {
-      max_value= DBL_MAX;
-    }
-    else
-    {
-      uint tmp=min(field_length,array_elements(log_10)-1);
-      max_value= (log_10[tmp]-1)/log_10[dec];
-      if (fabs(nr) < DBL_MAX/10.0e+32)
-	nr= floor(nr*log_10[dec]+0.5)/log_10[dec];
-    }
-    if (nr < -max_value)
-    {
-      nr= -max_value;
-      set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
-      error= 1;
-    }
-    else if (nr > max_value)
-    {
-      nr= max_value;
-      set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
-      error= 1;
-    }
-  }
+  int error= truncate(&nr, DBL_MAX);
 
 #ifdef WORDS_BIGENDIAN
   if (table->s->db_low_byte_first)
@@ -4121,6 +4033,63 @@ int Field_double::store(longlong nr, boo
 {
   return Field_double::store(unsigned_val ? ulonglong2double((ulonglong) nr) :
                              (double) nr);
+}
+
+/*
+  If a field has fixed length, truncate the double argument pointed to by 'nr'
+  appropriately.
+  Also ensure that the argument is within [-max_value; max_value] range.
+*/
+
+int Field_real::truncate(double *nr, double max_value)
+{
+  int error= 1;
+  double res= *nr;
+  
+  if (isnan(res))
+  {
+    res= 0;
+    set_null();
+    set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
+    goto end;
+  }
+  else if (unsigned_flag && res < 0)
+  {
+    res= 0;
+    set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
+    goto end;
+  }
+
+  if (!not_fixed)
+  {
+    uint order= field_length - dec;
+    uint step= array_elements(log_10) - 1;
+    max_value= 1.0;
+    for (; order > step; order-= step)
+      max_value*= log_10[step];
+    max_value*= log_10[order];
+    max_value-= 1.0 / log_10[dec];
+
+    double tmp= rint((res - floor(res)) * log_10[dec]) / log_10[dec];
+    res= floor(res) + tmp;
+  }
+  
+  if (res < -max_value)
+  {
+   res= -max_value;
+   set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
+  }
+  else if (res > max_value)
+  {
+    res= max_value;
+    set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, 1);
+  }
+  else
+    error= 0;
+
+end:
+  *nr= res;
+  return error;
 }
 
 

--- 1.222/sql/field.h	2007-04-29 17:47:35 +04:00
+++ 1.223/sql/field.h	2007-05-28 11:40:47 +04:00
@@ -530,15 +530,19 @@ public:
 /* base class for float and double and decimal (old one) */
 class Field_real :public Field_num {
 public:
+  my_bool not_fixed;
+
   Field_real(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
              uchar null_bit_arg, utype unireg_check_arg,
              const char *field_name_arg,
              uint8 dec_arg, bool zero_arg, bool unsigned_arg)
     :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg,
-               field_name_arg, dec_arg, zero_arg, unsigned_arg)
+               field_name_arg, dec_arg, zero_arg, unsigned_arg),
+    not_fixed(dec_arg >= NOT_FIXED_DEC)
     {}
   int store_decimal(const my_decimal *);
   my_decimal *val_decimal(my_decimal *);
+  int truncate(double *nr, double max_length);
   uint32 max_display_length() { return field_length; }
 };
 
@@ -823,29 +827,24 @@ public:
 
 class Field_double :public Field_real {
 public:
-  my_bool not_fixed;
   Field_double(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
 	       uchar null_bit_arg,
 	       enum utype unireg_check_arg, const char *field_name_arg,
 	       uint8 dec_arg,bool zero_arg,bool unsigned_arg)
     :Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
                 unireg_check_arg, field_name_arg,
-                dec_arg, zero_arg, unsigned_arg),
-     not_fixed(dec_arg >= NOT_FIXED_DEC)
+                dec_arg, zero_arg, unsigned_arg)
     {}
   Field_double(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
 	       uint8 dec_arg)
     :Field_real((char*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0,
-                NONE, field_name_arg, dec_arg, 0, 0),
-     not_fixed(dec_arg >= NOT_FIXED_DEC)
+                NONE, field_name_arg, dec_arg, 0, 0)
     {}
   Field_double(uint32 len_arg, bool maybe_null_arg, const char *field_name_arg,
-	       uint8 dec_arg, my_bool not_fixed_srg)
+	       uint8 dec_arg, my_bool not_fixed_arg)
     :Field_real((char*) 0, len_arg, maybe_null_arg ? (uchar*) "" : 0, (uint) 0,
-                NONE, field_name_arg, dec_arg, 0, 0),
-     not_fixed(not_fixed_srg)
-    {}
-  enum_field_types type() const { return MYSQL_TYPE_DOUBLE;}
+                NONE, field_name_arg, dec_arg, 0, 0)
+    {not_fixed= not_fixed_arg; }
   enum ha_base_keytype key_type() const { return HA_KEYTYPE_DOUBLE; }
   int  store(const char *to,uint length,CHARSET_INFO *charset);
   int  store(double nr);

--- 1.20/sql/init.cc	2007-01-31 11:40:34 +03:00
+++ 1.21/sql/init.cc	2007-05-28 11:37:14 +04:00
@@ -21,8 +21,6 @@
 
 void unireg_init(ulong options)
 {
-  uint i;
-  double nr;
   DBUG_ENTER("unireg_init");
 
   MYSYS_PROGRAM_DONT_USE_CURSES();
@@ -40,16 +38,5 @@ void unireg_init(ulong options)
   VOID(strmov(reg_ext,".frm"));
   reg_ext_length= 4;
   specialflag=SPECIAL_SAME_DB_NAME | options;  /* Set options from argv */
-  /* Make a tab of powers of 10 */
-  for (i=0,nr=1.0; i < array_elements(log_10) ; i++)
-  {					/* It's used by filesort... */
-    log_10[i]= nr ; nr*= 10.0;
-  }
-  /* Make a tab of powers of 0.1 */
-  for (i= 0, nr= 0.1; i < array_elements(log_01); i++)
-  {
-    log_01[i]= nr;
-    nr*= 0.1;
-  }
   DBUG_VOID_RETURN;
 }

--- 1.503/sql/mysql_priv.h	2007-04-28 23:20:14 +04:00
+++ 1.504/sql/mysql_priv.h	2007-05-28 11:37:14 +04:00
@@ -1621,8 +1621,6 @@ extern uint reg_ext_length;
 extern char glob_hostname[FN_REFLEN], mysql_home[FN_REFLEN];
 extern char pidfile_name[FN_REFLEN], system_time_zone[30], *opt_init_file;
 extern char log_error_file[FN_REFLEN], *opt_tc_log_file;
-extern double log_10[32];
-extern double log_01[32];
 extern ulonglong log_10_int[20];
 extern ulonglong keybuff_size;
 extern ulonglong thd_startup_options;

--- 1.638/sql/mysqld.cc	2007-04-26 18:02:53 +04:00
+++ 1.639/sql/mysqld.cc	2007-05-28 11:37:14 +04:00
@@ -512,8 +512,6 @@ ulong expire_logs_days = 0;
 ulong rpl_recovery_rank=0;
 const char *log_output_str= "TABLE";
 
-double log_10[32];			/* 10 potences */
-double log_01[32];
 time_t server_start_time;
 
 char mysql_home[FN_REFLEN], pidfile_name[FN_REFLEN], system_time_zone[30];

--- 1.54/mysql-test/r/type_float.result	2007-03-23 00:04:28 +03:00
+++ 1.55/mysql-test/r/type_float.result	2007-05-28 11:37:14 +04:00
@@ -344,3 +344,36 @@ create table t1 (s1 float(0,2));
 ERROR 42000: For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column 's1').
 create table t1 (s1 float(1,2));
 ERROR 42000: For float(M,D), double(M,D) or decimal(M,D), M must be >= D (column 's1').
+create table t1 (f1 double(200, 0));
+insert into t1 values (1e199), (-1e199);
+insert into t1 values (1e200), (-1e200);
+insert into t1 values (2e200), (-2e200);
+Warnings:
+Warning	1264	Out of range value adjusted for column 'f1' at row 1
+Warning	1264	Out of range value adjusted for column 'f1' at row 2
+select f1 + 0e0 from t1;
+f1 + 0e0
+1e+199
+-1e+199
+1e+200
+-1e+200
+1e+200
+-1e+200
+drop table t1;
+create table t1 (f1 float(30, 0));
+insert into t1 values (1e29), (-1e29);
+insert into t1 values (1e30), (-1e30);
+insert into t1 values (2e30), (-2e30);
+Warnings:
+Warning	1264	Out of range value adjusted for column 'f1' at row 1
+Warning	1264	Out of range value adjusted for column 'f1' at row 2
+select f1 + 0e0 from t1;
+f1 + 0e0
+1.0000000150475e+29
+-1.0000000150475e+29
+1.0000000150475e+30
+-1.0000000150475e+30
+1.0000000150475e+30
+-1.0000000150475e+30
+drop table t1;
+End of 5.0 tests

--- 1.33/mysql-test/t/type_float.test	2007-01-31 11:40:33 +03:00
+++ 1.34/mysql-test/t/type_float.test	2007-05-28 11:37:14 +04:00
@@ -222,3 +222,23 @@ drop table t1;
 create table t1 (s1 float(0,2));
 --error 1427
 create table t1 (s1 float(1,2));
+
+#
+# Bug #28121 "INSERT or UPDATE into DOUBLE(200,0) field being truncated to 31 digits"
+#
+
+create table t1 (f1 double(200, 0));
+insert into t1 values (1e199), (-1e199);
+insert into t1 values (1e200), (-1e200);
+insert into t1 values (2e200), (-2e200);
+select f1 + 0e0 from t1;
+drop table t1;
+
+create table t1 (f1 float(30, 0));
+insert into t1 values (1e29), (-1e29);
+insert into t1 values (1e30), (-1e30);
+insert into t1 values (2e30), (-2e30);
+select f1 + 0e0 from t1;
+drop table t1;
+
+--echo End of 5.0 tests
Thread
bk commit into 5.1 tree (kaa:1.2503)Alexey Kopytov28 May