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
862 stars 139 forks source link

bug: decimal type return incorrect result set #1348

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> CREATE TABLE t1 (a DECIMAL(17,0));
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO t1 VALUES (72057594037927935);
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM t1;
+-------------------+
| a                 |
+-------------------+
| 72057594037927936 |
+-------------------+
1 row in set (0.01 sec)

Expected behavior

mysql> SELECT * FROM t1;
+-------------------+
| a                 |
+-------------------+
| 72057594037927935 |
+-------------------+
1 row in set (0.00 sec)

How To Reproduce

CREATE TABLE t1 (a DECIMAL(17,0));
INSERT INTO t1 VALUES (72057594037927935);
SELECT * FROM t1;

Environment

root@ub01:~# /stonedb57/install/bin/mysqld --version
/stonedb57/install/bin/mysqld  Ver 5.7.36-StoneDB-v1.0.2 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: 0f4250589
        Last commit time: Date:   Tue Feb 21 06:09:37 2023 +0000
        Build time: Date: Wed Feb 22 17:50:51 CST 2023
root@ub01:~# cat /etc/issue
Ubuntu 20.04.5 LTS \n \l

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

davidshiz commented 1 year ago

same as #892

hustjieke commented 1 year ago

Related to https://github.com/stoneatom/stonedb/issues/456 , to make the result correct, we need impl decimal128 to expand max precision to 38.

I'll do a further check on this bug, when cast from double to decimal, a round operation may happen.

hustjieke commented 1 year ago

From issue #892:

mysql> CREATE TABLE t1 (a DECIMAL(17,0));
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO t1 VALUES (9999999999999999);
Query OK, 1 row affected (0.00 sec)

mysql> select * from t1;
+-------------------+
| a                 |
+-------------------+
| 10000000000000000 |
+-------------------+
1 row in set (0.00 sec)