|
| 1 | +#coding:utf-8 |
| 2 | + |
| 3 | +""" |
| 4 | +ID: n/a |
| 5 | +ISSUE: https://dl.acm.org/doi/pdf/10.1145/3428279 |
| 6 | +TITLE: Wrong result of AVG evaluation as result of SUM / COUNT |
| 7 | +DESCRIPTION: |
| 8 | + Manuel Rigger and Zhendong Su |
| 9 | + Finding Bugs in Database Systems via Query Partitioning |
| 10 | + https://dl.acm.org/doi/pdf/10.1145/3428279 |
| 11 | + page 11 listing 4 |
| 12 | +NOTES: |
| 13 | + [01.06.2025] pzotov |
| 14 | + Bug exists on Firebird 3.0.13.33807 (18.04.2025): |
| 15 | + Statement failed, SQLSTATE = 22003 |
| 16 | + Integer overflow. The result of an integer operation caused the most significant bit of the result to carry. |
| 17 | +""" |
| 18 | + |
| 19 | +import pytest |
| 20 | +from firebird.qa import * |
| 21 | + |
| 22 | +db = db_factory() |
| 23 | + |
| 24 | +test_script = """ |
| 25 | + set list on; |
| 26 | + |
| 27 | + recreate table t0 ( c0 bigint ); |
| 28 | + insert into t0 (c0) values (2) ; |
| 29 | + insert into t0 (c0) values (9223372036854775807) ; |
| 30 | + select avg (t0.c0) as avg_func from t0; |
| 31 | + commit; |
| 32 | +
|
| 33 | + select sum (s)/ sum (c) as avg_eval |
| 34 | + from ( |
| 35 | + select sum ( t0.c0 ) as s , count ( t0.c0 ) as c from t0 where c0 > 0 |
| 36 | + union all |
| 37 | + select sum ( t0.c0 ) as s , count ( t0.c0 ) as c from t0 where not (c0 > 0) |
| 38 | + union all |
| 39 | + select sum ( t0.c0 ) as s , count ( t0.c0 ) as c from t0 where c0 is null |
| 40 | + ); -- { -4611686018427387903} |
| 41 | + commit; |
| 42 | +
|
| 43 | +""" |
| 44 | + |
| 45 | +act = isql_act('db', test_script, substitutions=[('[ \t]+', ' ')]) |
| 46 | + |
| 47 | +@pytest.mark.version('>=4.0') |
| 48 | +def test_1(act: Action): |
| 49 | + act.expected_stdout = """ |
| 50 | + AVG_FUNC 4611686018427387904 |
| 51 | + AVG_EVAL 4611686018427387904 |
| 52 | + """ |
| 53 | + act.execute(combine_output = True) |
| 54 | + assert act.clean_stdout == act.clean_expected_stdout |
0 commit comments