[MDEV-10700] 10.2.2 windowing function returns incorrect result Created: 2016-08-29  Updated: 2017-02-15  Resolved: 2017-02-15

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

Type: Bug Priority: Major
Reporter: Kyle Joiner (Inactive) Assignee: Vicențiu Ciorbaru
Resolution: Fixed Votes: 1
Labels: 10.2-rc


 Description   

MariaDB [dw]> select count(distinct s) from (select sum(d) over(partition by a,b,c) as s from t) Z where s > 0;
+-------------------+
| count(distinct s) |
+-------------------+
| 1000 |
+-------------------+
1 row in set (0.28 sec)
 
MariaDB [dw]> select count(distinct s) from (select sum(d) as s from t group by a,b,c) Z where s > 0;
+-------------------+
| count(distinct s) |
+-------------------+
| 2120 |
+-------------------+
1 row in set (0.29 sec)

1000 <> 2120

MariaDB [dw]>
MariaDB [dw]> select count(distinct s) from (select sum(d) over(partition by a,b) as s from t) Z where s > 0;
+-------------------+
| count(distinct s) |
+-------------------+
| 630 |
+-------------------+
1 row in set (0.23 sec)
 
MariaDB [dw]> select count(distinct s) from (select sum(d) as s from t group by a,b) Z where s > 0;
+-------------------+
| count(distinct s) |
+-------------------+
| 976 |
+-------------------+
1 row in set (0.11 sec)

630 <> 976

MariaDB [dw]>
MariaDB [dw]> select count(distinct s) from (select sum(d) over(partition by a) as s from t) Z where s > 0;
+-------------------+
| count(distinct s) |
+-------------------+
| 0 |
+-------------------+
1 row in set (0.15 sec)
 
MariaDB [dw]> select count(distinct s) from (select sum(d) as s from t group by a) Z where s > 0;
+-------------------+
| count(distinct s) |
+-------------------+
| 1 |
+-------------------+
1 row in set (0.08 sec)

0 <> 1

Test case :

drop table if exists t;
create table t(a int,b int, c int , d int);
insert into t(a,b,c,d) values(1, rand()*1000, rand()*1000, rand()*1000);
insert into t(a,b,c,d) values(1, rand()*1000, rand()*1000, rand()*1000);
replace into t(a,b,c,d) select 1, rand()*1000, rand()*1000, rand()*1000 from t t1, t t2, t t3, t t4, t t5, t t6, t t7, t t8, t t9, t t10, t t11, t t12, t t13, t t14, t t15, t t16, t t17;
 
select count(distinct s) from (select sum(d) over(partition by a,b,c) as s from t) Z where s > 0;
select count(distinct s) from (select sum(d) as s from t group by a,b,c) Z where s > 0;
 
select count(distinct s) from (select sum(d) over(partition by a,b) as s from t) Z where s > 0;
select count(distinct s) from (select sum(d) as s from t group by a,b) Z where s > 0;
 
select count(distinct s) from (select sum(d) over(partition by a) as s from t) Z where s > 0;
select count(distinct s) from (select sum(d) as s from t group by a) Z where s > 0;



 Comments   
Comment by Vicențiu Ciorbaru [ 2016-09-16 ]

This is due to our current limitation regarding SORT_BUFFER_SIZE.

As a temporary fix, setting SORT_BUFFER_SIZE to a large enough value such that all values fit in memory will generate the correct results.

set SORT_BUFFER_SIZE=1024*1024*1024

Ought to fix it.

Comment by Vicențiu Ciorbaru [ 2017-02-07 ]

This needs rechecking at it should be fixed now.

Comment by Vicențiu Ciorbaru [ 2017-02-14 ]

This is also fixed by MDEV-10092

Comment by Vicențiu Ciorbaru [ 2017-02-15 ]

Test case added for bug to prevent regressions.
https://github.com/mariadb/server/commit/eb54d86b584833fe3586467a65794c3e46f3ddb6

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