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

Wrong result with aggregate function as a window function

    XMLWordPrintable

Details

    Description

      create table t4 (i int);
      insert into t4 values (1),(2);
      select i, sum(i) over (partition by i) from t4;
      

      Actual result

      +------+------------------------------+
      | i    | sum(i) over (partition by i) |
      +------+------------------------------+
      |    1 |                            3 |
      |    2 |                            2 |
      +------+------------------------------+
      2 rows in set (0.00 sec)
      

      Expected result

      postgres=# select i, sum(i) over (partition by i) from t4;
       i | sum 
      ---+-----
       1 |   1
       2 |   2
      (2 rows)
      

      If I add ORDER BY, the result becomes correct:

      MariaDB [test]> select i, sum(i) over (partition by i order by i) from t4;
      +------+-----------------------------------------+
      | i    | sum(i) over (partition by i order by i) |
      +------+-----------------------------------------+
      |    1 |                                       1 |
      |    2 |                                       2 |
      +------+-----------------------------------------+
      2 rows in set (0.00 sec)
      

      Attachments

        Issue Links

          Activity

            People

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