[MDEV-15204] LAG function doesn't require ORDER BY in OVER clause Created: 2018-02-04  Updated: 2019-05-05  Resolved: 2019-05-05

Status: Closed
Project: MariaDB Server
Component/s: Optimizer - Window functions
Affects Version/s: 10.2, 10.3
Fix Version/s: 10.2.18, 10.3.10, 10.4.0

Type: Bug Priority: Major
Reporter: Vicențiu Ciorbaru Assignee: Vicențiu Ciorbaru
Resolution: Fixed Votes: 0
Labels: beginner-friendly


 Description   

Our current implementation selects an ordering for rows implicitly. This can lead to results that look like this:

create table t1 (a int);
insert into t1 values (1), (2), (10), (0);
select a, lag(a, 1) over () from t1;
a    lag(a, 1) over ()
1    0
2    1
10    2
0    NULL

The ordering used by lag is (ORDER BY a), but we don't return the rows in this order. Also, this would be quite confusing if multiple window functions are used.

Instead of running this query like this and produce confusing results, we should return an error of the form:

"No order list in window specification for 'LAG'"



 Comments   
Comment by Vicențiu Ciorbaru [ 2018-02-04 ]

Lag should behave like rank() function. Calling rank() over () results in the error:

query 'select a, rank() over () from t1' failed: 4018: No order list in window specification for 'rank'

Generated at Thu Feb 08 08:19:28 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.