I have a question regarding MySQL locking and transaction management.
My Question is ..does mysql takes lock on the the tuple/table on which I am doing select/update in a transaction ?
Thesql transaction vs lock
MySQLtransaction
MySQLtransaction
I have a question regarding MySQL locking and transaction management.
My Question is ..does mysql takes lock on the the tuple/table on which I am doing select/update in a transaction ?
Best Answer
With MyISAM, you can use the
concurrent_insert=2
optimization, where anINSERT
will not block existing or newSELECT
statements (but will block anything else).With InnoDB, the rules are:
SELECT
s never blockUPDATE
orDELETE
on a row will place a lock on said row. But this can work even while the same row is beingSELECT
ed.INSERT
s are more complicated: if the table has anAUTO_INCREMENT
, then that is locked (though other concurrent operations are allowed if not competing forAUTO_INCREMENT
)INSERT
s may block one another because locking is done over the clustered index.DELETE
s,UPDATE
s on ranges are also more complex and may involve firther blocks due to locks on clustered index.This is probably not a thorough list, but should get you the general picture.