[MDEV-19064] Inconsistent behavior while using nested window functions (first_value, last_value, lead,lag) Created: 2019-03-27  Updated: 2020-08-17  Resolved: 2020-08-17

Status: Closed
Project: MariaDB Server
Component/s: Optimizer - Window functions
Affects Version/s: 10.2, 10.3, 10.4
Fix Version/s: 10.2.33, 10.3.24, 10.4.14, 10.5.5

Type: Bug Priority: Major
Reporter: Alice Sherepa Assignee: Varun Gupta (Inactive)
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-15180 server crashed with NTH_VALUE() Closed

 Description   

1))

 
MariaDB [test]> create table t1 (a int, b int);
Query OK, 0 rows affected (0.048 sec)
 
MariaDB [test]> insert into t1 values (1,3), (2,2), (3,1), (1,3), (2,2), (3,1);
Query OK, 6 rows affected (0.017 sec)
Records: 6  Duplicates: 0  Warnings: 0
 
MariaDB [test]> select  first_value(sum(a)) over () from t1;
ERROR 1111 (HY000): Invalid use of group function
 
MariaDB [test]> select  first_value(sum(a) over ()) over () from t1; 
+-------------------------------------+
| first_value(sum(a) over ()) over () |
+-------------------------------------+
|                                  12 |
|                                  12 |
|                                  12 |
|                                  12 |
|                                  12 |
|                                  12 |
+-------------------------------------+
6 rows in set (0.002 sec)
 
MariaDB [test]> select  first_value(sum(a) over (order by null)) over () from t1;
+--------------------------------------------------+
| first_value(sum(a) over (order by null)) over () |
+--------------------------------------------------+
|                                             NULL |
|                                               12 |
|                                               12 |
|                                               12 |
|                                               12 |
|                                               12 |
+--------------------------------------------------+
6 rows in set (0.002 sec)
 
MariaDB [test]> select  first_value(sum(a) over (order by a)) over () from t1;
ERROR 2013 (HY000): Lost connection to MySQL server during query         ###MDEV MDEV-15180


Postgres returns error " window function calls cannot be nested "

2))

create table t1 (a int);
insert into t1 values (1), (2), (3);
 
select  first_value(avg(a)) over () from t1;

MariaDB [test]> select  first_value(avg(a)) over () from t1;
ERROR 1111 (HY000): Invalid use of group function

Mysql 8.0/Postgres 9.6:

mysql> select  first_value(avg(a)) over () from t1;
+-----------------------------+
| first_value(avg(a)) over () |
+-----------------------------+
|                      2.0000 |
+-----------------------------+
1 row in set (0.00 sec)



 Comments   
Comment by Varun Gupta (Inactive) [ 2020-08-17 ]

Fixed by MDEV-22984

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