Commit bdc03e05 authored by Alexander Barkov's avatar Alexander Barkov

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.
parent 7e29f2d6
......@@ -2314,5 +2314,22 @@ MIN(a) SUM(a) CAST(SUM(a) AS SIGNED) CAST(AVG(a) AS SIGNED)
9.223372036854776e18 9.223372036854776e18 9223372036854775807 9223372036854775807
DROP TABLE t1;
#
# MDEV-7195 AVG() loses precision in INT context
#
CREATE TABLE t1 (
auto SERIAL,
fld1 bigint unsigned NOT NULL,
companynr tinyint(2) unsigned zerofill DEFAULT '00' NOT NULL,
UNIQUE fld1 (fld1)
);
INSERT INTO t1 VALUES (1,0x7FFFFFFFFFFFFFFF,00);
INSERT INTO t1 VALUES (2,0x7FFFFFFFFFFFFFFE,37);
INSERT INTO t1 VALUES (3,0x7FFFFFFFFFFFFFFC,37);
SELECT companynr, AVG(fld1), AVG(fld1)<<0 AS avg1, CAST(AVG(fld1) AS UNSIGNED)<<0 AS avg2 FROM t1 GROUP BY companynr;
companynr AVG(fld1) avg1 avg2
00 9223372036854775807.0000 9223372036854775807 9223372036854775807
37 9223372036854775805.0000 9223372036854775805 9223372036854775805
DROP TABLE t1;
#
# End of 10.1 tests
#
......@@ -1593,6 +1593,21 @@ INSERT INTO t1 VALUES (0x7FFFFFFFFFFFFFFF);
SELECT MIN(a), SUM(a), CAST(SUM(a) AS SIGNED), CAST(AVG(a) AS SIGNED) FROM t1;
DROP TABLE t1;
--echo #
--echo # MDEV-7195 AVG() loses precision in INT context
--echo #
CREATE TABLE t1 (
auto SERIAL,
fld1 bigint unsigned NOT NULL,
companynr tinyint(2) unsigned zerofill DEFAULT '00' NOT NULL,
UNIQUE fld1 (fld1)
);
INSERT INTO t1 VALUES (1,0x7FFFFFFFFFFFFFFF,00);
INSERT INTO t1 VALUES (2,0x7FFFFFFFFFFFFFFE,37);
INSERT INTO t1 VALUES (3,0x7FFFFFFFFFFFFFFC,37);
SELECT companynr, AVG(fld1), AVG(fld1)<<0 AS avg1, CAST(AVG(fld1) AS UNSIGNED)<<0 AS avg2 FROM t1 GROUP BY companynr;
DROP TABLE t1;
--echo #
--echo # End of 10.1 tests
--echo #
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment