Bug #121729 Binary prepared-statement parameters lose their charset in the statement based binary log; the replica diverges or stops
Description:
When a prepared statement is logged with statement-based logging (binlog_format=STATEMENT, or MIXED when the statement is logged as a statement), each parameter is written into the logged statement as a literal by Item_param::query_val_str(). A string parameter goes through append_query_string(), which writes a plain quoted literal and drops the parameter's character set.
A parameter bound to a binary string, from a binary user variable or a BLOB-typed parameter over the protocol, is therefore logged as a plain '...' literal. The replica reads that literal as text in the session's character_set_client, while the source used it as binary, so the replica can evaluate the statement differently:
1. Silent data divergence. On a latin1 connection, a binary parameter 0xC3A9 inserted into a utf8mb4 column stores C3A9 (é) on the source. The replica reads the logged literal as two latin1 characters and stores C383C2A9 (é). Nothing reports an error.
2. The replica stops. A binary parameter holding a vector, inserted into a VECTOR column, is accepted on the source. On the replica, Field_vector::store() rejects the logged literal because it isn't in the binary charset, and the applier stops with ER_DATA_INCOMPATIBLE_WITH_VECTOR ("Value of type 'string, size: 12' cannot be converted to 'vector' type").
How to repeat:
-- On the source
SET SESSION binlog_format = 'STATEMENT';
-- 1. Silent divergence
CREATE TABLE t2 (id INT PRIMARY KEY, c VARCHAR(10) CHARACTER SET utf8mb4);
SET NAMES latin1;
PREPARE s FROM 'INSERT INTO t2 VALUES (1, ?)';
SET @v = 0xC3A9; -- the UTF-8 bytes of 'é'
EXECUTE s USING @v;
DEALLOCATE PREPARE s;
SET NAMES utf8mb4;
SELECT id, HEX(c) FROM t2; -- source: C3A9
-- 2. Replica stops
CREATE TABLE t3 (id INT PRIMARY KEY, v VECTOR(3));
PREPARE s FROM 'INSERT INTO t3 VALUES (1, ?)';
SET @v = 0x0000803F0000004000004040; -- [1,2,3] as float32
EXECUTE s USING @v;
DEALLOCATE PREPARE s;
SELECT id, VECTOR_TO_STRING(v) FROM t3; -- source: [1,2,3]
-- On the replica
SELECT id, HEX(c) FROM t2; -- replica: C383C2A9
-- The applier has stopped on the INSERT into t3:
-- Error 6136: Value of type 'string, size: 12' cannot be converted to 'vector' type.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.042 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.
Description: When a prepared statement is logged with statement-based logging (binlog_format=STATEMENT, or MIXED when the statement is logged as a statement), each parameter is written into the logged statement as a literal by Item_param::query_val_str(). A string parameter goes through append_query_string(), which writes a plain quoted literal and drops the parameter's character set. A parameter bound to a binary string, from a binary user variable or a BLOB-typed parameter over the protocol, is therefore logged as a plain '...' literal. The replica reads that literal as text in the session's character_set_client, while the source used it as binary, so the replica can evaluate the statement differently: 1. Silent data divergence. On a latin1 connection, a binary parameter 0xC3A9 inserted into a utf8mb4 column stores C3A9 (é) on the source. The replica reads the logged literal as two latin1 characters and stores C383C2A9 (é). Nothing reports an error. 2. The replica stops. A binary parameter holding a vector, inserted into a VECTOR column, is accepted on the source. On the replica, Field_vector::store() rejects the logged literal because it isn't in the binary charset, and the applier stops with ER_DATA_INCOMPATIBLE_WITH_VECTOR ("Value of type 'string, size: 12' cannot be converted to 'vector' type"). How to repeat: -- On the source SET SESSION binlog_format = 'STATEMENT'; -- 1. Silent divergence CREATE TABLE t2 (id INT PRIMARY KEY, c VARCHAR(10) CHARACTER SET utf8mb4); SET NAMES latin1; PREPARE s FROM 'INSERT INTO t2 VALUES (1, ?)'; SET @v = 0xC3A9; -- the UTF-8 bytes of 'é' EXECUTE s USING @v; DEALLOCATE PREPARE s; SET NAMES utf8mb4; SELECT id, HEX(c) FROM t2; -- source: C3A9 -- 2. Replica stops CREATE TABLE t3 (id INT PRIMARY KEY, v VECTOR(3)); PREPARE s FROM 'INSERT INTO t3 VALUES (1, ?)'; SET @v = 0x0000803F0000004000004040; -- [1,2,3] as float32 EXECUTE s USING @v; DEALLOCATE PREPARE s; SELECT id, VECTOR_TO_STRING(v) FROM t3; -- source: [1,2,3] -- On the replica SELECT id, HEX(c) FROM t2; -- replica: C383C2A9 -- The applier has stopped on the INSERT into t3: -- Error 6136: Value of type 'string, size: 12' cannot be converted to 'vector' type.