We have a table in MySQL using InnoDB, and we are using a transaction isolation level of read uncommitted. Why does setting @x as shown acquire a lock?
mysql> set @x = (select userID from users limit 1);
Query OK, 0 rows affected (0.02 sec)
mysql>
Trying to update this table from another prompt results in a timeout error:
mysql> update users set userID = 1;
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
Your first statement executes a SELECT on the table, therefore the transaction acquires a read lock on one row.The second transaction tries to acquire a write lock on the same table (on all rows, since there is no
WHEREclause), but cannot.You need to issue a
COMMIT(orROLLBACK) command after theSET @x = (...), so that it releases the read lock.The above is wrong. I keep this post just because the below comments might be of interest.