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 |
+--------+