[MDEV-30491] select rtrim command result is truncated Created: 2023-01-29  Updated: 2023-11-28

Status: Confirmed
Project: MariaDB Server
Component/s: Server
Affects Version/s: 10.5.18
Fix Version/s: 10.4, 10.5, 10.6, 10.11

Type: Bug Priority: Major
Reporter: dongjian Assignee: Alexander Barkov
Resolution: Unresolved Votes: 0
Labels: None
Environment:

centos 7.6


Attachments: PNG File image-2023-01-29-16-55-36-398.png    

 Description   

MariaDB [mydb]> show create table t2;
+-------+----------------------------------------------------------------------------------------+
| Table | Create Table                                                                           |
+-------+----------------------------------------------------------------------------------------+
| t2    | CREATE TABLE `t2` (
  `col` double DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+----------------------------------------------------------------------------------------+
1 row in set (0.000 sec)
 
MariaDB [mydb]> select col from t2;
+-------------------------+
| col                     |
+-------------------------+
| -1.7976931348623157e308 |
+-------------------------+
1 row in set (0.000 sec)
 
MariaDB [mydb]> select rtrim(col) from t2;
+-------------------------+
| rtrim(col)              |
+-------------------------+
| -1.7976931348623157e308 |
+-------------------------+
1 row in set (0.000 sec)
 
MariaDB [mydb]> select col from t2 group by 1;
+-------------------------+
| col                     |
+-------------------------+
| -1.7976931348623157e308 |
+-------------------------+
1 row in set (0.001 sec)
 
MariaDB [mydb]> select rtrim(col) from t2 group by 1;
+------------------------+
| rtrim(col)             |
+------------------------+
| -1.7976931348623157e30 |
+------------------------+
1 row in set (0.001 sec)



 Comments   
Comment by Sergei Golubchik [ 2023-01-30 ]

Caused by using DBL_DIG + 7 as a max string length for a double:

$ grep 'DBL_DIG + 7' -r .sql
sql/sql_type.cc:                                                    DBL_DIG + 7,
sql/sql_const.h:#define MAX_DOUBLE_STR_LENGTH (DBL_DIG + 7)

DBL_DIG supposedly covers all significant digits after the decimal dot, while +7 supposedly comes from the sign character -, 1. and e308.

But DBL_DIG is defined as number of decimal digits that are guaranteed to be preserved in text → double → text roundtrip without change due to rounding or overflow. And "digits after the dot" can include one extra digit, that is not guaranteed to be preserved exactly (like in this bug report 7 becomes 5). And also there can be e-308.

So to be safe the length should be DBL_DIG + 9. But it fails many tests, these failures need to be analyzed. Perhaps this fix is too big for GA versions at all

Comment by dongjian [ 2023-02-02 ]

Thank you for your help.

Generated at Thu Feb 08 10:16:38 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.