Some database functions, such as SELECT ... FOR UPDATE and ON DELETE CASCADE , are implicitly vulnerable to deadlocks, as the database does not indicate which lock order to use. I found two discussions that hint that this behavior is not defined by the SQL standard, not to mention specific implementations. Thus, I work under the assumption that we cannot control the lock order (at least it is not obvious how to do this).
How should we avoid database locks if we cannot rely on the locking order?
If we should not avoid deadlocks (you have to fight very hard to convince me of this), then what should we do?
This question is for database agnostic, so please do not ask me which database I am using.
source share