Bug #119287 Decimal Precision Mismatch in UNION Query with CONCAT Function
Submitted: 1 Nov 10:08 Modified: 4 Nov 20:58
Reporter: Go Yakult Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:8.0.41 OS:Any
Assigned to: CPU Architecture:Any

[1 Nov 10:08] Go Yakult
Description:
In the following three queries, the first two return results with three decimal places, but the last query only retains one decimal place.

mysql> SELECT ALL concat(t0.c0,'') FROM t0;
+------------------+
| concat(t0.c0,'') |
+------------------+
| 0.072            |
| 0.199            |
+------------------+
2 rows in set (0.00 sec)

mysql> SELECT ALL concat(t0.c0,'') FROM t0 WHERE (NOT ( EXISTS (SELECT 1 from dual wHERE FALSE)));
+------------------+
| concat(t0.c0,'') |
+------------------+
| 0.072            |
| 0.199            |
+------------------+
2 rows in set (0.00 sec)

mysql> SELECT ALL concat(t0.c0,'') FROM t0 WHERE (NOT ( EXISTS (SELECT 1 from dual wHERE FALSE))) UNION ALL SELECT ALL concat(t0.c0,'') FROM t0 WHERE  EXISTS (SELECT 1 from dual wHERE FALSE) UNION ALL  SELECT ALL concat(t0.c0,'') FROM t0 WHERE ( EXISTS (SELECT 1 from dual wHERE FALSE)) IS UNKNOWN;
+------------------+
| concat(t0.c0,'') |
+------------------+
| 0.0              |
| 0.1              |
+------------------+
2 rows in set (0.00 sec)

How to repeat:
DROP TABLE IF EXISTS `t0`;
CREATE TABLE `t0` (
  `c0` float(3,3) unsigned DEFAULT NULL
) ;

INSERT INTO `t0` VALUES (0.072),(0.199);

SELECT ALL concat(t0.c0,'') FROM t0;
SELECT ALL concat(t0.c0,'') FROM t0 WHERE (NOT ( EXISTS (SELECT 1 from dual wHERE FALSE)));
SELECT ALL concat(t0.c0,'') FROM t0 WHERE (NOT ( EXISTS (SELECT 1 from dual wHERE FALSE))) UNION ALL SELECT ALL concat(t0.c0,'') FROM t0 WHERE  EXISTS (SELECT 1 from dual wHERE FALSE) UNION ALL  SELECT ALL concat(t0.c0,'') FROM t0 WHERE ( EXISTS (SELECT 1 from dual wHERE FALSE)) IS UNKNOWN;

Suggested fix:
The execution plan of the last one is different from the previous ones. This might be the reason.
[4 Nov 20:58] Roy Lyseng
Verified as described.

Note that FLOAT with precision and scale argument is deprecated.
It is recommended to use FLOAT without specifications or DECIMAL instead.