MySQL Reference Manual for version 4.0.18.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

14.4.9 InnoDB Transaction Model and Locking

In the InnoDB transaction model the goal has been to combine the best properties of a multi-versioning database to traditional two-phase locking. InnoDB does locking on row level and runs queries by default as non-locking consistent reads, in the style of Oracle. The lock table in InnoDB is stored so space-efficiently that lock escalation is not needed: typically several users are allowed to lock every row in the database, or any random subset of the rows, without InnoDB running out of memory.

In InnoDB all user activity happens inside transactions. If the autocommit mode is used in MySQL, then each SQL statement forms a single transaction. MySQL always starts a new connection with the autocommit mode switched on.

If the autocommit mode is switched off with SET AUTOCOMMIT = 0, then we can think that a user always has a transaction open. If he issues the SQL COMMIT or ROLLBACK statement, it ends the current transaction, and a new one starts. Both statements will release all InnoDB locks that were set during the current transaction. A COMMIT means that the changes made in the current transaction are made permanent and become visible to other users. A ROLLBACK statement, on the other hand, cancels all modifications made by the current transaction.

If the connection has AUTOCOMMIT = 1, then the user can still perform a multiple-statement transaction by starting it with START TRANSACTION or BEGIN and ending it with COMMIT or ROLLBACK.

14.4.9.1 InnoDB and SET ... TRANSACTION ISOLATION LEVEL ...  
14.4.9.2 Consistent Non-Locking Read  
14.4.9.3 Locking Reads SELECT ... FOR UPDATE and SELECT ... LOCK IN SHARE MODE  
14.4.9.4 Next-key Locking: Avoiding the Phantom Problem  
14.4.9.5 Locks Set by Different SQL Statements in InnoDB  
14.4.9.6 Deadlock Detection and Rollback  
14.4.9.7 An Example of How the Consistent Read Works in InnoDB  
14.4.9.8 How to Cope With Deadlocks  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by rdg (Feb 25 2004) using texi2html