Does the SQL standard specify the locking order for a multi-table query?
For example, given:
SELECT department.id FROM permissions, terminals, departments WHERE
department.id = ? AND
terminal.id = ? AND
permissions.parent = department.id AND
permissions.child = terminals.id;
- Does the SQL standard guarantee a locking order or is it determined by the (implementation-specific) execution plan?
- Is there a way to guarantee a locking order?
- If there is no way to guarantee locking order, how are we supposed to prevent deadlocks?
UPDATE: Please do not vote to close this issue without explaining your reasoning. As far as I'm concerned, this is a programming question, which makes it very much on-topic for Stackoverflow. If you believe the question needs to be further refined, please explain and I will be more than happy to answer you.
S
locks that are released as soon as the data is read (before the end the statement). Sometimes these locks can be kept until the statement ends however example and other times it doesn't take row levelS
locks at all. And given point 1 points 2 and 3 are unanswerable unless you specify a particular RDBMS. – Valentin