Feature idea + PoC patch: binlog_row_format_relay_statements

Hi everyone,

In complex multi-master or multi-hop topologies running binlog_format=ROW, fixing data drift across downstream nodes from a single origin is challenging. While executing statements within a transaction like START TRANSACTION; DELETE ...; INSERT ...; COMMIT; on an intermediate node works locally, it converts those statements into ROW events in its own binlog, causing replication issues downstream if data drift differs.

Proposed Solution:
A global dynamic boolean variable binlog_row_format_relay_statements (default OFF) that allows intermediate replicas with binlog_format=ROW to re-log incoming STATEMENT events (Query_log_event) as statements rather than converting them to row-based events, while keeping local writes and incoming ROW events unaffected.

I have created and tested a PoC patch for MySQL 5.7.44 (designed and tested as a DBA, with C++ code drafted via AI assistance) and shared it as a reference for the community/developers to evaluate:

Patch & full description (GitHub Gist):