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

Parsing, name resolution and optimization for window functions.

Details

    Description

      This task will cover the following phases of window functions processing:
      Parsing
      Name resolution and other semantic analysis
      Optimization and building all data structures needed for execution.

      Attachments

        Issue Links

          Activity

            Name resolution doesn't currently work when window functions are used with group by. Here is an example:

            create table t1 (
              username  varchar(32),
              amount int
            );
             
            insert into t1 values
            ('user1',1),
            ('user1',5),
            ('user1',3),
            ('user2',10),
            ('user2',20),
            ('user2',30);
             
            select 
              username,
              sum(amount), 
              rank() over (order by sum(amount) desc)
            from t1
            group by username;
            

            The query is valid, but I get this error:

            ERROR 1111 (HY000): Invalid use of group function
            

            psergei Sergei Petrunia added a comment - Name resolution doesn't currently work when window functions are used with group by. Here is an example: create table t1 ( username varchar(32), amount int );   insert into t1 values ('user1',1), ('user1',5), ('user1',3), ('user2',10), ('user2',20), ('user2',30);   select username, sum(amount), rank() over (order by sum(amount) desc) from t1 group by username; The query is valid, but I get this error: ERROR 1111 (HY000): Invalid use of group function

            The above query does not comply with SQL standard. But it can be rewritten:

            select 
              username,
              sum(amount) as s 
              rank() over (order by s desc)
            from t1
            group by username;
            

            Yet it still returned the same error message.
            I fixed this problem: now aliases for expressions with set functions can be used in window specifications.

            igor Igor Babaev (Inactive) added a comment - The above query does not comply with SQL standard. But it can be rewritten: select username, sum(amount) as s rank() over (order by s desc) from t1 group by username; Yet it still returned the same error message. I fixed this problem: now aliases for expressions with set functions can be used in window specifications.

            The query may be non-standard, but PostgreSQL, SQL Server, and Oracle all support it.

            I agree that we could live with the aliases, for now.

            psergei Sergei Petrunia added a comment - The query may be non-standard, but PostgreSQL, SQL Server, and Oracle all support it. I agree that we could live with the aliases, for now.

            People

              igor Igor Babaev (Inactive)
              igor Igor Babaev (Inactive)
              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.