Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-20732

max_char_length() returns value that is too small for a string returned by FORMAT() with doubles in scientific notation

Details

    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.

      Attachments

        Issue Links

          Activity

            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)
            

            tntnatbry Gagan Goel (Inactive) added a comment - 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)

            Patch for the fix is in PR 1431

            tntnatbry Gagan Goel (Inactive) added a comment - Patch for the fix is in PR 1431
            robertbindar Robert Bindar added a comment -

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

            robertbindar Robert Bindar added a comment - Merged the PR on github. Thanks for the good work!

            People

              drrtuy Roman
              drrtuy Roman
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.