I. Introduction
- front by "Mysql transaction - isolation" of learning, knowing the realization of the transaction , is based on obtaining a consistent view to achieve the.
II: So, when it will get to a consistent view of it?
- For example: There are three transaction, details of FIG start (autocommit = 1)
-
- Services A, B, C found value is how much?
- Transaction B value of k is found to 3 , and the Transaction A value of k is found 1
- Understanding
- the begin / Start Transaction command and the starting point is not a transaction , in execution to after their first operation InnoDB table statement, the transaction really start .
Three: Implementation Conformance view?
- In Repeatable Read isolation level transaction at boot time to "take a snapshot." Note that this is based on a snapshot of the entire library.
- At this point, you would say it does not look realistic ah. If a library has 100G, then I start a transaction, MySQL will copy data out of 100G, the process is much more Mana. However, I usually execute transactions quickly ah.
- This introduces the concept of InnoDB is MVCC.
Four: multi-version concurrency control (MVCC)
- concept
- Most of Mysql transactional storage engine to achieve not simple row-level locking , generally realized MVVc (multi-version concurrency control)
- different engines for different implement MVCC, typically there are (optimistic concurrency control / pessimistic concurrency control)
- Principle
- By a snapshot at a point of realization save data , but also said, however, how long the execution of each transaction sees the data are consistent.
- that is, transactions different start times for the same table, the same time to see the data may be different.
- Detailed
- by saving two hidden columns after each line achieved record
- a creation time saved row
- a expiration time the row
- Saving time is not the actual time
- but the system version number, each beginning a new transaction, the version number is automatically incremented
- Transaction system version number will be the start time of the transaction as the version number, and the version number to each row of the query to the record as a comparison
- MVVc process - in REPEATTABLE READ (repeatable read - isolation level) Example
- SELECT
- InnoDB will find the version earlier than the current version of the data line transaction , the transaction can be guaranteed line read
- either in before the transaction began already exists .
- either on their own or insert the modified transaction .
- Delete line version of either undefined or current affairs big and version number so you can ensure that the transaction to read a row, was not removed at the beginning of the transaction.
- INSERT
- To save the current system version number as the version number of the newly inserted row row.
- DELETE
- To save the current system version number identifies a row as deleted rows deleted
- UPDATE
- New inserts a row, to save the current system version number as the row version.
- and save the current version of the system to the original line, as a line deletion indicator.
- important point
- holds two version numbers, so that the majority of read operations do not need to lock.
- This design makes the data easier to read, good performance, and also to ensure compliance with the standard will read the line.
- lack of a record of each line needs additional storage space, need to do more maintenance work.
- MVVC currently only works in read committed / Repeatable Read isolation level at two
- Read Uncommitted always read the latest row
- serialization will be locked to the line for all to read.
Five: Appendix
-
MySQL *> Show Status Table like ' tblwechatTemplate ' \ G; * *************************** . 1 Row ******. ********************* * the name: tblwechatTemplate * table * engine: InnoDB * engine * Version: 10 * ROW_FORMAT: Dynamic * line mode * the rows: 32 * the number of rows in the table * for MyIsam other and are accurate * for InnoDB is an estimated value * AVG_ROW_LENGTH: 2048 * the average bytes per line * Data_length: 65536 *Table Data Size * Max_data_length: 0 * maximum capacity table data, and storing engine-related * Index_length: 49152 * the index size (bytes) * Data_free: 0 * AUTO_INCREMENT: 35 * the value increment primary key * create_time: 2019 - 04 - 22 16 : 19 : 21 * table creation time * update_time: 2019 - 05 - 16 17 : 03 : 45 * table data last modified * CHECK_TIME: NULL *Collation: utf8_general_ci * default character set and collation * Checksum: NULL * Create_options: * the Comment: template message template id record form