stoneatom / stonedb

StoneDB is an Open-Source MySQL HTAP and MySQL-Native DataBase for OLTP, Real-Time Analytics, a counterpart of MySQLHeatWave. (https://stonedb.io)
https://stonedb.io/
GNU General Public License v2.0
868 stars 141 forks source link

bug: decimal data type , return incorrect result #1868

Open davidshiz opened 1 year ago

davidshiz commented 1 year ago

Have you read the Contributing Guidelines on issues?

Please confirm if bug report does NOT exists already ?

Describe the problem

mysql> select * from cs1;
+-------------------+---------------+----------------------+
| d1                | d2            | d3                   |
+-------------------+---------------+----------------------+
|               125 |  1.2500000000 |  0.12500000000000000 |
|              -125 | -1.2500000000 | -0.12500000000000000 |
|  9999999999999998 |  0.0000000000 |  0.99999999999999984 |
|                 0 |  0.0000000000 |  0.00000000000000000 |
| -9999999999999998 | -0.0000000000 | -0.99999999999999984 |
|                 0 | -0.0000000000 | -0.00000000000000000 |
+-------------------+---------------+----------------------+
6 rows in set (0.01 sec)

Expected behavior

mysql> select * from cs1;
+--------------------+---------------------+----------------------+
| d1                 | d2                  | d3                   |
+--------------------+---------------------+----------------------+
|                125 |        1.2500000000 |  0.12500000000000000 |
|               -125 |       -1.2500000000 | -0.12500000000000000 |
|   9999999999999998 |  9999999.9999999998 |  0.99999999999999980 |
|  99999999999999999 |  9999999.9999999999 |  0.99999999999999999 |
|  -9999999999999998 | -9999999.9999999998 | -0.99999999999999980 |
| -99999999999999999 | -9999999.9999999999 | -0.99999999999999999 |
+--------------------+---------------------+----------------------+
6 rows in set (0.00 sec)

How To Reproduce

CREATE TABLE cs1 (d1 DECIMAL(17), d2 DECIMAL(17,10), d3 DECIMAL(17,17)) ;
INSERT INTO cs1 VALUES (125, 1.25, 0.125);
INSERT INTO cs1 VALUES (-125, -1.25, -0.125);
INSERT INTO cs1 values (9999999999999998, 9999999.9999999998, 0.9999999999999998);
INSERT INTO cs1 values (99999999999999999, 9999999.9999999999, 0.99999999999999999);
INSERT INTO cs1 values (-9999999999999998, -9999999.9999999998, -0.9999999999999998);
INSERT INTO cs1 values (-99999999999999999, -9999999.9999999999, -0.99999999999999999);

Environment

[root@stonedb-test bin]# ./mysqld --version
./mysqld  Ver 5.7.36-StoneDB-v1.0.1 for Linux on x86_64 (build-)
build information as follow:
        Repository address: https://github.com/stoneatom/stonedb.git:stonedb-5.7-dev
        Branch name: stonedb-5.7-dev
        Last commit ID: 12fa952
        Last commit time: Date:   Sat Jun 3 10:07:20 2023 +0800
        Build time: Date: Mon Jun  5 08:49:16 UTC 2023

Are you interested in submitting a PR to solve the problem?

RingsC commented 1 year ago

@davidshiz , pls, ref to https://stonedb.io/docs/SQL-reference/data-types, what the range we supported now

On StoneDB, the precision for DECIMAL numbers cannot be higher than 18. For example, if you specify decimal(19) in your code, an error will be reported. DECIMAL(6, 2) indicates that up to 6 places are supported at the left of the decimal and up to 2 at the right, and thus the value range is [-9999.99, 9999.99].

davidshiz commented 1 year ago

@davidshiz , pls, ref to https://stonedb.io/docs/SQL-reference/data-types, what the range we supported now

On StoneDB, the precision for DECIMAL numbers cannot be higher than 18. For example, if you specify decimal(19) in your code, an error will be reported. DECIMAL(6, 2) indicates that up to 6 places are supported at the left of the decimal and up to 2 at the right, and thus the value range is [-9999.99, 9999.99].

This document is wrong, 6 should be changed to 4, as follows indicates that up to 6 places are supported at the left of the decimal