[MDEV-9543] Parsing, name resolution and optimization for window functions. Created: 2016-02-10  Updated: 2017-01-18  Resolved: 2017-01-18

Status: Closed
Project: MariaDB Server
Component/s: Optimizer, Optimizer - Window functions
Fix Version/s: 10.2.1

Type: Task Priority: Major
Reporter: Igor Babaev Assignee: Igor Babaev
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MDEV-6115 window functions as in the SQL standard Closed

 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.



 Comments   
Comment by Sergei Petrunia [ 2016-03-16 ]

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

Comment by Igor Babaev [ 2016-03-17 ]

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.

Comment by Sergei Petrunia [ 2016-03-17 ]

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.

Generated at Thu Feb 08 07:35:27 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.