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

Issues with the COALESCE function.

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Critical
    • Resolution: Not a Bug
    • 11.5.2
    • N/A
    • Optimizer
    • None

    Description

      *The exported file for the database is in the attachment.

      --orignal sql
      SELECT ALL LINEITEM.L_SHIPMODE AS REF0, LINEITEM.L_TAX AS REF1 
      FROM LINEITEM 
      WHERE (LINEITEM.L_SHIPINSTRUCT) > 
            100
      GROUP BY LINEITEM.L_SHIPMODE, LINEITEM.L_TAX;
      

      return 0 rows

      --rewritten sql 
      SELECT ALL LINEITEM.L_SHIPMODE AS REF0, LINEITEM.L_TAX AS REF1 
      FROM LINEITEM
      WHERE (LINEITEM.L_SHIPINSTRUCT) > 
            COALESCE(100, LINEITEM.L_DISCOUNT, LINEITEM.L_COMMITDATE)
      GROUP BY LINEITEM.L_SHIPMODE, LINEITEM.L_TAX;

      return 72 row

      These two queries are logically equivalent, though they use different syntax to handle the comparison value.

      In the original query, LINEITEM.L_SHIPINSTRUCT is compared to the constant 100, filtering rows where LINEITEM.L_SHIPINSTRUCT is greater than 100.

      In the rewritten query, the COALESCE(100, LINEITEM.L_DISCOUNT, LINEITEM.L_COMMITDATE) function is used to select the first non-NULL value from 100, LINEITEM.L_DISCOUNT, and LINEITEM.L_COMMITDATE. This value is then compared with LINEITEM.L_SHIPINSTRUCT. And the result of COALESCE is still 100.

      The two SQL queries are logically equivalent, but they return different results, indicating the presence of a bug.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              luopeiqi luopeiqi
              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.