Bug #99606 Incorrect ROUND(X,D) result
Submitted: 17 May 2020 14:41 Modified: 18 May 2020 7:00
Reporter: ick R Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:8.0.20, 5.6.48, 5.7.30, 8.0.25, 5.7.34 OS:Any
Assigned to: CPU Architecture:Any
Tags: Aggregate Function, mysql-server

[17 May 2020 14:41] ick R
Description:
The ROUND(X,D) operation return unexpected value when b is defined in tables 
For example:there's a table like this(a DECIMAL(4, 3), b INT):
+-------+------+
| a     | b    |
+-------+------+
| 1.000 |    1 |
| 2.000 |    2 |
| 3.000 |    3 |
| 4.000 |    4 |
+-------+------+
when we do :SELECT ROUND(a,b) from t1 ; We still got 3 decimal places in each row ,which is obviously wrong.
In another case :SELECT ROUND(a,b-2) from t1 WHERE a=1 and b=1; 
We can get 0 but with 3 decimal places .According to the define of ROUND(X,D), it seems to have right value but wrong decimal.
Then I try SELECT ROUND(a,-1) from t1 WHERE a=1; get right value 0

How to repeat:
 DROP TABLE IF EXISTS t1;
CREATE TABLE t1( a DECIMAL(4, 3), b INT );
INSERT INTO t1 VALUES (1,1),(2,2),(3,3),(4,4);
SELECT ROUND(a,b) from t1 ;
+------------+
| ROUND(a,b) |
+------------+
|      1.000 |
|      2.000 |
|      3.000 |
|      4.000 |
+------------+
SELECT ROUND(a,b) from t1 where a=4 and b=4 ;
+------------+
| ROUND(a,b) |
+------------+
|      4.000 |
+------------+
SELECT ROUND(a,b-2) from t1 WHERE a=1 and b=1;
+--------------+
| ROUND(a,b-2) |
+--------------+
|        0.000 |
+--------------+
SELECT ROUND(a,-1) from t1 WHERE a=1;
+-------------+
| ROUND(a,-1) |
+-------------+
|           0 |
+-------------+
[18 May 2020 7:00] MySQL Verification Team
Hello ick R,

Thank you for the report and test case.

regards,
Umesh