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

sum() and avg() return incorrect result for float when calculation overflows float range

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Major
    • Resolution: Unresolved
    • 5.5(EOL), 10.0(EOL), 10.1(EOL), 10.2(EOL), 10.3(EOL), 10.4(EOL), 10.5, 10.6, 10.7(EOL), 10.8(EOL), 10.9(EOL), 10.10(EOL)
    • 10.5, 10.6
    • None
    • CentOS x86_64

    Description

      I believe MCOL-148 is the same issue and is not restricted to the InfiniDB use case.

      – Create table

      DROP TABLE IF EXISTS `inno_1`;
      CREATE TABLE `inno_1` (
        `uINT` int unsigned DEFAULT NULL,
        `uDECIMAL_65_30` decimal(65,30) unsigned DEFAULT NULL
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
      INSERT INTO `inno_1` VALUES
      (1,34750000000000003551216178095456255.999999999999999999999999999738),
      (1,26750000000000003986614330199113727.999999999999999999999999999706),
      (1,32750000000000003660065716121370623.999999999999999999999999999730),
      (1,77250000000000001238163495044775935.999999999999999999999999999908);
      

      – Compare results of query (incorrect result)

      SELECT uINT,avg(uDECIMAL_65_30) FROM inno_1 GROUP BY uINT;
      -- With (correct result):
      SELECT avg(uDECIMAL_65_30) FROM inno_1;
       
      MariaDB [test]> SELECT uINT,avg(uDECIMAL_65_30) FROM inno_1 GROUP BY uINT;
      +------+--------------------------------------------------------------------+
      | uINT | avg(uDECIMAL_65_30)                                                |
      +------+--------------------------------------------------------------------+
      |    1 | 17875000000000003109014929865179135.999999999999999999999999999771 |
      +------+--------------------------------------------------------------------+
      1 row in set, 1 warning (0.00 sec)
       
      MariaDB [test]> show warnings;
      +---------+------+--------------------------------------------------------------+
      | Level   | Code | Message                                                      |
      +---------+------+--------------------------------------------------------------+
      | Warning | 1916 | Got overflow when converting '' to DECIMAL. Value truncated. |
      +---------+------+--------------------------------------------------------------+
      1 row in set (0.00 sec)
      

      Vs.

      MariaDB [test]> SELECT avg(uDECIMAL_65_30) FROM inno_1;
      +--------------------------------------------------------------------+
      | avg(uDECIMAL_65_30)                                                |
      +--------------------------------------------------------------------+
      | 42875000000000003109014929865179135.999999999999999999999999999771 |
      +--------------------------------------------------------------------+
      1 row in set (0.00 sec)
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              ashwing Ashwin Gopalakrishnan
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

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