[MDEV-20732] max_char_length() returns value that is too small for a string returned by FORMAT() with doubles in scientific notation Created: 2019-10-03  Updated: 2020-01-16  Resolved: 2020-01-16

Status: Closed
Project: MariaDB Server
Component/s: Data types
Affects Version/s: 10.4
Fix Version/s: 10.4.12, 10.5.1

Type: Bug Priority: Minor
Reporter: Roman Assignee: Roman
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
PartOf
is part of MCOL-2178 Run CS with vanilla 10.4 Closed

 Description   

Consider the example:

MariaDB [test]> CREATE OR REPLACE TABLE t1 AS SELECT FORMAT(1e300,2);
ERROR 1406 (22001): Data too long for column 'FORMAT(1e300,2)' at row 1

There is an assumption that doubles represented as strings couldn't take more then 22 chars. This is incorrect if a big double is sent into FORMAT() function. However the expression args[0]->max_char_length() that is called inside Item_func_format::fix_length_and_dec() returns 22 and this causes the error.

This is also relevant for ColumnStore.



 Comments   
Comment by Gagan Goel (Inactive) [ 2019-12-30 ]

Re-opening this since Format() function on a float data type does not estimate the result length correctly.

Here is an example:

MariaDB [test]> create table i1 (a double, b float);
Query OK, 0 rows affected (0.044 sec)
 
MariaDB [test]> create table i2 as select format(a, 0), format(b, 0) from i1;
Query OK, 0 rows affected (0.044 sec)
Records: 0  Duplicates: 0  Warnings: 0
 
MariaDB [test]> show create table i2;
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                          |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| i2    | CREATE TABLE `i2` (
  `format(a, 0)` varchar(413) CHARACTER SET utf8 DEFAULT NULL,
  `format(b, 0)` varchar(1) CHARACTER SET utf8 DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.000 sec)

Comment by Gagan Goel (Inactive) [ 2019-12-30 ]

Patch for the fix is in PR 1431

Comment by Robert Bindar [ 2020-01-16 ]

Merged the PR on github. Thanks for the good work!

Generated at Thu Feb 08 09:01:44 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.