clickhouse-sink-connector icon indicating copy to clipboard operation
clickhouse-sink-connector copied to clipboard

[MySQL] ON CASCADE child operations are not replicated

Open AdamKatzDev opened this issue 1 year ago • 4 comments

Not sure if this is a well known caveat but: https://bugs.mysql.com/bug.php?id=32506 - Foreign key cascades do not appear when binlog_format = 'ROW'

I hoped to use this connector for a project with a lot of ON CASCADE in schema. Probably the fact that ON CASCADE child operations are not replicated for MySQL should be mentioned somewhere in the connector documentation. There could even be some protection added to the connector code itself.

Other sources: https://dev.mysql.com/doc/refman/8.0/en/innodb-and-mysql-replication.html

Replication and CASCADE. Cascading actions for InnoDB tables on the source are executed on the replica only if the tables sharing the foreign key relation use InnoDB on both the source and replica. This is true whether you are using statement-based or row-based replication.

https://code.openark.org/blog/mysql/things-that-dont-work-well-with-mysqls-foreign-key-implementation

No binary log entries for cascaded writes

https://debezium.io/documentation/faq/

Why don’t I see DELETE events in some cases? This may be caused by the usage of CASCADE DELETE statements. In this case the deletion events generated by the database are not part of the binlog and thus cannot be captured by Debezium.

AdamKatzDev avatar Dec 18 '23 18:12 AdamKatzDev

yes this is a known edge case for debezium and MySQL. here is a workaround.

https://stackoverflow.com/questions/57443976/debezium-does-not-capture-cascade-delete

aadant avatar Dec 19 '23 07:12 aadant

@aadant is there a complete solution for this issue? A script for Clickhouse or MySQL that keep the triggers in a synced state? For some removing cascade operations is not an option. I was really surprised when stumbled upon this bug, it wasn't a known issue for me at least.

AdamKatzDev avatar Dec 19 '23 11:12 AdamKatzDev

@AdamKatzDev it would be a custom solution on your end.

aadant avatar Jan 09 '24 21:01 aadant

confirmed here https://code.openark.org/blog/mysql/things-that-dont-work-well-with-mysqls-foreign-key-implementation#more-8226

aadant avatar Jan 12 '24 03:01 aadant