当前位置:网站首页>Is the transaction in mysql45 isolated or not?
Is the transaction in mysql45 isolated or not?
2022-07-26 05:52:00 【lingengy】

Business id
InnoDB Each transaction has a unique transaction ID, called transaction id. It is at the beginning of the transaction to InnoDB Of the transaction system , It is strictly increasing in the order of application .
And each row of data has multiple versions . Every time a transaction updates data , Will generate a new data version , And the transaction id The transaction assigned to this data version ID, Write it down as row trx_id. meanwhile , Keep the old data version , And in the new data version , You can get information directly .
in other words , A row in a data table , There may be multiple versions (row), Each version has its own row trx_id.
Snapshots and views
stay MySQL in , There are two “ View ” The concept of :
- One is view. It is a virtual table defined by a query statement , Execute the query statement at the time of the call and generate the result . The syntax for creating a view is create view … , And its query method is the same as the table .
- The other is InnoDB In the realization of MVCC Consistent read view used in , namely consistent read view, Used to support RC(Read Committed, Read the submission ) and RR(Repeatable Read, Repeatable ) Implementation of isolation level .
View has no physical structure , It is used to define during the execution of a transaction “ What data can I see ”.
At repeatable read isolation level , When the transaction starts “ Took a snapshot ”. Be careful , This snapshot is based on the entire library .

On the implementation , InnoDB An array is constructed for each transaction , Used to save the transaction startup moment , Right now “ active ” All the business of ID.“ active ” Refers to , Launched but not yet submitted .
A data version , For a transaction view , Except that your updates are always visible , There are three situations :
- Version not submitted , invisible ;
- Version submitted , But it was submitted after the view was created , invisible ;
- Version submitted , And it was submitted before the view was created , so .
Update logic
The updated data is read first and then written , And this read , Can only read the current value , be called “ The current reading ”(current read).
therefore , In the execution of the transaction B When querying statements , Take a look at their own version number is 101, The version number of the latest data is also 101, It's your own update , You can use it directly , So the query results in k The value of is 3.
Here we mention a concept , It's called current reading . Actually , except update Out of statement ,select If the statement is locked , It's also the current reading .
therefore , If the business A Query statement select * from t where id=1 Revise it , add lock in share mode or for update, You can also read that the version number is 101 The data of , Back to k The value of is 3. The next two select sentence , That is to add the read lock respectively (S lock , Shared lock ) And write lock (X lock , Exclusive lock ).
mysql> select k from t where id=1 lock in share mode;
mysql> select k from t where id=1 for update;
边栏推荐
- unity 像素画导入模糊问题
- JS的调用方式与执行顺序
- 嵌入式通用学习路线整理
- Sequential search, half search, block search~
- ES Cluster in Red status: what about write & delete operations?
- Dynamic memory management and flexible array
- 金仓数据库 KingbaseES SQL 语言参考手册 (11. SQL语句:ABORT 到 ALTER INDEX)
- Select sort / insert sort / bubble sort
- SSH Remote Management
- Jdbc流式查询与游标查询
猜你喜欢

金仓数据库 KingbaseES SQL 语言参考手册 (8. 函数(十))

嵌入式通用学习路线整理

Is it really hopeless to choose electronic engineering and be discouraged?

Mysql45 speak in simple terms index

柠檬班自动化学习毕竟

Debugging sharp weapon! A lightweight log library log.c

The refurbishment and counterfeiting of chips have made people feel numb

Application and value of IVR in VoIP telephone system

又一开源神器,值得收藏学习!

光量子里程碑:6分钟内解决3854个变量问题
随机推荐
Hack the box - Introduction to networking module detailed Chinese tutorial
电机控制专栏文章汇总
Ros2 preliminary: basic communication with topic
ES Cluster in Red status: what about write & delete operations?
如何查看Pod里容器名称
[论文笔记] 面向网络语音隐写的抗分组丢失联合编码
Mongodb tutorial Chapter 08 comparison operators
K. Link with Bracket Sequence I dp
Qu Weihai, chairman and CEO of Xinyi interactive, adheres to mutual benefit and win-win results, and Qu Weihai promotes enterprise development
How to name the project version number? Looks like cow b
Is it really hopeless to choose electronic engineering and be discouraged?
为什么LPDDR不能完全代替DDR?
解决Vagrant报错b:48:in `join‘: incompatible character encodings: GBK and UTF-8 (Encoding::Compatib
《MongoDB入门教程》第08篇 比较运算符
QT writing IOT management platform 47 general database settings
Redis主从复制
Lightweight MCU command line interaction project, all open source
[paper notes] anti packet loss joint coding for network speech steganography
Introduction to Chinese text error correction task
ETCD数据库源码分析——Cluster membership changes日志