RE: When using FOR UPDATE whole the table seems to lock instead of selected row

2010-01-18 Thread Gavin Towey
I think Baron was referring to a technique like this: you sell a t-shirt, UPDATE table SET t=t-X WHERE t = X, if you get rows affected, it's sold and ok. if not, the stock ran out before the operation. but it's safe. see http://dev.mysql.com/tech-resources/articles/storage-engine/part_3.html

Re: When using FOR UPDATE whole the table seems to lock instead of selected row

2010-01-15 Thread Perrin Harkins
On Fri, Jan 15, 2010 at 2:54 AM, Johan Machielse johan.machie...@kpnplanet.nl wrote: The problem is that multiple users can read and update the same field simultaneously (worse case) which could lead to unpredictable problems. There are other ways to do handle most cases. For example: UPDATE

When using FOR UPDATE whole the table seems to lock instead of selected row

2010-01-14 Thread Johan Machielse
Hi, I have created a query to read and update a stock item by using the FOR UPDATE statement. According to the MySql documention only the rows that are selected using the FOR UPDATE should be locked for other sessions, but somehow whole the table is locked. This post gives some general

Re: When using FOR UPDATE whole the table seems to lock instead of selected row

2010-01-14 Thread Baron Schwartz
Johan, I don't see a valid need for using FOR UPDATE here. In fact, FOR UPDATE is the cause of many grievances, and I would advise you to avoid it by any means possible. Among other things, it will cause serious performance problems when your server gets busy. And as you can see, it's hard to

Re: When using FOR UPDATE whole the table seems to lock instead of selected row

2010-01-14 Thread Johan Machielse
Hi Baron, Thank you for your answer. The problem is that multiple users can read and update the same field simultaneously (worse case) which could lead to unpredictable problems. According to the MySql online documentation (http://dev.mysql.com/doc/refman/5.0/en/innodb-locking-reads.html)