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

FLOOR()/CEIL() incorrectly calculate the precision of a DECIMAL(M,D) column.

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.5, 10.1(EOL), 10.2(EOL), 10.3(EOL), 10.4(EOL)
    • 10.4.16, 10.5.7
    • Data types
    • None

    Description

      MariaDB [test]> create table i1 (a decimal(38,10));
      Query OK, 0 rows affected (0.057 sec)
       
      MariaDB [test]> create table i2 as select floor(a), ceil(a) from i1;
      Query OK, 0 rows affected (0.019 sec)
      Records: 0  Duplicates: 0  Warnings: 0
       
      MariaDB [test]> show create table i2;
      +-------+--------------------------------------------------------------------------------------------------------------------------------------------+
      | Table | Create Table                                                                                                                               |
      +-------+--------------------------------------------------------------------------------------------------------------------------------------------+
      | i2    | CREATE TABLE `i2` (
        `floor(a)` decimal(28,0) DEFAULT NULL,
        `ceil(a)` decimal(28,0) DEFAULT NULL
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
      +-------+--------------------------------------------------------------------------------------------------------------------------------------------+
      1 row in set (0.001 sec)
       
      MariaDB [test]> insert into i1 values (9999999999999999999999999999.9999999999), (-9999999999999999999999999999.9999999999);
      Query OK, 2 rows affected (0.002 sec)
      Records: 2  Duplicates: 0  Warnings: 0
       
      MariaDB [test]> create table i3 as select floor(a), ceil(a) from i1;
      ERROR 1264 (22003): Out of range value for column 'ceil(a)' at row 1
      MariaDB [test]> create table i3 as select floor(a) from i1;
      ERROR 1264 (22003): Out of range value for column 'floor(a)' at row 2
      

      For DECIMAL(M,0), i2 should have M=29, instead of M=28 as in the above. This is because M can exceed by 1 for FLOOR/CEIL functions, for example, when we insert the 2 rows into i1, the result of the functions would contain 29 digits, instead of 28.

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              tntnatbry Gagan Goel (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 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.