mariadb/mysql-test/r/mysql_binary_zero_insert.result
Brandon Nesterenko 1ce35c327e MDEV-25444: mysql --binary-mode is not able to replay some mysqlbinlog outputs
Note: This patch backports commits 10cd281 and 1755ea4 from 10.3.

10cd281:
Problem:- Some binary data is inserted into the table using
Jconnector. When binlog dump of the data is applied using mysql
client it gives syntax error.

Reason:-
After investigating it turns out to be a issue of mysql client not
able to properly handle  \\0 <0 in binary>. In all binary files
where mysql client fails to insert
these 2 bytes are common (0x5c00)

Solution:-
I have changed mysql.cc to include for the possibility that binary
string can have \\0 in it

1755ea4:
Changes on top of Sachin’s patch. Specifically:
 1) Refined the parsing break condition to only change the parser’s
behavior for parsing strings in binary mode (behavior of \0 outside
of strings is unchanged).
 2) Prefixed binary_zero_insert.test with ‘mysql_’ to more clearly
associate the  purpose of the test.
 3) As the input of the test contains binary zeros (0x5c00),
different text editors can visualize this sequence differently, and
Github would not display it at all. Therefore, the input itself was
consolidated into the test and created out of hex sequences to make
it easier to understand what is happening.
 4) Extended test to validate that the rows which correspond to the
INSERTS with 0x5c00 have the correct binary zero data.

Reviewed By:
============
Andrei Elkin <andrei.elkin@mariadb.com>
2021-10-06 07:50:37 -06:00

54 lines
1.6 KiB
Text

# Note: This test assumes NO_BACKSLASH_ESCAPES is not set in SQL_MODE.
##############################
# Setup
##############################
#
# Saving old state
#
set @old_sql_mode= @@global.SQL_MODE;
set @@global.SQL_MODE= "";
#
# Create table for data entry
#
CREATE TABLE tb (`id` int(11) NOT NULL AUTO_INCREMENT,`cb` longblob DEFAULT NULL, PRIMARY KEY (`id`)) AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
RESET MASTER;
##############################
# Test Case
##############################
#
# \0 (0x5c00 in binary) should be allowed in data strings if
# --binary-mode is enabled.
#
FOUND 10 /\x5c\x00/ in binary_zero_inserts.sql
# MYSQL --binary-mode test < MYSQL_TMP_DIR/binary_zero_inserts.sql
#
# Ensure a row exists from each insert statement with a \0
#
SELECT COUNT(*)=8 from tb;
COUNT(*)=8
1
#
# Ensure that the binary zero was parsed and exists in the row data
# Note: We only look for 00 because the 5c only served as an escape
# in parsing.
#
# MYSQL_DUMP test tb --hex-blob | grep INSERT > MYSQL_TMP_DIR/dump.sql
FOUND 10 /00/ in dump.sql
#
# Ensure data consistency on mysqlbinlog replay
#
FLUSH LOGS;
# MYSQL_BINLOG MYSQLD_DATADIR/binlog_file > MYSQL_TMP_DIR/binlog_zeros.sql
FOUND 10 /\x5c\x00/ in binlog_zeros.sql
# MYSQL --binary-mode test < MYSQL_TMP_DIR/binlog_zeros.sql
# Table checksum is equivalent before and after binlog replay
#
# A \0 should still be treated as end-of-query in binary mode.
#
# MYSQL --binary-mode -B test < MYSQL_TMP_DIR/binary_zero_eoq.sql
##############################
# Cleanup
##############################
SET @@global.sql_mode= @old_sql_mode;
drop table tb;
RESET MASTER;