O'Reilly logo
  • Bart Bialek thinks this is interesting:

If you can get both queries to scan the same index in the same direction, you can often reduce the number of deadlocks, because queries can’t create a cycle when they request locks in the same order. This is sometimes easy to do. For example, if you need to update a number of records within a transaction, sort them by their primary key in the application’s memory, then update them in that order—then they can’t deadlock. At other times, however, it can be infeasible (such as when you have two processes that need to work on the same table but are using different indexes).

From

Cover of High Performance MySQL, 3rd Edition

Note

Preventing dead locks