Detect and handle write skew (concept)
SQL
Hard
2 views
Problem Description
Two doctors on call table. Each transaction sees at least one on call and turns itself off, resulting none on call. Use SERIALIZABLE to prevent.
Sample Test Case
Input:
OnCall(doctor_id, on_call)
Output:
Serializable prevents skew
Constraints
Concept example
Official Solution
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE; BEGIN; UPDATE OnCall SET on_call = 0 WHERE doctor_id = 1 AND (SELECT COUNT(*) FROM OnCall WHERE on_call = 1) > 1; COMMIT;
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!