InnoDB automatically detects a deadlock of transactions and rolls back a transaction or transactions to break the deadlock.
InnoDB tries to pick small transactions to roll back, where the size of a transaction is determined by the number of rows inserted, updated, or deleted.
InnoDB is aware of table locks if
innodb_table_locks=1 (the default) and
AUTOCOMMIT=0, and the MySQL layer above it knows about row-level locks. Otherwise,
InnoDB cannot detect deadlocks where a table lock set by a MySQL
LOCK TABLES statement or a lock set by a storage engine other than
InnoDB is involved. You must resolve these situations by setting the value of the
innodb_lock_wait_timeout system variable.
InnoDB performs ...