Four necessary conditions for deadlocks

  1. A transaction blocks and requests for other resources are not released
  2. Resources in the hands of a transaction cannot be taken away unless they are released
  3. A resource can only be obtained by one transaction
  4. Multiple transactions request resources from other transactions, forming a mutual wait

To solve

  1. If multiple transactions concurrently read multiple tables, have them manipulate multiple tables in a certain order
  2. If a transaction needs to acquire multiple resources, let it acquire all of them at once
  3. For deadlock-prone services, upgrade the granularity of locks and use table locks