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

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

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Duplicate
    • 10.0.21, 10.1.6
    • N/A
    • OTHER
    • None

    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)

      Attachments

        Activity

          People

            sanja Oleksandr Byelkin
            GeoffMontee Geoff Montee (Inactive)
            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.