MySQL database transaction MVCC

Innodb just borrowed the name MVCC provides non-blocking reads only.
https://m.imooc.com/article/17290
1. simple lock is how to achieve the read committed?

Starting from this isolation level effect: The transaction can only read the records of other committed transactions.
Database transaction isolation level implementation, InnoDB supports row-level locking, plus the write row-level exclusive lock (X lock), then when other transactions are accessing another transaction update (except for select operations are write operations on other operating nature ) during the same record, read the transaction will be blocked. We can only wait until the record (in fact, the lock on the index) can be accessed after the release of the exclusive lock, that is, when the transaction is committed. This can really achieve read commited isolation level results.
Database to do so can really achieve the effect of a transaction can only read the records of other committed transactions, but this is a very inefficient approach, and why? Because for most applications, the read operation is greater than the write operation, when a write lock, then read operations are blocked, this will lead to a corresponding application by the ability to contain the database.

2. demonstrate the real situation look like?

Look as follows:
1. Open the client instance two, provided transaction isolation level read committed, and each open transaction.

Isolation committed Level Read Transaction SET;
SET the autocommit = 0;
the begin;
2. The client 1 to do an update operation:

update test set name = 'test' where id = 32;
the results shown below:
screenshot

3. Client 2 do query:

select name from test where id = 32 ;
results are shown below:
screenshot

Then you have questions about the estimates, being the client 1 upate records, client 2 also non-blocking read, and read the data that was not changed.
That's InnoDB secondary played well, because the internal use of MVCC mechanism to achieve consistency non-blocking reads, greatly improving the efficiency of concurrent read and write, write, does not affect read, and read something mirrored version of the record.

Guess you like

Origin blog.csdn.net/sinat_36748650/article/details/92083061