Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

1 Answer
1

If the server acquires metadata locks for a statement that is
syntactically valid but fails during execution, it does not release
the locks early. Lock release is still deferred to the end of the
transaction because the failed statement is written to the binary log
and the locks protect log consistency.

Both of these links describe DDL (Data Definition Language) against a table as a contributing factor. What is interesting to keep in mind is that doing something like TRUNCATE TABLE is, in reality, DDL. We have to aware of any SQL we run. We may think it is SQL that is part of a transaction when, in fact, it is DDL. TRUNCATE TABLE is an example of DDL we think is DML. This can cause current transactions to commit and may have unpredictable results when it comes to writing binary log events as the first link states:

Before MySQL 5.5.3, when a transaction acquired a metadata lock for a
table used within a statement, it released the lock at the end of the
statement. This approach had the disadvantage that if a DDL statement
occurred for a table that was being used by another session in an
active transaction, statements could be written to the binary log in
the wrong order.