Skip to content

Commit bdc03e0

Browse files
author
Alexander Barkov
committed
MDEV-7195 AVG() loses precision in INT context
The fix for MDEV-8918 previously fixed the problem reported in MDEV-7195. Adding a test case from MDEV-7195 only.
1 parent 7e29f2d commit bdc03e0

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

mysql-test/r/func_group.result

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,5 +2314,22 @@ MIN(a) SUM(a) CAST(SUM(a) AS SIGNED) CAST(AVG(a) AS SIGNED)
23142314
9.223372036854776e18 9.223372036854776e18 9223372036854775807 9223372036854775807
23152315
DROP TABLE t1;
23162316
#
2317+
# MDEV-7195 AVG() loses precision in INT context
2318+
#
2319+
CREATE TABLE t1 (
2320+
auto SERIAL,
2321+
fld1 bigint unsigned NOT NULL,
2322+
companynr tinyint(2) unsigned zerofill DEFAULT '00' NOT NULL,
2323+
UNIQUE fld1 (fld1)
2324+
);
2325+
INSERT INTO t1 VALUES (1,0x7FFFFFFFFFFFFFFF,00);
2326+
INSERT INTO t1 VALUES (2,0x7FFFFFFFFFFFFFFE,37);
2327+
INSERT INTO t1 VALUES (3,0x7FFFFFFFFFFFFFFC,37);
2328+
SELECT companynr, AVG(fld1), AVG(fld1)<<0 AS avg1, CAST(AVG(fld1) AS UNSIGNED)<<0 AS avg2 FROM t1 GROUP BY companynr;
2329+
companynr AVG(fld1) avg1 avg2
2330+
00 9223372036854775807.0000 9223372036854775807 9223372036854775807
2331+
37 9223372036854775805.0000 9223372036854775805 9223372036854775805
2332+
DROP TABLE t1;
2333+
#
23172334
# End of 10.1 tests
23182335
#

mysql-test/t/func_group.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,21 @@ INSERT INTO t1 VALUES (0x7FFFFFFFFFFFFFFF);
15931593
SELECT MIN(a), SUM(a), CAST(SUM(a) AS SIGNED), CAST(AVG(a) AS SIGNED) FROM t1;
15941594
DROP TABLE t1;
15951595

1596+
--echo #
1597+
--echo # MDEV-7195 AVG() loses precision in INT context
1598+
--echo #
1599+
CREATE TABLE t1 (
1600+
auto SERIAL,
1601+
fld1 bigint unsigned NOT NULL,
1602+
companynr tinyint(2) unsigned zerofill DEFAULT '00' NOT NULL,
1603+
UNIQUE fld1 (fld1)
1604+
);
1605+
INSERT INTO t1 VALUES (1,0x7FFFFFFFFFFFFFFF,00);
1606+
INSERT INTO t1 VALUES (2,0x7FFFFFFFFFFFFFFE,37);
1607+
INSERT INTO t1 VALUES (3,0x7FFFFFFFFFFFFFFC,37);
1608+
SELECT companynr, AVG(fld1), AVG(fld1)<<0 AS avg1, CAST(AVG(fld1) AS UNSIGNED)<<0 AS avg2 FROM t1 GROUP BY companynr;
1609+
DROP TABLE t1;
1610+
15961611
--echo #
15971612
--echo # End of 10.1 tests
15981613
--echo #

0 commit comments

Comments
 (0)