[MDEV-12051] Wrong results for window functions over queries with implicit grouping on always empty set. Created: 2017-02-11  Updated: 2017-02-13  Resolved: 2017-02-13

Status: Closed
Project: MariaDB Server
Component/s: Optimizer - Window functions
Affects Version/s: 10.2.3
Fix Version/s: 10.2.4

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


 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 |                                        |
+--------+----------------------------------------+



 Comments   
Comment by Igor Babaev [ 2017-02-13 ]

The fix for this bug was pushed into the 10.2 tree.

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