Bug #117057 Inconsistent Results Between Materialized Table and View with GREATEST
Submitted: 27 Dec 2024 12:35 Modified: 27 Dec 2024 12:59
Reporter: Aaditya Dubey Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:8.4.3, 8.0.40 OS:Any
Assigned to: CPU Architecture:Any

[27 Dec 2024 12:35] Aaditya Dubey
Description:
Query using the GREATEST function and logical conditions (1 > c0) produces inconsistent results when executed on a materialized table versus a view with the same definition.

How to repeat:
1. Set up table t0:

CREATE TABLE t0 (c0 DOUBLE, c1 TIME, c2 DOUBLE, c3 BOOLEAN);
INSERT INTO t0 (c0, c1, c2, c3) VALUES (-8.334868730580727e+29, '00:27:32', 6.509225676008042e+29, -50);

2. Create materialized table t1 and query it:

CREATE TABLE t1 AS (SELECT (GREATEST(c0,c1)) AS c0 , c2 AS c2, c3 AS c3 FROM t0 );
SELECT c2, (c0), c3 FROM t1 WHERE (1 > c0) ORDER BY (c0) DESC, c3 DESC, c2 ASC;
+----------------------+----------+------+
| c2                   | c0       | c3   |
+----------------------+----------+------+
| 6.509225676008042e29 | 00:27:32 |  -50 |
+----------------------+----------+------+
1 row in set, 1 warning (0.00 sec)

3. Create view t1 instead and query it:

CREATE VIEW t1 AS (SELECT (GREATEST(c0,c1)) AS c0 , c2 AS c2, c3 AS c3 FROM t0 );
SELECT c2, (c0), c3 FROM t1 WHERE (1 > c0) ORDER BY (c0) DESC, c3 DESC, c2 ASC;
Empty set (0.01 sec)

Suggested fix:
Both the materialized table and the view should return consistent results based on the query conditions.
[27 Dec 2024 12:59] MySQL Verification Team
Hello Aaditya,

Thank you for the report and feedback.
Verified as described.

regards,
Umesh