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

Wrong result for a grouping query with DISTINCT

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Major
    • Resolution: Unresolved
    • 5.5, 10.0, 10.1, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9
    • 10.4, 10.5, 10.6
    • Optimizer

    Description

      When working on mdev-8646 I discovered that in in mariadb-10.0/10.1.
      the query

      SELECT DISTINCT (COUNT(*) + 1) AS c FROM t1 GROUP BY a

      always returns only 1 row.
      This can be demonstrated with the following test case:

      create table t1 (a int, b int);
      insert into t1 values (1,3), (2,4), (1,5), (1,3), (2,1), (1,5), (1,7), (3,1), (3,2), (3,1), (2,4);
      SELECT (COUNT(*) + 1) AS c FROM t1 GROUP BY a;
      SELECT DISTINCT (COUNT(*) + 1) AS c FROM t1 GROUP BY a;

      The first query from the test case returns the correct result set:

      MariaDB [test]> SELECT (COUNT(*) + 1) AS c FROM t1 GROUP BY a;
      +---+
      | c |
      +---+
      | 6 |
      | 4 |
      | 4 |
      +---+

      The second query returns only 1 row:

      MariaDB [test]> SELECT DISTINCT (COUNT(*) + 1) AS c FROM t1 GROUP BY a;
      +---+
      | c |
      +---+
      | 6 |
      +---+

      Interesting that the query

       
      SELECT DISTINCT (COUNT(distinct b) + 1) AS c FROM t1 GROUP BY a;

      returns the correct result set:

      MariaDB [test]> SELECT DISTINCT (COUNT(distinct b) + 1) AS c FROM t1 GROUP BY a;
      +---+
      | c |
      +---+
      | 4 |
      | 3 |
      +---+

      I did not check the earlier versions of mariadb.

      Attachments

        Activity

          People

            psergei Sergei Petrunia
            igor Igor Babaev
            Votes:
            0 Vote for this issue
            Watchers:
            3 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.