Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RBR replication works incorrectly for 'BINARY' type #3984

Closed
sougou opened this issue May 27, 2018 · 2 comments
Closed

RBR replication works incorrectly for 'BINARY' type #3984

sougou opened this issue May 27, 2018 · 2 comments

Comments

@sougou
Copy link
Contributor

sougou commented May 27, 2018

Overview of the Issue

MySQL pads binary columns with zeroes. Here's an example script that shows the problem:

mysql> create table d(id int, val binary(5), primary key(id));
Query OK, 0 rows affected (0.02 sec)

mysql> insert into d values(1, 'a');
Query OK, 1 row affected (0.01 sec)

mysql> select * from d where val='a';
Empty set (0.00 sec)

mysql> select * from d where val='a\0\0\0\0';
+----+-------+
| id | val   |
+----+-------+
|  1 | a     |
+----+-------+
1 row in set (0.00 sec)

When a row like this goes through our binlog streamer, DMLs get generated as val='a', and that does not match the target row. This fails filtered replication.

Reproduction Steps

Create a table like the above, start running a split clone, and perform a DML that changes any row on that table. The filtered replication will fail to affect the target row.

@sougou
Copy link
Contributor Author

sougou commented May 27, 2018

@alainjobart Let's discuss this when you have the time.

@sougou
Copy link
Contributor Author

sougou commented May 27, 2018

Did some binlog mining:

mysql> create table sbt(id int, val char(5), primary key(id));
Query OK, 0 rows affected (0.03 sec)

mysql> insert into sbt values(1, 'a');
Query OK, 1 row affected (0.02 sec)

mysql> update sbt set val='b' where id = 1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> update sbt set val='cc' where id = 1;
Query OK, 1 row affected (0.02 sec)
Rows matched: 1  Changed: 1  Warnings: 0

Char codes:

'a'=0x61
'b'=0x62
'c'=0x63

For first update ('a'->'b'):

mysql.binlogEvent{0xaa, 0x2f, 0xa, 0x5b, 0x1f, 0x96, 0xe9, 0xf5, 0x40, 0x32, 0x0, 0x0, 0x0, 0x48, 0xf, 0x0, 0x0, 0x0, 0x0, 0x72, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x2, 0x0, 0x2, 0xff, 0xff, 0xfc, 0x1, 0x0, 0x0, 0x0, 0x1, 0x61, 0xfc, 0x1, 0x0, 0x0, 0x0, 0x1, 0x62, 0xe4, 0xbf, 0x63, 0x5a}

For second update ('b'->'cc'):

mysql.binlogEvent{0x5e, 0x33, 0xa, 0x5b, 0x1f, 0x96, 0xe9, 0xf5, 0x40, 0x33, 0x0, 0x0, 0x0, 0x6c, 0x10, 0x0, 0x0, 0x0, 0x0, 0x72, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x2, 0x0, 0x2, 0xff, 0xff, 0xfc, 0x1, 0x0, 0x0, 0x0, 0x1, 0x62, 0xfc, 0x1, 0x0, 0x0, 0x0, 0x2, 0x63, 0x63, 0xd6, 0xf1, 0xdf, 0x54}

MySQL does not supply all bytes of a column. So, we have to add the padding before putting those in the where clause.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant