当前位置:网站首页>Mysql45 talks about transaction isolation: why can't I see it after you change it?
Mysql45 talks about transaction isolation: why can't I see it after you change it?
2022-07-26 05:53:00 【lingengy】
Some basic concepts of transaction can be seen from this article I wrote before :spring Business management
One 、 Implementation of transaction isolation
stay MySQL in , In fact, each record will record a rollback operation at the same time when it is updated . The latest value on the record , By rolling back operations , Can get the value of the previous state .
Suppose a value from 1 Has been changed in order to 2、3、4, In the rollback log, there will be records like the following .![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-HHkRMljW-1657094914100)(C3F362CD7B4E473483C046C8493CE31C)]](/img/92/9129800d2473945c30b5860376dfdf.png)
There will be different transactions started at different times read-view, There can be multiple versions of the same record in the system , It's multi version concurrency control of database (MVCC). When a transaction wants to see where it is read-view The value of , To rollback from the current value to its read-view In order to get the value of its transaction in the version .
Through this mechanism , Just record read-view The position of , It has nothing to do with how many times this value has been modified .
The system will judge that there is no earlier rollback log in the system read-view When , No transactions need these rollback logs anymore , The rollback log will be deleted .
About why try not to use long transactions
Long transactions mean that there will be a very old transaction view in the system . Since these transactions may access any data in the database at any time , So before this transaction is committed , All possible rollback records in the database must be kept , This can lead to a lot of storage space .
In addition to the impact on rollback segments , Long transactions also take up lock resources , It could also drag down the entire warehouse , We will expand the lock later .
Two 、 How to start a transaction
MySQL There are several ways to start a transaction :
- Start the transaction statement explicitly , begin or start transaction. The accompanying commit statement is commit, The rollback statement is rollback.
- set autocommit=0, This command will turn off the automatic submission of this thread . It means if you only execute one select sentence , This transaction starts , And it doesn't automatically commit . This business continues until you take the initiative to commit or rollback sentence , Or disconnect .
Some client connection frameworks will default to one after successful connection set autocommit=0 The order of . This results in the following queries being in the transaction , If it's a long connection , It leads to an unexpected long affair .
therefore , I would suggest that you always use set autocommit=1, Start the transaction through an explicit statement .
But some development students will struggle “ One more interaction ” The problem of . For a business that requires frequent use of transactions , The second way is that each transaction does not need to be actively executed once at the beginning “begin”, Reduce the number of statement interactions . If you have that concern , I suggest you use commit work and chain grammar .
stay autocommit by 1 Under the circumstances , use begin Explicitly started transactions , If you execute commit Then commit the transaction . If you execute commit work and chain, Commit the transaction and start the next transaction automatically , This also saves the need to execute again begin Statement overhead . At the same time, the benefit is to know clearly whether each statement is in a transaction from the perspective of program development .
You can information_schema Library innodb_trx Query long transactions in this table , Take the following statement , Used to find a duration greater than 60s The business of .
select * from information_schema.innodb_trx where TIME_TO_SEC(timediff(now(),trx_started))>60
边栏推荐
- 高手是怎样炼成的?
- How are masters refined?
- Why can't lpddr completely replace DDR?
- Usage and common problems of SIP softphone registered with SIP account
- Using easyexcel to import tables to realize batch insertion of xlsx files ----- MySQL of Linux
- 选电子工程被劝退,真的没前景了?
- Qu Weihai, chairman and CEO of Xinyi interactive, adheres to mutual benefit and win-win results, and Qu Weihai promotes enterprise development
- 【2023杰理科技提前批笔试题】~ 题目及参考答案
- 金仓数据库 KingbaseES SQL 语言参考手册 (11. SQL语句:ABORT 到 ALTER INDEX)
- Introduction to Chinese text error correction task
猜你喜欢

金仓数据库 KingbaseES SQL 语言参考手册 (6. 表达式)

Qt编写物联网管理平台47-通用数据库设置
![[STM32 series summary] blogger's way to quickly advance STM32 in actual combat (continuous update)](/img/20/bf7d2653aafd35e6588f819d110453.png)
[STM32 series summary] blogger's way to quickly advance STM32 in actual combat (continuous update)
![[personal summary] end of July 24, 2022](/img/9e/dfc37c2684aa8849291817782c947b.png)
[personal summary] end of July 24, 2022

Development projects get twice the result with half the effort, a large collection of open source STM32 driver Libraries

为什么LPDDR不能完全代替DDR?

Mysql45 speak in simple terms index

MBA-day28 数的概念-练习题

Unity2d animator cannot create transition

光量子里程碑:6分钟内解决3854个变量问题
随机推荐
某公司给每个工位装监控:只为看员工写代码?
Lamp architecture
Talking about the practice of software defect management
MBA-day28 数的概念-练习题
Day110. Shangyitong: gateway integration, hospital scheduling management: Department list, statistics based on date, scheduling details
中文文本纠错任务简介
[MySQL must know and know] time function number function string function condition judgment
Mysql45 speak in simple terms index
Three graduates, three years of experience in embedded software
Redis publish subscription
sdc中对cdc的处理方式
1.12 Web开发基础
Binary sort tree (BST)~
金仓数据库 KingbaseES SQL 语言参考手册 (5. 操作符)
Unity Profiler
No EGL display error resolution
Etcd database source code analysis - cluster membership changes log
How to name the project version number? Looks like cow b
Qt编写物联网管理平台47-通用数据库设置
三本毕业,三年嵌入式软件的心路历程