Reading submitted and repeatable read will enable the view by default.
View concept
1. One is a view, which is a virtual table defined by the query statement
2. Another is the consistent view used by innodb when implementing mvcc, read view, which has an implementation that supports read submitted and repeatable read isolation level.
How does snapshot work in mvcc
An array is constructed for each transaction to save the database state at the time of transaction startup
2. Two information is saved in the array
- Transaction id
- Transaction modification operations to database
Using the feature of multiple versions of each transaction, the ability to "create snapshots in seconds" is realized.
4. Updated data is read first and then written, which is called "current reading"
How is the repeatable readability of transactions implemented?
1. A snapshot will be created when the transaction starts, and all other transaction ids in the current system will be recorded in the snapshot.
2. When a transaction reads data, it will determine whether the data is visible based on the transaction id and other transaction ids in the snapshot.
3. If the transaction id is in the snapshot, the data will be visible, otherwise the data will not be visible.
4. When a transaction updates data, it will first read the data, and then determine whether the data is visible based on the transaction id and other transaction ids in the snapshot.
5. If the data is visible, update the data, otherwise an exception will be thrown.
Innodb's row data will have multiple versions, each version of the data has its own row id, and each transaction or statement has its own consistency view.
For repeatable reads, the query only recognizes data that has been submitted before the transaction starts
For reads submitted, the query only recognizes transactions that have been submitted before the statement is started
Why do most companies now use read submitted rather than repeatable reading?
1. Lock competition is reduced. In concurrency, the waiting time of locks between different transactions can be reduced and the overall system throughput can be improved.
2. Reduce the possibility of deadlock
3. Data consistency requirements