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

Wrong results for window functions over queries with implicit grouping on always empty set.

    XMLWordPrintable

Details

    Description

      Let 's have a table like this one:

      CREATE TABLE t1 (a INT, b VARCHAR(8));
      INSERT INTO t1 VALUES (1,'foo'),(2,'bar');
      

      The following works fine:

       
      MariaDB [test]> select max(a), row_number() over () from t1 where a > 2;
      +--------+----------------------+
      | max(a) | row_number() over () |
      +--------+----------------------+
      |   NULL |                    1 |
      +--------+----------------------+
       
      MariaDB [test]> select max(a), sum(max(a)) over () from t1 where a > 2;
      +--------+---------------------+
      | max(a) | sum(max(a)) over () |
      +--------+---------------------+
      |   NULL | NULL                |
      +--------+---------------------+
       
      MariaDB [test]> select max(a), sum(max(a)) over (partition by max(a)) from t1 where a > 2;
      +--------+----------------------------------------+
      | max(a) | sum(max(a)) over (partition by max(a)) |
      +--------+----------------------------------------+
      |   NULL | NULL                                   |
      +--------+----------------------------------------+
      

      Yet these queries return wrong results:

      MariaDB [test]> select max(a), row_number() over () from t1 where 1 = 2;
      +--------+----------------------+
      | max(a) | row_number() over () |
      +--------+----------------------+
      |   NULL |                    0 |
      +--------+----------------------+
       
      MariaDB [test]> select max(a), sum(max(a)) over () from t1 where 1 = 2;
      +--------+---------------------+
      | max(a) | sum(max(a)) over () |
      +--------+---------------------+
      |   NULL |                     |
      +--------+---------------------+
       
      MariaDB [test]> select max(a), sum(max(a)) over (partition by max(a)) from t1 where 1 = 2;
      +--------+----------------------------------------+
      | max(a) | sum(max(a)) over (partition by max(a)) |
      +--------+----------------------------------------+
      |   NULL |                                        |
      +--------+----------------------------------------+
      

      Attachments

        Activity

          People

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