[Commits] 0e6c2f5: MDEV-8521 Drastic loss of precision in COLUMN_JSON() on DOUBLEs

OleksandrByelkin sanja at mariadb.com
Thu Dec 10 17:17:20 EET 2015


revision-id: 0e6c2f514ebcdb693c3a714f6bdb06cff376b357 (mariadb-10.0.22-39-g0e6c2f5)
parent(s): 6eb86763619be92f73ba91a126313351b6155d8e
committer: Oleksandr Byelkin
timestamp: 2015-12-10 16:17:20 +0100
message:

MDEV-8521 Drastic loss of precision in COLUMN_JSON() on DOUBLEs

fixed conversion

---
 mysql-test/r/dyncol.result | 18 +++++++++++++++---
 mysql-test/t/dyncol.test   |  7 +++++++
 mysys/ma_dyncol.c          |  4 +++-
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/mysql-test/r/dyncol.result b/mysql-test/r/dyncol.result
index fe66e8a..af7c3b7 100644
--- a/mysql-test/r/dyncol.result
+++ b/mysql-test/r/dyncol.result
@@ -1693,10 +1693,10 @@ ERROR 22007: Illegal value used as argument of dynamic column function
 #
 select column_json(column_create("int", -1212 as int, "uint", 12334 as unsigned int, "decimal", "23.344" as decimal, "double", 1.23444e50 as double, "string", 'gdgd\\dhdjh"dhdhd' as char, "time", "0:45:49.000001" AS time, "datetime", "2011-04-05 0:45:49.000001" AS datetime, "date", "2011-04-05" AS date));
 column_json(column_create("int", -1212 as int, "uint", 12334 as unsigned int, "decimal", "23.344" as decimal, "double", 1.23444e50 as double, "string", 'gdgd\\dhdjh"dhdhd' as char, "time", "0:45:49.000001" AS time, "datetime", "2011-04-05 0:45:49.000001" 
-{"int":-1212,"date":"2011-04-05","time":"00:45:49.000001","uint":12334,"double":1.2e50,"string":"gdgd\\dhdjh\"dhdhd","decimal":23.344,"datetime":"2011-04-05 00:45:49.000001"}
+{"int":-1212,"date":"2011-04-05","time":"00:45:49.000001","uint":12334,"double":1.23444e50,"string":"gdgd\\dhdjh\"dhdhd","decimal":23.344,"datetime":"2011-04-05 00:45:49.000001"}
 select column_json(column_create(1, -1212 as int, 2, 12334 as unsigned int, 3, "23.344" as decimal, 4, 1.23444e50 as double, 5, 'gdgd\\dhdjh"dhdhd' as char, 6, "0:45:49.000001" AS time, 7, "2011-04-05 0:45:49.000001" AS datetime, 8, "2011-04-05" AS date));
 column_json(column_create(1, -1212 as int, 2, 12334 as unsigned int, 3, "23.344" as decimal, 4, 1.23444e50 as double, 5, 'gdgd\\dhdjh"dhdhd' as char, 6, "0:45:49.000001" AS time, 7, "2011-04-05 0:45:49.000001" AS datetime, 8, "2011-04-05" AS date))
-{"1":-1212,"2":12334,"3":23.344,"4":1.2e50,"5":"gdgd\\dhdjh\"dhdhd","6":"00:45:49.000001","7":"2011-04-05 00:45:49.000001","8":"2011-04-05"}
+{"1":-1212,"2":12334,"3":23.344,"4":1.23444e50,"5":"gdgd\\dhdjh\"dhdhd","6":"00:45:49.000001","7":"2011-04-05 00:45:49.000001","8":"2011-04-05"}
 #
 # CHECK test
 #
@@ -1834,7 +1834,19 @@ COLUMN_CREATE(
 'two', 123.456 as DOUBLE
 )
 )
-{"one":123.456,"two":123.46}
+{"one":123.456,"two":123.456}
+#
+# MDEV-8521: Drastic loss of precision in COLUMN_JSON() on DOUBLEs
+#
+select column_get(column_create('float', 1.23456789012345E+100 as double), 'float' as double);
+column_get(column_create('float', 1.23456789012345E+100 as double), 'float' as double)
+1.23456789012345e100
+select column_json(column_create('float', 1.23456789012345E+100 as double));
+column_json(column_create('float', 1.23456789012345E+100 as double))
+{"float":1.23456789012345e100}
+select column_json(column_create('float', 1.23456789012345E+10 as double));
+column_json(column_create('float', 1.23456789012345E+10 as double))
+{"float":12345678901.2345}
 #
 # end of 10.0 tests
 #
diff --git a/mysql-test/t/dyncol.test b/mysql-test/t/dyncol.test
index ceebeb2..0f4058d 100644
--- a/mysql-test/t/dyncol.test
+++ b/mysql-test/t/dyncol.test
@@ -893,6 +893,13 @@ SELECT COLUMN_JSON(
     )
 );
 
+--echo #
+--echo # MDEV-8521: Drastic loss of precision in COLUMN_JSON() on DOUBLEs
+--echo #
+
+select column_get(column_create('float', 1.23456789012345E+100 as double), 'float' as double); 
+select column_json(column_create('float', 1.23456789012345E+100 as double)); 
+select column_json(column_create('float', 1.23456789012345E+10 as double));
 
 --echo #
 --echo # end of 10.0 tests
diff --git a/mysys/ma_dyncol.c b/mysys/ma_dyncol.c
index 7dfaf29..06820a0 100644
--- a/mysys/ma_dyncol.c
+++ b/mysys/ma_dyncol.c
@@ -3837,7 +3837,9 @@ mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val,
         return ER_DYNCOL_RESOURCE;
       break;
     case DYN_COL_DOUBLE:
-      len= my_snprintf(buff, sizeof(buff), "%g", val->x.double_value);
+
+      len= my_gcvt(val->x.double_value, MY_GCVT_ARG_DOUBLE,
+                   sizeof(buff) - 1, buff, NULL);
       if (dynstr_realloc(str, len + (quote ? 2 : 0)))
         return ER_DYNCOL_RESOURCE;
       dynstr_append_mem(str, buff, len);


More information about the commits mailing list