views:

108

answers:

1

In manual it said that InnoDB has row-level locking, so why if I select some of the rows with FOR UPDATE statement it won't let me insert new row into that table? New row shouldn't be locked after all, it wasn't selected.

+2  A: 

In InnoDB, an insert on an auto-increment column results in a table lock. Selecting a row FOR UPDATE results in a row level lock.

Since you can't acquire a table lock if there are row locks, the UPDATE prevents the INSERT until its transaction is committed.

Andomar