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

0 changed to 0.0 caused by DISTINCT and UNION ALL [10.1.37, 10.11.1]

    XMLWordPrintable

Details

    Description

      Description:
      In theory, the result of sql2(DISTINCT) ⊆ the result of sql1:

      (SELECT (c1 DIV 1)*0.1 FROM t) UNION ALL (SELECT '1'); -- sql1
      (SELECT DISTINCT (c1 DIV 1)*0.1 FROM t) UNION ALL (SELECT '1'); -- sql2
      

      However, the value 0 changed to 0.0 after adding DISTINCT, seems like a logical bug:

      mysql> select version();
      +-----------------------------------------+
      | version()                               |
      +-----------------------------------------+
      | 10.11.1-MariaDB-1:10.11.1+maria~ubu2204 |
      +-----------------------------------------+
      1 row in set (0.00 sec)
       
      mysql> (SELECT (c1 DIV 1)*0.1 FROM t) UNION ALL (SELECT '1');
      +----------------+
      | (c1 DIV 1)*0.1 |
      +----------------+
      | 0              |
      | 1              |
      +----------------+
      2 rows in set (0.00 sec)
       
      mysql> (SELECT DISTINCT (c1 DIV 1)*0.1 FROM t) UNION ALL (SELECT '1');
      +----------------+
      | (c1 DIV 1)*0.1 |
      +----------------+
      | 0.0            |
      | 1              |
      +----------------+
      2 rows in set (0.00 sec)
      

      How to repeat:

      drop table if exists t;
      create table t (c1 double);
      insert into t values (0.1);
       
      (SELECT (c1 DIV 1)*0.1 FROM t) UNION ALL (SELECT '1');
      (SELECT DISTINCT (c1 DIV 1)*0.1 FROM t) UNION ALL (SELECT '1');
      

      Hope these can be helpful for your debugging:
      We look for the first version of the bug in all docker images (with format x.x.x) of https://hub.docker.com/_/mariadb/tags
      We found that the bug first occurred in mariadb:10.1.37, it cannot be reproduced in mariadb:10.1.36:

      MariaDB [TEST]> select version();
      +--------------------------+
      | version()                |
      +--------------------------+
      | 10.1.37-MariaDB-1~bionic |
      +--------------------------+
      1 row in set (0.00 sec)
       
      MariaDB [TEST]> (SELECT (c1 DIV 1)*0.1 FROM t) UNION ALL (SELECT '1');
      +----------------+
      | (c1 DIV 1)*0.1 |
      +----------------+
      | 0              |
      | 1              |
      +----------------+
      2 rows in set (0.00 sec)
       
      MariaDB [TEST]> (SELECT DISTINCT (c1 DIV 1)*0.1 FROM t) UNION ALL (SELECT '1');
      +----------------+
      | (c1 DIV 1)*0.1 |
      +----------------+
      | 0.0            |
      | 1              |
      +----------------+
      2 rows in set (0.00 sec)
       
      MariaDB [TEST]> select version();
      +--------------------------+
      | version()                |
      +--------------------------+
      | 10.1.36-MariaDB-1~bionic |
      +--------------------------+
      1 row in set (0.00 sec)
       
      MariaDB [TEST]> (SELECT (c1 DIV 1)*0.1 FROM t) UNION ALL (SELECT '1');
      +----------------+
      | (c1 DIV 1)*0.1 |
      +----------------+
      | 0.0            |
      | 1              |
      +----------------+
      2 rows in set (0.00 sec)
       
      MariaDB [TEST]> (SELECT DISTINCT (c1 DIV 1)*0.1 FROM t) UNION ALL (SELECT '1');
      +----------------+
      | (c1 DIV 1)*0.1 |
      +----------------+
      | 0.0            |
      | 1              |
      +----------------+
      2 rows in set (0.00 sec)
      

      Attachments

        Activity

          People

            sanja Oleksandr Byelkin
            qaqcatz qaqcatz
            Votes:
            0 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.