[MDEV-11907] Bogus 'Division by 0' warnings upon using COUNT as a window function Created: 2017-01-24  Updated: 2017-03-30  Resolved: 2017-03-30

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

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Igor Babaev
Resolution: Fixed Votes: 0
Labels: 10.2-ga

Issue Links:
Relates
relates to MDEV-7635 update defaults and simplify mysqld c... Closed
relates to MDEV-10873 Analyze setting final result of compo... Open

 Description   

drop table if exists t1;
create table t1 (pk int, c int);
insert into t1 values (1,1),(2,1),(3,1),(4,1),(5,2);
set sql_mode='ERROR_FOR_DIVISION_BY_ZERO';
select pk, c, c/count(*) over (partition by c order by pk
rows between 1 preceding and 2 following) as CNT
from t1;
show warnings;
drop table t1;

MariaDB [test]> select pk, c, c/count(*) over (partition by c order by pk
    -> rows between 1 preceding and 2 following) as CNT
    -> from t1;
+------+------+--------+
| pk   | c    | CNT    |
+------+------+--------+
|    1 |    1 | 0.3333 |
|    2 |    1 | 0.2500 |
|    3 |    1 | 0.3333 |
|    4 |    1 | 0.5000 |
|    5 |    2 | 2.0000 |
+------+------+--------+
5 rows in set, 5 warnings (0.00 sec)

MariaDB [test]> show warnings;
+---------+------+---------------+
| Level   | Code | Message       |
+---------+------+---------------+
| Warning | 1365 | Division by 0 |
| Warning | 1365 | Division by 0 |
| Warning | 1365 | Division by 0 |
| Warning | 1365 | Division by 0 |
| Warning | 1365 | Division by 0 |
+---------+------+---------------+
5 rows in set (0.00 sec)

It becomes unexpectedly important since we are going to enable ERROR_FOR_DIVISION_BY_ZERO in 10.2 by default.



 Comments   
Comment by Vicențiu Ciorbaru [ 2017-03-29 ]

Ok to push.

Comment by Igor Babaev [ 2017-03-30 ]

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

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