Bug #120259 CREATE VIEW materialization changes byte-valued UNION results
Submitted: 14 Apr 2:43 Modified: 14 Apr 4:49
Reporter: Peiyuan Liu Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:8.4.8 OS:Any
Assigned to: CPU Architecture:Any

[14 Apr 2:43] Peiyuan Liu
Description:
Materializing one grouped `UNION ALL` branch as a view keeps the final row count unchanged but changes the actual byte-valued rows returned by the query. The grouped left branch should return raw byte `0x40`, but after exposing that branch input through a view it returns ASCII-digit bytes `0x3634` instead. Logically, the original SQL and the view-based rewritten SQL are equivalent, but they produce different results.

How to repeat:
DROP DATABASE IF EXISTS t1;
CREATE DATABASE t1;
USE t1;

CREATE TABLE t2 (
  c9 BLOB,
  c12 BIT(8),
  c14 TINYINT
);

INSERT INTO t2 VALUES (X'AA', b'01000000', 1);

SELECT MAX(c12) AS col_2
FROM t2
GROUP BY c14
UNION ALL
SELECT c9 AS col_2
FROM t2;

CREATE VIEW V_t2_07 AS
SELECT * FROM t2;

SELECT MAX(c12) AS col_2
FROM V_t2_07
GROUP BY c14
UNION ALL
SELECT c9 AS col_2
FROM t2;

Original result:
+-------+
| col_2 |
+-------+
| 0x40  |
| 0xAA  |
+-------+

After create view, result:
+--------+
| col_2  |
+--------+
| 0x3634 |
| 0xAA   |
+--------+
[14 Apr 4:49] Chaithra Marsur Gopala Reddy
Hi Peiyuan Liu,

Thank you for the test case. Verified as described.