[MDEV-23350] ROUND(bigint_22_or_longer) returns a wrong data type Created: 2020-07-31  Updated: 2020-08-02  Resolved: 2020-08-02

Status: Closed
Project: MariaDB Server
Component/s: Data types
Affects Version/s: 10.1, 10.2, 10.3, 10.4, 10.5
Fix Version/s: 10.4.14, 10.5.5

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-23337 Rounding functions create a wrong dat... Closed
relates to MDEV-23032 FLOOR()/CEIL() incorrectly calculate ... Closed

 Description   

After fixes made in MDEV-23337, ROUND() returns good results for integer input:

CREATE OR REPLACE TABLE t1 (a bigint(21) unsigned);
CREATE OR REPLACE TABLE t2 AS SELECT ROUND(a),TRUNCATE(a,0),FLOOR(a),CEILING(a) FROM t1;
DESC t2;

+---------------+---------------------+------+-----+---------+-------+
| Field         | Type                | Null | Key | Default | Extra |
+---------------+---------------------+------+-----+---------+-------+
| ROUND(a,0)    | bigint(21) unsigned | YES  |     | NULL    |       |
| TRUNCATE(a,0) | bigint(21) unsigned | YES  |     | NULL    |       |
| FLOOR(a)      | bigint(21) unsigned | YES  |     | NULL    |       |
| CEILING(a)    | bigint(21) unsigned | YES  |     | NULL    |       |
+---------------+---------------------+------+-----+---------+-------+

However, if the length get longer than 21, the result is still not nice:

CREATE OR REPLACE TABLE t1 (a bigint(22) unsigned);
CREATE OR REPLACE TABLE t2 AS SELECT ROUND(a),TRUNCATE(a,0),FLOOR(a),CEILING(a) FROM t1;
DESC t2;

+---------------+------------------------+------+-----+---------+-------+
| Field         | Type                   | Null | Key | Default | Extra |
+---------------+------------------------+------+-----+---------+-------+
| ROUND(a,0)    | decimal(22,0) unsigned | YES  |     | NULL    |       |
| TRUNCATE(a,0) | bigint(22) unsigned    | YES  |     | NULL    |       |
| FLOOR(a)      | bigint(22) unsigned    | YES  |     | NULL    |       |
| CEILING(a)    | bigint(22) unsigned    | YES  |     | NULL    |       |
+---------------+------------------------+------+-----+---------+-------+

Notice, decimal(22,0) instead of bigint(22), which is the data type of the argument.

ROUND(bigint,0) cannot go outside of the BIGINT limit. No needs to create the decimal data type.


Generated at Thu Feb 08 09:21:45 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.