Bug #106437 need an option to let applier thread ignore virtual columns on replica..
Submitted: 10 Feb 2022 23:42
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Row Based Replication ( RBR ) Severity:S2 (Serious)
Version:8.0.28 OS:Any
Assigned to: CPU Architecture:Any
Tags: booking.com

[10 Feb 2022 23:42] Shane Bester
Description:
Given that different versions of MySQL may evaluate function results differently (due to bugfixes, or other unintended changes),  this means that GENERATED columns on the replica might evaluate differently than on the source.

The testcase leads to replica breaking with:

[ERROR] [MY-010584] [Repl] Slave SQL for channel '': Worker 1 failed executing transaction 'e780dbec-8ac7-11ec-8ce4-902b34d12797:7' at master log fc30-bin.000002, end_log_pos 1974; Could not execute Delete_rows event on table test.t; Can't find record in 't', Error_code: 1032; Can't find record in 't', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's master log fc30-bin.000002, end_log_pos 1974, Error_code: MY-001032

The source binary log contained:

#220211  1:31:04 server id 1  end_log_pos 1974 CRC32 0x8e1d285b 	Delete_rows: table id 112 flags: STMT_END_F
### DELETE FROM `test`.`t`
### WHERE
###   @1=2 /* INT meta=0 nullable=1 is_null=0 */
###   @2='߉\x12�\x1d�' /* MEDIUMBLOB/MEDIUMTEXT meta=3 nullable=1 is_null=0 */
###   @3='�\x1b\x0b��\x11�\t��L�I\x03�' /* STRING(16) meta=65040 nullable=1 is_null=0 */
### DELETE FROM `test`.`t`
### WHERE
###   @1=1 /* INT meta=0 nullable=1 is_null=0 */
###   @2='a' /* MEDIUMBLOB/MEDIUMTEXT meta=3 nullable=1 is_null=0 */
###   @3='v\x0fu5v�[\x00tu��M_�' /* STRING(16) meta=65040 nullable=1 is_null=0 */
# at 1974

It's not necessary to try matching column @3 which is the GENERATED column.

Unfortunately,  due to fix of "Bug 33199145 - CONVERT(.. USING charset) gets wrong max_length"   the CAST function on 8.0.28 now evaluates to NULL (it's invalid utf16),  so the row isn't found.   However,  it's not material to the operation that the GENERATED column matches at all.

How to repeat:
Point in case:
---------------
Setup RBR replication from 8.0.27 -> 8.0.28
On Source do this:

create database if not exists test;
use test;
drop table if exists t;
create table t (
  a int,
  d mediumblob,
  i binary(16) generated always as (unhex(md5(cast(`d` as char(3072) charset utf16)))) VIRTUAL, 
  key (i)
) engine=innodb;

insert into t(a,d) values(1,'a');
show warnings;

insert into t(a,d) values(2,0xDF8912DC1DFE);
show warnings;          -- NO errors/warnings!

select * from t;
show warnings;          -- NO warnings!
delete from t order by rand();

--  check replica status.

Suggested fix:
Please provide an option for replication applier to ignore GENERATED columns when searching for rows.
[11 Feb 2022 0:42] MySQL Verification Team
It's better that all tables have a PRIMARY KEY,  but in some cases third party applications/vendors haven't made that improvement yet.
[9 Mar 2022 12:39] Sven Sandberg
Posted by developer:
 
Correction to the previous comment. The new bug we reported is BUG#33932279.