Bug #104373 Killed/Aborted Optimize Table Logged to Binlog
Submitted: 21 Jul 2021 7:26 Modified: 27 Jul 2021 15:28
Reporter: Steven Azzopardi Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Replication Severity:S3 (Non-critical)
Version:8.0.21 - 8.0.25, 8.0.26, 5.7.35 OS:CentOS (7/8)
Assigned to: CPU Architecture:x86

[21 Jul 2021 7:26] Steven Azzopardi
Description:
When an OPTIMIZE TABLE command fails on a server , the entry is still added to the binlog and will be applied to any slaves that replicate from that server. 

Not sure if it is intended to be this way since this old bug was supposedly fixed in earlier versions of MySQL https://bugs.mysql.com/bug.php?id=5551 to prevent from this being logged.

This does not occur for ALTER TABLE commands so possibly it is only particular to the OPTIMIZE TABLE command.

How to repeat:
Below is a test case to replicate it:

Connection 1:

Perform optimize table on a table large enough that will give enough time to kill the process from a second connection.

Connection 2:

Kill connection 1 via KILL command or disconnect SSH session for a MySQL client running connection 1.

Entries will be found in the binlog for the server in question and also in the slave once it has been replicated.
[27 Jul 2021 15:28] MySQL Verification Team
Hello Steven Azzopardi,

Thank you for the report.

regards,
Umesh