I'm wondering about data consistency when relying on FOR UPDATE OF <table>
in a JOIN. I'll try to make a simple example:
Transaction 1 does:
BEGIN;
SELECT 1 FROM a WHERE a.id = 5 FOR UPDATE;
UPDATE b SET val = 'other' WHERE b.a_id = 5;
COMMIT;
Transaction 2 does this very closely after:
BEGIN;
SELECT b.val FROM a, b WHERE a.id = 5 AND b.a_id = 5 FOR UPDATE OF a;
[...]
Is there a chance that transaction 2 acquires the lock, but still gets an outdated b.val
? The lock is on the row from a
-- does it wait on that lock before retrieving the row from b
?