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

CREATE VIEW extraction changes row multiplicity for DISTINCT over grouped aggregate results

    XMLWordPrintable

Details

    Description

      Under semantic-equivalent rewriting, extracting a grouped aggregate into a view causes a stable row-count mismatch on MariaDB.
      The source and mutated queries are logically equivalent, but produce different results.

      CREATE TABLE t1 (c4 INT NULL);
      INSERT INTO t1 (c4) VALUES (1);
      INSERT INTO t1 (c4) VALUES (2);
       
      -- Source Original SQL
      SELECT DISTINCT VARIANCE(fqd39.c4) AS col_2 FROM t1 AS fqd39 GROUP BY fqd39.c4;
       
      -- View SQL
      CREATE VIEW v AS SELECT VARIANCE(fqd39.c4) AS col_2 FROM t1 AS fqd39 GROUP BY fqd39.c4;
       
      -- Mutated SQL
      SELECT DISTINCT v.col_2 AS col_2 FROM v;
      

      Observed result - Query A (original):

      col_2
      0.0
      0.0

      Observed result - Query B (mutated):

      col_2
      0.0

      Attachments

        Issue Links

          Activity

            People

              psergei Sergei Petrunia
              pyuan Peiyuan Liu
              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.