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

CASE with identical COUNT(*) branches makes a nested empty-input aggregate predicate return NULL instead of TRUE

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.11, 11.4, 11.8, 12.3, 13.1, 11.8.9
    • 10.11, 11.4, 11.8, 12.3, 13.1
    • Optimizer
    • Linux x86_64, MariaDB 11.8.9 binary distribution

    Description

      While testing MariaDB 11.8.9, I came across an interesting result discrepancy involving a user variable (@v) in a nested COUNT(*) query. Two equivalent forms return different results: one returns a row, while the other returns an empty set. The reduced test case is shown below.

      CREATE TABLE t (a INT) ENGINE=InnoDB;
      SET @v = '';
       
      SELECT 1 AS result
      WHERE (
      SELECT COUNT() = (
      (SELECT COUNT() FROM (SELECT 1) d) - 1
      )
      FROM t
      );
       
      SELECT 1 AS result
      WHERE (
      SELECT COUNT() = (
      (
      SELECT CASE
      WHEN (SELECT COUNT() FROM (SELECT @v AS a) s)
      THEN COUNT()
      ELSE COUNT()
      END
      FROM (SELECT 1) d
      ) - 1
      )
      FROM t
      );
      

      Actual result on 11.8.9-MariaDB:

      The first query returns:

      result
      1
      

      The second query returns:

      Empty set
      

      Expected result:

      Both queries should return one row:

      result
      1
      

      Attachments

        Activity

          People

            psergei Sergei Petrunia
            jxgui jinxingui
            Votes:
            0 Vote for this issue
            Watchers:
            2 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.