The MySQL Server has a few options to help deal with transactions holding InnoDB locks for excessive periods of time. The –innodb-lock-wait-timeout option is one such option, but that just affects statements waiting on locks already held by another transaction. If you want to ensure your application isn’t holding locks for long periods of time to start with, what options do you have?
Well, the manual has a useful example that leverages InnoDB tables in INFORMATION_SCHEMA to show which transactions are locking rows needed by other transactions. That’s cool stuff, and you can take this a step further by looking for all connections with open transactions …
[Read more]