Details
-
Bug
-
Status: Confirmed (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.11, 11.4, 11.8, 12.3, 13.1
Description
CONVERT(x USING binary) names its result width after the character count of the argument instead of its byte count. The value returned by a direct SELECT is correct, but every path that materializes the declared width (derived table, DISTINCT, CREATE TABLE ... AS SELECT) silently truncates it.
Reproduced on 10.11.19 (debug build):
CREATE TABLE c (v VARCHAR(2) CHARACTER SET utf8mb4); |
INSERT INTO c VALUES (0xF09F9880F09F9880); -- two emoji, 8 bytes |
|
|
SELECT LENGTH(CONVERT(v USING binary)) FROM c; -- 8 (correct) |
SELECT LENGTH(b) FROM |
(SELECT DISTINCT CONVERT(v USING binary) AS b FROM c) d; -- 2 (truncated) |
|
|
SET sql_mode=''; |
CREATE TABLE t AS SELECT CONVERT(v USING binary) AS b FROM c; |
-- information_schema says varbinary(2); the stored value is 2 bytes
|
Expected: the reserved width, and the materialized value, is 8 bytes.