MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Alexey Kopytov Date:January 28 2009 5:59pm
Subject:bzr commit into mysql-5.0-bugteam branch (Alexey.Kopytov:2728)
Bug#21205
View as plain text  
#At file:///Users/kaa/src/bzr/bug21205/my50-bug21205/ based on revid:azundris@stripped

 2728 Alexey Kopytov	2009-01-28
      Fix for bug #21205: Different number of digits for float/double/real in --ps-protocol
      
      Various parts of code used different 'precision' arguments for sprintf("%g") when converting
      floating point numbers to a string. This led to differences in results in some cases 
      depending on whether the text-based or prepared statements protocol is used for a query.
      
      Fixed by changing arguments to sprintf("%g") to always be 15 (DBL_DIG) so that results are
      consistent regardless of the protocol.
      
      This patch will be null-merged to 6.0 as the problem does not exists there (fixed by the
      patch for WL#2934).
modified:
  client/sql_string.cc
  libmysql/libmysql.c
  mysql-test/r/archive_gis.result
  mysql-test/r/func_group.result
  mysql-test/r/func_math.result
  mysql-test/r/func_str.result
  mysql-test/r/gis.result
  mysql-test/r/innodb_gis.result
  mysql-test/r/select.result
  mysql-test/r/sp.result
  mysql-test/r/type_float.result
  mysql-test/t/type_float.test
  sql/sql_string.cc

per-file messages:
  client/sql_string.cc
    Use 15 (DBL_DIG) as a precision argument for sprintf(), as Field_double::val_str() does.
  libmysql/libmysql.c
    Use 15 (DBL_DIG) as a precision argument for sprintf(), as Field_double::val_str() does.
  mysql-test/r/archive_gis.result
    Fixed test results to take additional precision into account.
  mysql-test/r/func_group.result
    Fixed test results to take additional precision into account.
  mysql-test/r/func_math.result
    Fixed test results to take additional precision into account.
  mysql-test/r/func_str.result
    Fixed test results to take additional precision into account.
  mysql-test/r/gis.result
    Fixed test results to take additional precision into account.
  mysql-test/r/innodb_gis.result
    Fixed test results to take additional precision into account.
  mysql-test/r/select.result
    Fixed test results to take additional precision into account.
  mysql-test/r/sp.result
    Fixed test results to take additional precision into account.
  mysql-test/r/type_float.result
    Fixed test results to take additional precision into account.
  mysql-test/t/type_float.test
    Fixed test results to take additional precision into account.
  sql/sql_string.cc
    Use 15 (DBL_DIG) as a precision argument for sprintf(), as Field_double::val_str() does.
=== modified file 'client/sql_string.cc'
--- a/client/sql_string.cc	2007-03-28 17:46:42 +0000
+++ b/client/sql_string.cc	2009-01-28 17:59:08 +0000
@@ -125,7 +125,7 @@ bool String::set(double num,uint decimal
   str_charset=cs;
   if (decimals >= NOT_FIXED_DEC)
   {
-    uint32 len= my_sprintf(buff,(buff, "%.14g",num));// Enough for a DATETIME
+    uint32 len= my_sprintf(buff,(buff, "%.15g",num));// Enough for a DATETIME
     return copy(buff, len, &my_charset_latin1, cs, &dummy_errors);
   }
 #ifdef HAVE_FCONVERT
@@ -677,7 +677,7 @@ void String::qs_append(const char *str, 
 void String::qs_append(double d)
 {
   char *buff = Ptr + str_length;
-  str_length+= my_sprintf(buff, (buff, "%.14g", d));
+  str_length+= my_sprintf(buff, (buff, "%.15g", d));
 }
 
 void String::qs_append(double *d)

=== modified file 'libmysql/libmysql.c'
--- a/libmysql/libmysql.c	2008-03-29 07:52:16 +0000
+++ b/libmysql/libmysql.c	2009-01-28 17:59:08 +0000
@@ -3786,13 +3786,13 @@ static void fetch_float_with_conversion(
 #undef NOT_FIXED_DEC
     {
       /*
-        The 14 below is to ensure that the server and client has the same
+        DBL_DIG below is to ensure that the server and client has the same
         precisions. This will ensure that on the same machine you get the
         same value as a string independent of the protocol you use.
       */
       sprintf(buff, "%-*.*g", (int) min(sizeof(buff)-1,
                                         param->buffer_length),
-	      min(14,width), value);
+              min(DBL_DIG, width), value);
       end= strcend(buff, ' ');
       *end= 0;
     }

=== modified file 'mysql-test/r/archive_gis.result'
--- a/mysql-test/r/archive_gis.result	2007-03-29 09:20:08 +0000
+++ b/mysql-test/r/archive_gis.result	2009-01-28 17:59:08 +0000
@@ -291,7 +291,7 @@ Note	1003	select astext(startpoint(`test
 SELECT fid, AsText(Centroid(g)) FROM gis_polygon ORDER by fid;
 fid	AsText(Centroid(g))
 108	POINT(15 15)
-109	POINT(25.416666666667 25.416666666667)
+109	POINT(25.4166666666667 25.4166666666667)
 110	POINT(20 10)
 SELECT fid, Area(g) FROM gis_polygon ORDER by fid;
 fid	Area(g)
@@ -325,8 +325,8 @@ fid	IsClosed(g)
 116	0
 SELECT fid, AsText(Centroid(g)) FROM gis_multi_polygon ORDER by fid;
 fid	AsText(Centroid(g))
-117	POINT(55.588527753042 17.426536064114)
-118	POINT(55.588527753042 17.426536064114)
+117	POINT(55.5885277530424 17.426536064114)
+118	POINT(55.5885277530424 17.426536064114)
 119	POINT(2 2)
 SELECT fid, Area(g) FROM gis_multi_polygon ORDER by fid;
 fid	Area(g)

=== modified file 'mysql-test/r/func_group.result'
--- a/mysql-test/r/func_group.result	2008-11-24 15:30:47 +0000
+++ b/mysql-test/r/func_group.result	2009-01-28 17:59:08 +0000
@@ -61,7 +61,7 @@ grp	sum
 NULL	NULL
 1	7
 2	20.25
-3	45.483163247594
+3	45.4831632475944
 create table t2 (grp int, a bigint unsigned, c char(10));
 insert into t2 select grp,max(a)+max(grp),max(c) from t1 group by grp;
 replace into t2 select grp, a, c from t1 limit 2,1;
@@ -1195,7 +1195,7 @@ std(s1/s2)
 0.21325764
 select std(o1/o2) from bug22555;
 std(o1/o2)
-0.21325763586649
+0.213257635866493
 select std(e1/e2) from bug22555;
 std(e1/e2)
 0.21325764
@@ -1221,7 +1221,7 @@ round(std(s1/s2), 17)
 0.21325763586649341
 select std(o1/o2) from bug22555;
 std(o1/o2)
-0.21325763586649
+0.213257635866493
 select round(std(e1/e2), 17) from bug22555;
 round(std(e1/e2), 17)
 0.21325763586649341
@@ -1246,7 +1246,7 @@ round(std(s1/s2), 17)
 0.21325763586649341
 select std(o1/o2) from bug22555;
 std(o1/o2)
-0.21325763586649
+0.213257635866493
 select round(std(e1/e2), 17) from bug22555;
 round(std(e1/e2), 17)
 0.21325763586649341

=== modified file 'mysql-test/r/func_math.result'
--- a/mysql-test/r/func_math.result	2007-10-01 09:51:59 +0000
+++ b/mysql-test/r/func_math.result	2009-01-28 17:59:08 +0000
@@ -60,7 +60,7 @@ Warnings:
 Note	1003	select ln(exp(10)) AS `ln(exp(10))`,exp((ln(sqrt(10)) * 2)) AS `exp(ln(sqrt(10))*2)`,ln(-(1)) AS `ln(-1)`,ln(0) AS `ln(0)`,ln(NULL) AS `ln(NULL)`
 select log2(8),log2(15),log2(-2),log2(0),log2(NULL);
 log2(8)	log2(15)	log2(-2)	log2(0)	log2(NULL)
-3	3.9068905956085	NULL	NULL	NULL
+3	3.90689059560852	NULL	NULL	NULL
 explain extended select log2(8),log2(15),log2(-2),log2(0),log2(NULL);
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
@@ -68,7 +68,7 @@ Warnings:
 Note	1003	select log2(8) AS `log2(8)`,log2(15) AS `log2(15)`,log2(-(2)) AS `log2(-2)`,log2(0) AS `log2(0)`,log2(NULL) AS `log2(NULL)`
 select log10(100),log10(18),log10(-4),log10(0),log10(NULL);
 log10(100)	log10(18)	log10(-4)	log10(0)	log10(NULL)
-2	1.2552725051033	NULL	NULL	NULL
+2	1.25527250510331	NULL	NULL	NULL
 explain extended select log10(100),log10(18),log10(-4),log10(0),log10(NULL);
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
@@ -85,7 +85,7 @@ Note	1003	select pow(10,log10(10)) AS `p
 set @@rand_seed1=10000000,@@rand_seed2=1000000;
 select rand(999999),rand();
 rand(999999)	rand()
-0.014231365187309	0.028870999839968
+0.0142313651873091	0.028870999839968
 explain extended select rand(999999),rand();
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
@@ -101,7 +101,7 @@ Warnings:
 Note	1003	select pi() AS `pi()`,format(sin((pi() / 2)),6) AS `format(sin(pi()/2),6)`,format(cos((pi() / 2)),6) AS `format(cos(pi()/2),6)`,format(abs(tan(pi())),6) AS `format(abs(tan(pi())),6)`,format((1 / tan(1)),6) AS `format(cot(1),6)`,format(asin(1),6) AS `format(asin(1),6)`,format(acos(0),6) AS `format(acos(0),6)`,format(atan(1),6) AS `format(atan(1),6)`
 select degrees(pi()),radians(360);
 degrees(pi())	radians(360)
-180	6.2831853071796
+180	6.28318530717959
 SELECT ACOS(1.0);
 ACOS(1.0)
 0
@@ -321,7 +321,7 @@ mod(5, cast(-2 as unsigned))	mod(5, 1844
 5	5	1
 select pow(cast(-2 as unsigned), 5), pow(18446744073709551614, 5), pow(-2, 5);
 pow(cast(-2 as unsigned), 5)	pow(18446744073709551614, 5)	pow(-2, 5)
-2.1359870359209e+96	2.1359870359209e+96	-32
+2.13598703592091e+96	2.13598703592091e+96	-32
 CREATE TABLE t1 (a timestamp, b varchar(20), c bit(1));
 INSERT INTO t1 VALUES('1998-09-23', 'str1', 1), ('2003-03-25', 'str2', 0);
 SELECT a DIV 900 y FROM t1 GROUP BY y;

=== modified file 'mysql-test/r/func_str.result'
--- a/mysql-test/r/func_str.result	2008-12-09 10:00:43 +0000
+++ b/mysql-test/r/func_str.result	2009-01-28 17:59:08 +0000
@@ -1131,10 +1131,10 @@ cast(rtrim(ltrim('  20.06 ')) as decimal
 20.06
 select conv("18383815659218730760",10,10) + 0;
 conv("18383815659218730760",10,10) + 0
-1.8383815659219e+19
+1.83838156592187e+19
 select "18383815659218730760" + 0;
 "18383815659218730760" + 0
-1.8383815659219e+19
+1.83838156592187e+19
 CREATE TABLE t1 (code varchar(10));
 INSERT INTO t1 VALUES ('a12'), ('A12'), ('a13');
 SELECT ASCII(code), code FROM t1 WHERE code='A12';

=== modified file 'mysql-test/r/gis.result'
--- a/mysql-test/r/gis.result	2007-11-24 11:05:24 +0000
+++ b/mysql-test/r/gis.result	2009-01-28 17:59:08 +0000
@@ -284,7 +284,7 @@ Note	1003	select astext(startpoint(`test
 SELECT fid, AsText(Centroid(g)) FROM gis_polygon;
 fid	AsText(Centroid(g))
 108	POINT(15 15)
-109	POINT(25.416666666667 25.416666666667)
+109	POINT(25.4166666666667 25.4166666666667)
 110	POINT(20 10)
 SELECT fid, Area(g) FROM gis_polygon;
 fid	Area(g)
@@ -318,8 +318,8 @@ fid	IsClosed(g)
 116	0
 SELECT fid, AsText(Centroid(g)) FROM gis_multi_polygon;
 fid	AsText(Centroid(g))
-117	POINT(55.588527753042 17.426536064114)
-118	POINT(55.588527753042 17.426536064114)
+117	POINT(55.5885277530424 17.426536064114)
+118	POINT(55.5885277530424 17.426536064114)
 119	POINT(2 2)
 SELECT fid, Area(g) FROM gis_multi_polygon;
 fid	Area(g)
@@ -651,11 +651,11 @@ insert into t1 values ('85984',GeomFromT
 select object_id, geometrytype(geo), ISSIMPLE(GEO), ASTEXT(centroid(geo)) from
 t1 where object_id=85998;
 object_id	geometrytype(geo)	ISSIMPLE(GEO)	ASTEXT(centroid(geo))
-85998	MULTIPOLYGON	0	POINT(115.31877315203 -36.237472821022)
+85998	MULTIPOLYGON	0	POINT(115.318773152032 -36.2374728210215)
 select object_id, geometrytype(geo), ISSIMPLE(GEO), ASTEXT(centroid(geo)) from
 t1 where object_id=85984;
 object_id	geometrytype(geo)	ISSIMPLE(GEO)	ASTEXT(centroid(geo))
-85984	MULTIPOLYGON	0	POINT(-114.87787186923 36.33101763469)
+85984	MULTIPOLYGON	0	POINT(-114.877871869233 36.3310176346905)
 drop table t1;
 create table t1 (fl geometry not null);
 insert into t1 values (1);

=== modified file 'mysql-test/r/innodb_gis.result'
--- a/mysql-test/r/innodb_gis.result	2007-10-10 13:26:02 +0000
+++ b/mysql-test/r/innodb_gis.result	2009-01-28 17:59:08 +0000
@@ -291,7 +291,7 @@ Note	1003	select astext(startpoint(`test
 SELECT fid, AsText(Centroid(g)) FROM gis_polygon ORDER by fid;
 fid	AsText(Centroid(g))
 108	POINT(15 15)
-109	POINT(25.416666666667 25.416666666667)
+109	POINT(25.4166666666667 25.4166666666667)
 110	POINT(20 10)
 SELECT fid, Area(g) FROM gis_polygon ORDER by fid;
 fid	Area(g)
@@ -325,8 +325,8 @@ fid	IsClosed(g)
 116	0
 SELECT fid, AsText(Centroid(g)) FROM gis_multi_polygon ORDER by fid;
 fid	AsText(Centroid(g))
-117	POINT(55.588527753042 17.426536064114)
-118	POINT(55.588527753042 17.426536064114)
+117	POINT(55.5885277530424 17.426536064114)
+118	POINT(55.5885277530424 17.426536064114)
 119	POINT(2 2)
 SELECT fid, Area(g) FROM gis_multi_polygon ORDER by fid;
 fid	Area(g)

=== modified file 'mysql-test/r/select.result'
--- a/mysql-test/r/select.result	2008-12-24 15:24:11 +0000
+++ b/mysql-test/r/select.result	2009-01-28 17:59:08 +0000
@@ -2790,26 +2790,26 @@ id	select_type	table	type	possible_keys	
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	Select tables optimized away
 select max(key1) from t1 where key1 <= 0.6158;
 max(key1)
-0.61580002307892
+0.615800023078918
 select max(key2) from t2 where key2 <= 1.6158;
 max(key2)
-1.6158000230789
+1.61580002307892
 select min(key1) from t1 where key1 >= 0.3762;
 min(key1)
-0.37619999051094
+0.376199990510941
 select min(key2) from t2 where key2 >= 1.3762;
 min(key2)
-1.3761999607086
+1.37619996070862
 select max(key1), min(key2) from t1, t2
 where key1 <= 0.6158 and key2 >= 1.3762;
 max(key1)	min(key2)
-0.61580002307892	1.3761999607086
+0.615800023078918	1.37619996070862
 select max(key1) from t1 where key1 <= 0.6158 and rand() + 0.5 >= 0.5;
 max(key1)
-0.61580002307892
+0.615800023078918
 select min(key1) from t1 where key1 >= 0.3762 and rand() + 0.5 >= 0.5;
 min(key1)
-0.37619999051094
+0.376199990510941
 DROP TABLE t1,t2;
 create table t1(a bigint unsigned, b bigint);
 insert into t1 values (0xfffffffffffffffff, 0xfffffffffffffffff), 

=== modified file 'mysql-test/r/sp.result'
--- a/mysql-test/r/sp.result	2008-10-17 14:55:06 +0000
+++ b/mysql-test/r/sp.result	2009-01-28 17:59:08 +0000
@@ -581,7 +581,7 @@ return 2.7182818284590452354|
 set @e = e()|
 select e(), @e|
 e()	@e
-2.718281828459	2.718281828459
+2.71828182845905	2.71828182845905
 drop function if exists inc|
 create function inc(i int) returns int
 return i+1|
@@ -618,7 +618,7 @@ create function fun(d double, i int, u i
 return mul(inc(i), fac(u)) / e()|
 select fun(2.3, 3, 5)|
 fun(2.3, 3, 5)
-176.58213176229
+176.582131762292
 insert into t2 values (append("xxx", "yyy"), mul(4,3), e())|
 insert into t2 values (append("a", "b"), mul(2,mul(3,4)), fun(1.7, 4, 6))|
 select * from t2 where s = append("a", "b")|
@@ -5972,9 +5972,9 @@ CREATE TABLE t3 (f1 INT, f2 FLOAT)|
 INSERT INTO t3 VALUES (1, 3.4), (1, 2), (1, 0.9), (2, 8), (2, 7)|
 SELECT SUM(f2), bug25373(f1) FROM t3 GROUP BY bug25373(f1) WITH ROLLUP|
 SUM(f2)	bug25373(f1)
-6.3000000715256	1
+6.30000007152557	1
 15	2
-21.300000071526	NULL
+21.3000000715256	NULL
 DROP FUNCTION bug25373|
 DROP TABLE t3|
 DROP DATABASE IF EXISTS mysqltest1|

=== modified file 'mysql-test/r/type_float.result'
--- a/mysql-test/r/type_float.result	2008-12-10 13:07:32 +0000
+++ b/mysql-test/r/type_float.result	2009-01-28 17:59:08 +0000
@@ -385,12 +385,12 @@ Warning	1264	Out of range value adjusted
 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
+1.00000001504747e+29
+-1.00000001504747e+29
+1.00000001504747e+30
+-1.00000001504747e+30
+1.00000001504747e+30
+-1.00000001504747e+30
 drop table t1;
 create table t1(d double, u bigint unsigned);
 insert into t1(d) values (9.22337203685479e18),
@@ -401,4 +401,9 @@ u
 9223372036854790144
 18400000000000000000
 drop table t1;
+CREATE TABLE t1 (f1 DOUBLE);
+INSERT INTO t1 VALUES(-1.79769313486231e+308);
+SELECT f1 FROM t1;
+f1
+-1.79769313486231e+308
 End of 5.0 tests

=== modified file 'mysql-test/t/type_float.test'
--- a/mysql-test/t/type_float.test	2008-12-10 13:07:32 +0000
+++ b/mysql-test/t/type_float.test	2009-01-28 17:59:08 +0000
@@ -267,4 +267,12 @@ select u from t1;
 
 drop table t1;
 
+#
+# Bug #21205: Different number of digits for float/doble/real in --ps-protocol
+#
+
+CREATE TABLE t1 (f1 DOUBLE);
+INSERT INTO t1 VALUES(-1.79769313486231e+308);
+SELECT f1 FROM t1;
+
 --echo End of 5.0 tests

=== modified file 'sql/sql_string.cc'
--- a/sql/sql_string.cc	2007-12-19 13:49:04 +0000
+++ b/sql/sql_string.cc	2009-01-28 17:59:08 +0000
@@ -125,7 +125,7 @@ bool String::set(double num,uint decimal
   str_charset=cs;
   if (decimals >= NOT_FIXED_DEC)
   {
-    uint32 len= my_sprintf(buff,(buff, "%.14g",num));// Enough for a DATETIME
+    uint32 len= my_sprintf(buff,(buff, "%.15g",num));// Enough for a DATETIME
     return copy(buff, len, &my_charset_latin1, cs, &dummy_errors);
   }
 #ifdef HAVE_FCONVERT
@@ -677,7 +677,7 @@ void String::qs_append(const char *str, 
 void String::qs_append(double d)
 {
   char *buff = Ptr + str_length;
-  str_length+= my_sprintf(buff, (buff, "%.14g", d));
+  str_length+= my_sprintf(buff, (buff, "%.15g", d));
 }
 
 void String::qs_append(double *d)

Thread
bzr commit into mysql-5.0-bugteam branch (Alexey.Kopytov:2728)Bug#21205Alexey Kopytov28 Jan