none’ ◦ The very reason for rollbacks • Consistency ◦ Transactions should bring the DB to one VALID state to another ◦ VALID : adheres to all defined rules such as constraints, triggers and cascade • Isolation ◦ Concurrent transactions happen as if they are executed serially. ◦ Each transactions happen as if they are ‘isolated’ from other transactions • Durability ◦ Once a transaction commits, results are stored permanently (Gets stored in disk)
-> session keeps the transaction open, until an explicit COMMIT or ROLLBACK ◦ SET autocommit = 1 -> COMMIT for each SQL statement that update/modifies a table ◦ When to use autocommit = 0? ▪ Manual Replication or Dumping data ▪ When transactions are guaranteed to be short • Commit / Rollback ◦ Self-explanatory ◦ Releases locks
◦ Index-record locks • Gap Locks ◦ Between index records, or Gap before the first or after the last index record ◦ Used in REPEATABLE READ, but not in READ-COMMITTED • Next Key Locks ( Row + Gap locks ) ◦ Index-record lock + Gap lock on the gap preceding the index record • Insert Intention Lock ◦ Gap lock set by INSERT operations prior to row insertion. • AUTO-INC Locks ◦ Default : consecutive lock mode
i. Within a transaction, Sets and keeps the snapshot established by the first read ii. Trx read view will not see trx with id >= 22142679487, sees < 22142661616 ◦ For unique index with unique search condition, only locks single index record ◦ For range searches, InnoDB locks the index range scanned ( Gap locks and Next-key Locks ) Transaction Isolation Levels
• Read Committed a. Only differences comes from LOCKS i. No Gap Locks! b. Each consistent read within a transaction sets and reads its own fresh snapshot. i. SELECTs need to scan more and more previous versions of the rows, and performance suffers.
• Read Committed • Read Uncommitted a. Read Committed + possible dirty reads b. Nope... • Serializable a. SELECT … FROM requires locks! b. Stay away from it
from application client b. As the InnoDB transaction history grows, SELECTs need to scan more and more previous versions of the rows, and performance suffers. c. https://bugs.mysql.com/bug.php?id=75540
1. Undo logs piling up 2. SELECTs have to look at old old snapshots until the hung transaction commits or aborts 3. Read throughput is decreased significantly 4. Connections pile up 5. Unable to make client connections