| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Re: How to update multiple rows atomically
Marshall wrote:
> Marshall wrote: >
> > Here's what I came up with later: > > UPDATE T t1, T t2 set t1.owner = 1, t2.owner = 1 where > t1.owner = 0 and t2.owner = 0 and t1.id = 2 and t2.id = 3; > > It seems an interesting update to me, in that it depends on > a multi-row condition. This makes it possible to do atomically > something that requires a carefully thought out synchronization > dance otherwise. > > 1) lock the first row with test-and-set > 2) if we didn't do the update, fail > 3) lock the second row with test-and-set > 4) if we didn't do the update, fail > > with it not being obvious what the correct order to lock the > resources is. (Lots of programmers fail to understand > that in locking multiple resources, it is necessary always > to lock them in a canonical order to avoid deadlock.)
What makes you think the above update statement will avoid deadlock? Or starvation? Or any other concurrency problem? Received on Sat Jul 29 2006 - 08:55:29 CDT
![]() |
![]() |