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

IF(x, SUM(y), z) returns {0, NULL} and mangles results

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 10.0.21, 10.1.6
    • Fix Version/s: N/A
    • Component/s: OTHER
    • Labels:

      Description

      When executing a query that contains IF(x, SUM(\y), z), the results sometimes get mangled because the operation returns

      {0, NULL}

      for a single column in MariaDB.

      For example:

      MariaDB [db1]> SELECT 'marker1',
          ->   IF(1, SUM(1), 1) AS IF_SUM1,
          ->   'marker2',
          ->   IF(1, SUM(2), 2) AS IF_SUM2,
          ->   'marker3',
          ->   'marker4'
          -> FROM mysql.user t1
          -> WHERE t1.max_questions = 1;
      +---------+---------+---------+---------+---------+---------+
      | marker1 | IF_SUM1 | marker2 | IF_SUM2 | marker3 | marker4 |
      +---------+---------+---------+---------+---------+---------+
      | marker1 |       0 | NULL    | marker2 | 0       | NULL    |
      +---------+---------+---------+---------+---------+---------+
      1 row in set (0.00 sec)
      

      The same query works normally on MySQL 5.5:

      mysql> SELECT 'marker1',
          ->   IF(1, SUM(1), 1) AS IF_SUM1,
          ->   'marker2',
          ->   IF(1, SUM(2), 2) AS IF_SUM2,
          ->   'marker3',
          ->   'marker4'
          -> FROM mysql.user t1
          -> WHERE t1.max_questions = 1;
      +---------+---------+---------+---------+---------+---------+
      | marker1 | IF_SUM1 | marker2 | IF_SUM2 | marker3 | marker4 |
      +---------+---------+---------+---------+---------+---------+
      | marker1 |    NULL | marker2 |    NULL | marker3 | marker4 |
      +---------+---------+---------+---------+---------+---------+
      1 row in set (0.00 sec)
      

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            psergey Sergei Petrunia added a comment -

            Geoff Montee, can you submit the dump of the dataset that you were using? Also, the testcase uses mysql.user. Is it essential that a system table is used or the issue can be repeated with non-system table as well?

            Show
            psergey Sergei Petrunia added a comment - Geoff Montee , can you submit the dump of the dataset that you were using? Also, the testcase uses mysql.user . Is it essential that a system table is used or the issue can be repeated with non-system table as well?
            Hide
            GeoffMontee Geoff Montee added a comment -

            Hi Sergei Petrunia ,

            This can be reproduced with non-system tables as well, but I shouldn't attach the dump to the JIRA, since it is customer data. I'll send you an email with the relevant information.

            Show
            GeoffMontee Geoff Montee added a comment - Hi Sergei Petrunia , This can be reproduced with non-system tables as well, but I shouldn't attach the dump to the JIRA, since it is customer data. I'll send you an email with the relevant information.
            Hide
            elenst Elena Stepanova added a comment -

            Geoff Montee, Sergei Petrunia ,
            I think we already have this one, MDEV-8663, at least it looks the same to me. Does everyone agree?

            Show
            elenst Elena Stepanova added a comment - Geoff Montee , Sergei Petrunia , I think we already have this one, MDEV-8663 , at least it looks the same to me. Does everyone agree?
            Hide
            sanja Oleksandr Byelkin added a comment -

            I've fixed, MDEV-8663, so please send me test suite, or check is that fix fixes this problem please.

            Show
            sanja Oleksandr Byelkin added a comment - I've fixed, MDEV-8663 , so please send me test suite, or check is that fix fixes this problem please.
            Hide
            GeoffMontee Geoff Montee added a comment -

            Hi Oleksandr Byelkin,

            I've emailed you the data that I used to reproduce this issue.

            Show
            GeoffMontee Geoff Montee added a comment - Hi Oleksandr Byelkin , I've emailed you the data that I used to reproduce this issue.
            Hide
            sanja Oleksandr Byelkin added a comment -

            It is a duplicate of MDEV-8663 (I checked, the problem fixed bug the fix of MDEV-8663).

            Show
            sanja Oleksandr Byelkin added a comment - It is a duplicate of MDEV-8663 (I checked, the problem fixed bug the fix of MDEV-8663 ).

              People

              • Assignee:
                sanja Oleksandr Byelkin
                Reporter:
                GeoffMontee Geoff Montee
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: