insert into table1 ...;
update table2 set count=count+1;
The above inserts something into table1
, and if it succeeds, updates the count
field of table2
.
Of course this kind of thing can be handled by transactions, but transactions need to lock the table, which will be not efficient in a high concurrent system. And it can be even worse if you need to update multiple tables in that transaction.
What's your solution?
I'm using PHP, and I implement transactions this way:
mysql_query('begin');
mysql_query($statement1);
mysql_query($statement2);
...
mysql_query('commit');
So it looks like all tables referred in those $statement
will be locked?