diff options
author | Alexander Barkov <bar@mariadb.com> | 2020-08-02 18:58:01 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2020-08-02 18:58:01 +0400 |
commit | 863d5b4f75b488412c237af8bed9632aabce690b (patch) | |
tree | 9660a6ffab193834d99599261e0fd44c22cbcd0c | |
parent | da78e952fb327161311a590eb902c5c55da0f2fc (diff) | |
download | mariadb-git-863d5b4f75b488412c237af8bed9632aabce690b.tar.gz |
MDEV-23350 ROUND(bigint_22_or_longer) returns a wrong data type
The condition in Item_func_round::fix_arg_int() to decide whether:
- we can preserve the data type of args[0] versus
- the result can go outside of the args[0] data type
was wrong.
The data type of the first argument can be preserved in these cases:
- TRUNCATE(x, n)
- ROUND(x, n>=0)
Fixing the condition accordingly.
-rw-r--r-- | mysql-test/main/type_int.result | 323 | ||||
-rw-r--r-- | mysql-test/main/type_int.test | 13 | ||||
-rw-r--r-- | sql/item_func.cc | 3 |
3 files changed, 336 insertions, 3 deletions
diff --git a/mysql-test/main/type_int.result b/mysql-test/main/type_int.result index 609889cd5e8..95c27c0b8d8 100644 --- a/mysql-test/main/type_int.result +++ b/mysql-test/main/type_int.result @@ -413,6 +413,7 @@ COUNT(*) DROP TABLE t1; # # MDEV-23337 Rounding functions create a wrong data type for numeric input +# MDEV-23350 ROUND(bigint_22_or_longer) returns a wrong data type # CREATE PROCEDURE p1(t VARCHAR(64)) BEGIN @@ -420,7 +421,7 @@ SELECT t AS ``; EXECUTE IMMEDIATE REPLACE('CREATE TABLE t1 (a TYPE)', 'TYPE', t); INSERT IGNORE INTO t1 VALUES (-100000000000000000000000000000); INSERT IGNORE INTO t1 VALUES (100000000000000000000000000000); -CREATE TABLE t2 AS SELECT a, ROUND(a), TRUNCATE(a,0), FLOOR(a), CEILING(a) FROM t1; +CREATE TABLE t2 AS SELECT a, ROUND(a), ROUND(a,1), ROUND(a,10), TRUNCATE(a,0), FLOOR(a), CEILING(a) FROM t1; SHOW CREATE TABLE t2; SELECT * FROM t2; DROP TABLE t1, t2; @@ -432,17 +433,23 @@ Table t2 Create Table CREATE TABLE `t2` ( `a` tinyint(4) DEFAULT NULL, `ROUND(a)` tinyint(4) DEFAULT NULL, + `ROUND(a,1)` tinyint(4) DEFAULT NULL, + `ROUND(a,10)` tinyint(4) DEFAULT NULL, `TRUNCATE(a,0)` tinyint(4) DEFAULT NULL, `FLOOR(a)` tinyint(4) DEFAULT NULL, `CEILING(a)` tinyint(4) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 a -128 ROUND(a) -128 +ROUND(a,1) -128 +ROUND(a,10) -128 TRUNCATE(a,0) -128 FLOOR(a) -128 CEILING(a) -128 a 127 ROUND(a) 127 +ROUND(a,1) 127 +ROUND(a,10) 127 TRUNCATE(a,0) 127 FLOOR(a) 127 CEILING(a) 127 @@ -452,17 +459,23 @@ Table t2 Create Table CREATE TABLE `t2` ( `a` smallint(6) DEFAULT NULL, `ROUND(a)` smallint(6) DEFAULT NULL, + `ROUND(a,1)` smallint(6) DEFAULT NULL, + `ROUND(a,10)` smallint(6) DEFAULT NULL, `TRUNCATE(a,0)` smallint(6) DEFAULT NULL, `FLOOR(a)` smallint(6) DEFAULT NULL, `CEILING(a)` smallint(6) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 a -32768 ROUND(a) -32768 +ROUND(a,1) -32768 +ROUND(a,10) -32768 TRUNCATE(a,0) -32768 FLOOR(a) -32768 CEILING(a) -32768 a 32767 ROUND(a) 32767 +ROUND(a,1) 32767 +ROUND(a,10) 32767 TRUNCATE(a,0) 32767 FLOOR(a) 32767 CEILING(a) 32767 @@ -472,17 +485,23 @@ Table t2 Create Table CREATE TABLE `t2` ( `a` mediumint(9) DEFAULT NULL, `ROUND(a)` mediumint(9) DEFAULT NULL, + `ROUND(a,1)` mediumint(9) DEFAULT NULL, + `ROUND(a,10)` mediumint(9) DEFAULT NULL, `TRUNCATE(a,0)` mediumint(9) DEFAULT NULL, `FLOOR(a)` mediumint(9) DEFAULT NULL, `CEILING(a)` mediumint(9) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 a -8388608 ROUND(a) -8388608 +ROUND(a,1) -8388608 +ROUND(a,10) -8388608 TRUNCATE(a,0) -8388608 FLOOR(a) -8388608 CEILING(a) -8388608 a 8388607 ROUND(a) 8388607 +ROUND(a,1) 8388607 +ROUND(a,10) 8388607 TRUNCATE(a,0) 8388607 FLOOR(a) 8388607 CEILING(a) 8388607 @@ -492,17 +511,23 @@ Table t2 Create Table CREATE TABLE `t2` ( `a` int(11) DEFAULT NULL, `ROUND(a)` int(11) DEFAULT NULL, + `ROUND(a,1)` int(11) DEFAULT NULL, + `ROUND(a,10)` int(11) DEFAULT NULL, `TRUNCATE(a,0)` int(11) DEFAULT NULL, `FLOOR(a)` int(11) DEFAULT NULL, `CEILING(a)` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 a -2147483648 ROUND(a) -2147483648 +ROUND(a,1) -2147483648 +ROUND(a,10) -2147483648 TRUNCATE(a,0) -2147483648 FLOOR(a) -2147483648 CEILING(a) -2147483648 a 2147483647 ROUND(a) 2147483647 +ROUND(a,1) 2147483647 +ROUND(a,10) 2147483647 TRUNCATE(a,0) 2147483647 FLOOR(a) 2147483647 CEILING(a) 2147483647 @@ -512,17 +537,153 @@ Table t2 Create Table CREATE TABLE `t2` ( `a` bigint(20) DEFAULT NULL, `ROUND(a)` bigint(20) DEFAULT NULL, + `ROUND(a,1)` bigint(20) DEFAULT NULL, + `ROUND(a,10)` bigint(20) DEFAULT NULL, `TRUNCATE(a,0)` bigint(20) DEFAULT NULL, `FLOOR(a)` bigint(20) DEFAULT NULL, `CEILING(a)` bigint(20) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 a -9223372036854775808 ROUND(a) -9223372036854775808 +ROUND(a,1) -9223372036854775808 +ROUND(a,10) -9223372036854775808 TRUNCATE(a,0) -9223372036854775808 FLOOR(a) -9223372036854775808 CEILING(a) -9223372036854775808 a 9223372036854775807 ROUND(a) 9223372036854775807 +ROUND(a,1) 9223372036854775807 +ROUND(a,10) 9223372036854775807 +TRUNCATE(a,0) 9223372036854775807 +FLOOR(a) 9223372036854775807 +CEILING(a) 9223372036854775807 +CALL p1('bigint(20)'); + bigint(20) +Table t2 +Create Table CREATE TABLE `t2` ( + `a` bigint(20) DEFAULT NULL, + `ROUND(a)` bigint(20) DEFAULT NULL, + `ROUND(a,1)` bigint(20) DEFAULT NULL, + `ROUND(a,10)` bigint(20) DEFAULT NULL, + `TRUNCATE(a,0)` bigint(20) DEFAULT NULL, + `FLOOR(a)` bigint(20) DEFAULT NULL, + `CEILING(a)` bigint(20) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +a -9223372036854775808 +ROUND(a) -9223372036854775808 +ROUND(a,1) -9223372036854775808 +ROUND(a,10) -9223372036854775808 +TRUNCATE(a,0) -9223372036854775808 +FLOOR(a) -9223372036854775808 +CEILING(a) -9223372036854775808 +a 9223372036854775807 +ROUND(a) 9223372036854775807 +ROUND(a,1) 9223372036854775807 +ROUND(a,10) 9223372036854775807 +TRUNCATE(a,0) 9223372036854775807 +FLOOR(a) 9223372036854775807 +CEILING(a) 9223372036854775807 +CALL p1('bigint(21)'); + bigint(21) +Table t2 +Create Table CREATE TABLE `t2` ( + `a` bigint(21) DEFAULT NULL, + `ROUND(a)` bigint(21) DEFAULT NULL, + `ROUND(a,1)` bigint(21) DEFAULT NULL, + `ROUND(a,10)` bigint(21) DEFAULT NULL, + `TRUNCATE(a,0)` bigint(21) DEFAULT NULL, + `FLOOR(a)` bigint(21) DEFAULT NULL, + `CEILING(a)` bigint(21) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +a -9223372036854775808 +ROUND(a) -9223372036854775808 +ROUND(a,1) -9223372036854775808 +ROUND(a,10) -9223372036854775808 +TRUNCATE(a,0) -9223372036854775808 +FLOOR(a) -9223372036854775808 +CEILING(a) -9223372036854775808 +a 9223372036854775807 +ROUND(a) 9223372036854775807 +ROUND(a,1) 9223372036854775807 +ROUND(a,10) 9223372036854775807 +TRUNCATE(a,0) 9223372036854775807 +FLOOR(a) 9223372036854775807 +CEILING(a) 9223372036854775807 +CALL p1('bigint(22)'); + bigint(22) +Table t2 +Create Table CREATE TABLE `t2` ( + `a` bigint(22) DEFAULT NULL, + `ROUND(a)` bigint(22) DEFAULT NULL, + `ROUND(a,1)` bigint(22) DEFAULT NULL, + `ROUND(a,10)` bigint(22) DEFAULT NULL, + `TRUNCATE(a,0)` bigint(22) DEFAULT NULL, + `FLOOR(a)` bigint(22) DEFAULT NULL, + `CEILING(a)` bigint(22) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +a -9223372036854775808 +ROUND(a) -9223372036854775808 +ROUND(a,1) -9223372036854775808 +ROUND(a,10) -9223372036854775808 +TRUNCATE(a,0) -9223372036854775808 +FLOOR(a) -9223372036854775808 +CEILING(a) -9223372036854775808 +a 9223372036854775807 +ROUND(a) 9223372036854775807 +ROUND(a,1) 9223372036854775807 +ROUND(a,10) 9223372036854775807 +TRUNCATE(a,0) 9223372036854775807 +FLOOR(a) 9223372036854775807 +CEILING(a) 9223372036854775807 +CALL p1('bigint(23)'); + bigint(23) +Table t2 +Create Table CREATE TABLE `t2` ( + `a` bigint(23) DEFAULT NULL, + `ROUND(a)` bigint(23) DEFAULT NULL, + `ROUND(a,1)` bigint(23) DEFAULT NULL, + `ROUND(a,10)` bigint(23) DEFAULT NULL, + `TRUNCATE(a,0)` bigint(23) DEFAULT NULL, + `FLOOR(a)` bigint(23) DEFAULT NULL, + `CEILING(a)` bigint(23) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +a -9223372036854775808 +ROUND(a) -9223372036854775808 +ROUND(a,1) -9223372036854775808 +ROUND(a,10) -9223372036854775808 +TRUNCATE(a,0) -9223372036854775808 +FLOOR(a) -9223372036854775808 +CEILING(a) -9223372036854775808 +a 9223372036854775807 +ROUND(a) 9223372036854775807 +ROUND(a,1) 9223372036854775807 +ROUND(a,10) 9223372036854775807 +TRUNCATE(a,0) 9223372036854775807 +FLOOR(a) 9223372036854775807 +CEILING(a) 9223372036854775807 +CALL p1('bigint(30)'); + bigint(30) +Table t2 +Create Table CREATE TABLE `t2` ( + `a` bigint(30) DEFAULT NULL, + `ROUND(a)` bigint(30) DEFAULT NULL, + `ROUND(a,1)` bigint(30) DEFAULT NULL, + `ROUND(a,10)` bigint(30) DEFAULT NULL, + `TRUNCATE(a,0)` bigint(30) DEFAULT NULL, + `FLOOR(a)` bigint(30) DEFAULT NULL, + `CEILING(a)` bigint(30) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +a -9223372036854775808 +ROUND(a) -9223372036854775808 +ROUND(a,1) -9223372036854775808 +ROUND(a,10) -9223372036854775808 +TRUNCATE(a,0) -9223372036854775808 +FLOOR(a) -9223372036854775808 +CEILING(a) -9223372036854775808 +a 9223372036854775807 +ROUND(a) 9223372036854775807 +ROUND(a,1) 9223372036854775807 +ROUND(a,10) 9223372036854775807 TRUNCATE(a,0) 9223372036854775807 FLOOR(a) 9223372036854775807 CEILING(a) 9223372036854775807 @@ -532,17 +693,23 @@ Table t2 Create Table CREATE TABLE `t2` ( `a` tinyint(3) unsigned DEFAULT NULL, `ROUND(a)` tinyint(3) unsigned DEFAULT NULL, + `ROUND(a,1)` tinyint(3) unsigned DEFAULT NULL, + `ROUND(a,10)` tinyint(3) unsigned DEFAULT NULL, `TRUNCATE(a,0)` tinyint(3) unsigned DEFAULT NULL, `FLOOR(a)` tinyint(3) unsigned DEFAULT NULL, `CEILING(a)` tinyint(3) unsigned DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 a 0 ROUND(a) 0 +ROUND(a,1) 0 +ROUND(a,10) 0 TRUNCATE(a,0) 0 FLOOR(a) 0 CEILING(a) 0 a 255 ROUND(a) 255 +ROUND(a,1) 255 +ROUND(a,10) 255 TRUNCATE(a,0) 255 FLOOR(a) 255 CEILING(a) 255 @@ -552,17 +719,23 @@ Table t2 Create Table CREATE TABLE `t2` ( `a` smallint(5) unsigned DEFAULT NULL, `ROUND(a)` smallint(5) unsigned DEFAULT NULL, + `ROUND(a,1)` smallint(5) unsigned DEFAULT NULL, + `ROUND(a,10)` smallint(5) unsigned DEFAULT NULL, `TRUNCATE(a,0)` smallint(5) unsigned DEFAULT NULL, `FLOOR(a)` smallint(5) unsigned DEFAULT NULL, `CEILING(a)` smallint(5) unsigned DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 a 0 ROUND(a) 0 +ROUND(a,1) 0 +ROUND(a,10) 0 TRUNCATE(a,0) 0 FLOOR(a) 0 CEILING(a) 0 a 65535 ROUND(a) 65535 +ROUND(a,1) 65535 +ROUND(a,10) 65535 TRUNCATE(a,0) 65535 FLOOR(a) 65535 CEILING(a) 65535 @@ -572,17 +745,23 @@ Table t2 Create Table CREATE TABLE `t2` ( `a` mediumint(8) unsigned DEFAULT NULL, `ROUND(a)` mediumint(8) unsigned DEFAULT NULL, + `ROUND(a,1)` mediumint(8) unsigned DEFAULT NULL, + `ROUND(a,10)` mediumint(8) unsigned DEFAULT NULL, `TRUNCATE(a,0)` mediumint(8) unsigned DEFAULT NULL, `FLOOR(a)` mediumint(8) unsigned DEFAULT NULL, `CEILING(a)` mediumint(8) unsigned DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 a 0 ROUND(a) 0 +ROUND(a,1) 0 +ROUND(a,10) 0 TRUNCATE(a,0) 0 FLOOR(a) 0 CEILING(a) 0 a 16777215 ROUND(a) 16777215 +ROUND(a,1) 16777215 +ROUND(a,10) 16777215 TRUNCATE(a,0) 16777215 FLOOR(a) 16777215 CEILING(a) 16777215 @@ -592,17 +771,23 @@ Table t2 Create Table CREATE TABLE `t2` ( `a` int(10) unsigned DEFAULT NULL, `ROUND(a)` int(10) unsigned DEFAULT NULL, + `ROUND(a,1)` int(10) unsigned DEFAULT NULL, + `ROUND(a,10)` int(10) unsigned DEFAULT NULL, `TRUNCATE(a,0)` int(10) unsigned DEFAULT NULL, `FLOOR(a)` int(10) unsigned DEFAULT NULL, `CEILING(a)` int(10) unsigned DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 a 0 ROUND(a) 0 +ROUND(a,1) 0 +ROUND(a,10) 0 TRUNCATE(a,0) 0 FLOOR(a) 0 CEILING(a) 0 a 4294967295 ROUND(a) 4294967295 +ROUND(a,1) 4294967295 +ROUND(a,10) 4294967295 TRUNCATE(a,0) 4294967295 FLOOR(a) 4294967295 CEILING(a) 4294967295 @@ -612,17 +797,153 @@ Table t2 Create Table CREATE TABLE `t2` ( `a` bigint(20) unsigned DEFAULT NULL, `ROUND(a)` bigint(20) unsigned DEFAULT NULL, + `ROUND(a,1)` bigint(20) unsigned DEFAULT NULL, + `ROUND(a,10)` bigint(20) unsigned DEFAULT NULL, `TRUNCATE(a,0)` bigint(20) unsigned DEFAULT NULL, `FLOOR(a)` bigint(20) unsigned DEFAULT NULL, `CEILING(a)` bigint(20) unsigned DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 a 0 ROUND(a) 0 +ROUND(a,1) 0 +ROUND(a,10) 0 +TRUNCATE(a,0) 0 +FLOOR(a) 0 +CEILING(a) 0 +a 18446744073709551615 +ROUND(a) 18446744073709551615 +ROUND(a,1) 18446744073709551615 +ROUND(a,10) 18446744073709551615 +TRUNCATE(a,0) 18446744073709551615 +FLOOR(a) 18446744073709551615 +CEILING(a) 18446744073709551615 +CALL p1('bigint(20) unsigned'); + bigint(20) unsigned +Table t2 +Create Table CREATE TABLE `t2` ( + `a` bigint(20) unsigned DEFAULT NULL, + `ROUND(a)` bigint(20) unsigned DEFAULT NULL, + `ROUND(a,1)` bigint(20) unsigned DEFAULT NULL, + `ROUND(a,10)` bigint(20) unsigned DEFAULT NULL, + `TRUNCATE(a,0)` bigint(20) unsigned DEFAULT NULL, + `FLOOR(a)` bigint(20) unsigned DEFAULT NULL, + `CEILING(a)` bigint(20) unsigned DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +a 0 +ROUND(a) 0 +ROUND(a,1) 0 +ROUND(a,10) 0 +TRUNCATE(a,0) 0 +FLOOR(a) 0 +CEILING(a) 0 +a 18446744073709551615 +ROUND(a) 18446744073709551615 +ROUND(a,1) 18446744073709551615 +ROUND(a,10) 18446744073709551615 +TRUNCATE(a,0) 18446744073709551615 +FLOOR(a) 18446744073709551615 +CEILING(a) 18446744073709551615 +CALL p1('bigint(21) unsigned'); + bigint(21) unsigned +Table t2 +Create Table CREATE TABLE `t2` ( + `a` bigint(21) unsigned DEFAULT NULL, + `ROUND(a)` bigint(21) unsigned DEFAULT NULL, + `ROUND(a,1)` bigint(21) unsigned DEFAULT NULL, + `ROUND(a,10)` bigint(21) unsigned DEFAULT NULL, + `TRUNCATE(a,0)` bigint(21) unsigned DEFAULT NULL, + `FLOOR(a)` bigint(21) unsigned DEFAULT NULL, + `CEILING(a)` bigint(21) unsigned DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +a 0 +ROUND(a) 0 +ROUND(a,1) 0 +ROUND(a,10) 0 +TRUNCATE(a,0) 0 +FLOOR(a) 0 +CEILING(a) 0 +a 18446744073709551615 +ROUND(a) 18446744073709551615 +ROUND(a,1) 18446744073709551615 +ROUND(a,10) 18446744073709551615 +TRUNCATE(a,0) 18446744073709551615 +FLOOR(a) 18446744073709551615 +CEILING(a) 18446744073709551615 +CALL p1('bigint(22) unsigned'); + bigint(22) unsigned +Table t2 +Create Table CREATE TABLE `t2` ( + `a` bigint(22) unsigned DEFAULT NULL, + `ROUND(a)` bigint(22) unsigned DEFAULT NULL, + `ROUND(a,1)` bigint(22) unsigned DEFAULT NULL, + `ROUND(a,10)` bigint(22) unsigned DEFAULT NULL, + `TRUNCATE(a,0)` bigint(22) unsigned DEFAULT NULL, + `FLOOR(a)` bigint(22) unsigned DEFAULT NULL, + `CEILING(a)` bigint(22) unsigned DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +a 0 +ROUND(a) 0 +ROUND(a,1) 0 +ROUND(a,10) 0 +TRUNCATE(a,0) 0 +FLOOR(a) 0 +CEILING(a) 0 +a 18446744073709551615 +ROUND(a) 18446744073709551615 +ROUND(a,1) 18446744073709551615 +ROUND(a,10) 18446744073709551615 +TRUNCATE(a,0) 18446744073709551615 +FLOOR(a) 18446744073709551615 +CEILING(a) 18446744073709551615 +CALL p1('bigint(23) unsigned'); + bigint(23) unsigned +Table t2 +Create Table CREATE TABLE `t2` ( + `a` bigint(23) unsigned DEFAULT NULL, + `ROUND(a)` bigint(23) unsigned DEFAULT NULL, + `ROUND(a,1)` bigint(23) unsigned DEFAULT NULL, + `ROUND(a,10)` bigint(23) unsigned DEFAULT NULL, + `TRUNCATE(a,0)` bigint(23) unsigned DEFAULT NULL, + `FLOOR(a)` bigint(23) unsigned DEFAULT NULL, + `CEILING(a)` bigint(23) unsigned DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +a 0 +ROUND(a) 0 +ROUND(a,1) 0 +ROUND(a,10) 0 +TRUNCATE(a,0) 0 +FLOOR(a) 0 +CEILING(a) 0 +a 18446744073709551615 +ROUND(a) 18446744073709551615 +ROUND(a,1) 18446744073709551615 +ROUND(a,10) 18446744073709551615 +TRUNCATE(a,0) 18446744073709551615 +FLOOR(a) 18446744073709551615 +CEILING(a) 18446744073709551615 +CALL p1('bigint(30) unsigned'); + bigint(30) unsigned +Table t2 +Create Table CREATE TABLE `t2` ( + `a` bigint(30) unsigned DEFAULT NULL, + `ROUND(a)` bigint(30) unsigned DEFAULT NULL, + `ROUND(a,1)` bigint(30) unsigned DEFAULT NULL, + `ROUND(a,10)` bigint(30) unsigned DEFAULT NULL, + `TRUNCATE(a,0)` bigint(30) unsigned DEFAULT NULL, + `FLOOR(a)` bigint(30) unsigned DEFAULT NULL, + `CEILING(a)` bigint(30) unsigned DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +a 0 +ROUND(a) 0 +ROUND(a,1) 0 +ROUND(a,10) 0 TRUNCATE(a,0) 0 FLOOR(a) 0 CEILING(a) 0 a 18446744073709551615 ROUND(a) 18446744073709551615 +ROUND(a,1) 18446744073709551615 +ROUND(a,10) 18446744073709551615 TRUNCATE(a,0) 18446744073709551615 FLOOR(a) 18446744073709551615 CEILING(a) 18446744073709551615 diff --git a/mysql-test/main/type_int.test b/mysql-test/main/type_int.test index 4822f22521f..e54726b8720 100644 --- a/mysql-test/main/type_int.test +++ b/mysql-test/main/type_int.test @@ -295,6 +295,7 @@ DROP TABLE t1; --echo # --echo # MDEV-23337 Rounding functions create a wrong data type for numeric input +--echo # MDEV-23350 ROUND(bigint_22_or_longer) returns a wrong data type --echo # DELIMITER $$; @@ -304,7 +305,7 @@ BEGIN EXECUTE IMMEDIATE REPLACE('CREATE TABLE t1 (a TYPE)', 'TYPE', t); INSERT IGNORE INTO t1 VALUES (-100000000000000000000000000000); INSERT IGNORE INTO t1 VALUES (100000000000000000000000000000); - CREATE TABLE t2 AS SELECT a, ROUND(a), TRUNCATE(a,0), FLOOR(a), CEILING(a) FROM t1; + CREATE TABLE t2 AS SELECT a, ROUND(a), ROUND(a,1), ROUND(a,10), TRUNCATE(a,0), FLOOR(a), CEILING(a) FROM t1; SHOW CREATE TABLE t2; SELECT * FROM t2; DROP TABLE t1, t2; @@ -318,12 +319,22 @@ CALL p1('smallint'); CALL p1('mediumint'); CALL p1('int'); CALL p1('bigint'); +CALL p1('bigint(20)'); +CALL p1('bigint(21)'); +CALL p1('bigint(22)'); +CALL p1('bigint(23)'); +CALL p1('bigint(30)'); CALL p1('tinyint unsigned'); CALL p1('smallint unsigned'); CALL p1('mediumint unsigned'); CALL p1('int unsigned'); CALL p1('bigint unsigned'); +CALL p1('bigint(20) unsigned'); +CALL p1('bigint(21) unsigned'); +CALL p1('bigint(22) unsigned'); +CALL p1('bigint(23) unsigned'); +CALL p1('bigint(30) unsigned'); --horizontal_results DROP PROCEDURE p1; diff --git a/sql/item_func.cc b/sql/item_func.cc index 6b19933fd48..dc30bad6fe3 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -2472,7 +2472,8 @@ void Item_func_round::fix_arg_int(const Type_handler *preferred, Longlong_hybrid val1= args[1]->to_longlong_hybrid(); if (args[1]->null_value) fix_length_and_dec_double(NOT_FIXED_DEC); - else if ((!val1.to_uint(DECIMAL_MAX_SCALE) && truncate) || + else if (truncate || + !val1.neg() /* ROUND(x, n>=0) */ || args[0]->decimal_precision() < DECIMAL_LONGLONG_DIGITS) { // Here we can keep INT_RESULT |