we’re trying to get some statistics over our large log tables on MySQL. Some select queries are taking too long to complete and causing exceptions as;
Caused by: java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
This is causing our whole application to stop serving with the same error. After some research we decided to change ‘innodb_lock_wait_timeout’ variable of our MySQL server configuration.
But, What are the drawbacks of this configuration change?
As load increases, you’ll need an even longer timeout. The drawbacks will be a risk of ever increasing maximum query times for other client queries. You need to look into this, I would suggest using the linux tool
mytopto find the long running queries then do an EXPLAIN on them to see how the locks are being used. Restructure your data and/or query to lock less.Finally, MariaDB (a fork of MySQL) has a lot of focus on reducing the amount of locks needed for operations, so moving to that may help you also.