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

Wrong result with aggregate function as a window function

    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

              • Assignee:
                psergey Sergei Petrunia
                Reporter:
                elenst Elena Stepanova
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: