当前位置:网站首页>Deeply understand the characteristics of database transaction isolation
Deeply understand the characteristics of database transaction isolation
2022-07-07 10:50:00 【Taylor lance】
Many students don't know much about database transaction isolation , After reading it for a long time, I seem to understand it and I don't seem to understand it , Let me talk about my understanding ;
Here is a key point , Do it , Open it manually sql Command window , Knock the command by hand , A certain , A certain .
First , What is business ;
One sql Is a statement a transaction ?
Only the display is written begin ,rollback,commit; Is it a business ?
One sql Statement is a transaction , Database default begin and commit;
Show written , That sentence is even more business , So when reading books, as long as the textbook mentions affairs , You have to understand A statement is also a transaction .
Connect :https://zhuanlan.zhihu.com/p/67808523
Log in to the database first postgres perhaps mysql/oracle
Through the command :
show default_transaction;
Check the default isolation level of the database .
** Serialization (Serializable,SQLite The default mode ):** The highest level of isolation . Two simultaneous transactions 100% Isolation , Each transaction has its own " The world ", Serial execution .
** Repeatable (Repeatable read,MySQL The default mode ):** If a transaction executes successfully and new data is added ( Transaction submission ), This data is visible to other ongoing transactions . But if the transaction succeeds in modifying a piece of data , The modification result is not visible to the running transaction . therefore , Transactions only break through isolation in terms of new data , Still isolate existing data .
** Read committed (Read committed,Oracle、PostgreSQL、SQL Server The default mode ):** Repeatable + New isolation breakthrough . If the transaction A Read the data D, Then the data D To be transacted B modify ( Or delete ) And submit , Business A Read data again D Changes in data ( Or delete ) Is visible . This is called non repeatable (non-repeatable read).
** Read uncommitted (Read uncommitted):** The lowest level of isolation , Yes, read committed + New isolation breakthrough . If the transaction A Read the data D, Then the data D To be transacted B modify ( But did not submit , Business B Still running ), Business A Read data again D when , Data modification is visible . If the transaction B Roll back , The transaction A Second read data D It's meaningless , Because that's business B Changes made that never happened ( It has been rolled back ). This is called dirty reading (dirty read).
Serialization (Serializable,SQLite The default mode )
And then by order :
show transaction_isolation;
View the current isolation level .
Let's first look at the highest isolation level :serializable
begin;
set transaction isolation level serializable;
....
commit;
The isolation level set above is serializable, Before setting , Be sure to add. begin, It means that your current business is serializable Isolation ,commit after , If the next transaction is not set , Is the default isolation level of your database .
What does this isolation level mean ?
You open another window , You don't need to show the addition begin commit, Just add it in a mess , Delete , Modifying data , While changing, you set it on the other side serializable Query in the window of , Have you found , You set up. serializable The data in this window seems to live in a copy of the moment you just entered , Nothing has changed . This is the highest specification isolation .
To sum up :serializable Under isolation level , you are here serializable All operations in the transaction are isolated in the state of the table before you enter the transaction ( It's like giving you copy Took a snapshot , All your operations are on this copy ), You can't see what others have changed .
Repeatable (Repeatable read,MySQL The default mode )
In this state , You can see the submissions added by others . You can't see what others have modified and submitted .
however ,PostgreSQL Achieve more stringent , It is not only required to be repeatable , Unreal reading is not allowed yet . So it seems to be similar to serializable It's the same .
Read committed (Read committed
You can see what others have submitted ..
Read uncommitted (Read uncommitted
You can see what others haven't submitted .
in fact , stay postgresql in , Read uncommitted (read uncommitted) And read submit (read committed) The implementation of is consistent , So in essence PG Only three isolation levels are achieved .
Reference resources :https://www.xluke.info/article/pg-isolation
边栏推荐
- Records on the use of easyflash v3.3
- Deep understanding of Apache Hudi asynchronous indexing mechanism
- Five simple and practical daily development functions of chrome are explained in detail. Unlock quickly to improve your efficiency!
- 2022年7月10日“五心公益”活动通知+报名入口(二维码)
- Is the gold content of intermediate e-commerce division in the soft exam high?
- Leetcode-304: two dimensional area and retrieval - matrix immutable
- P2788 math 1 - addition and subtraction
- Common shortcut keys in IDA
- Simple and easy to modify spring frame components
- TypeScript 接口继承
猜你喜欢
软考一般什么时候出成绩呢?在线蹬?
优雅的 Controller 层代码
Is the soft test intermediate useful??
How to successfully pass the senior system architecture designer in the second half of the year?
July 10, 2022 "five heart public welfare" activity notice + registration entry (two-dimensional code)
String formatting
2022年7月10日“五心公益”活动通知+报名入口(二维码)
Five simple and practical daily development functions of chrome are explained in detail. Unlock quickly to improve your efficiency!
Network engineer test questions and answers in May of the first half of 2022
Deeply analyze the main contents of erc-4907 agreement and think about the significance of this agreement to NFT market liquidity!
随机推荐
2022.7.5DAY597
2021 summary and 2022 outlook
[OneNote] can't connect to the network and can't sync the problem
Unable to open kernel device '\.\vmcidev\vmx': operation completed successfully. Reboot after installing vmware workstation? Module "devicepoweron" failed to start. Failed to start the virtual machine
Mendeley -- a free document management tool that automatically inserts references into papers
555 circuit details
openinstall与虎扑达成合作,挖掘体育文化产业数据价值
【作业】2022.7.6 写一个自己的cal函数
香橙派OrangePi 4 LTS开发板通过Mini PCIE连接SATA硬盘的操作方法
【PyTorch 07】 动手学深度学习——chapter_preliminaries/ndarray 习题动手版
深入理解Apache Hudi异步索引机制
【STM32】实战3.1—用STM32与TB6600驱动器驱动42步进电机(一)
CC2530 zigbee IAR8.10.1环境搭建
MONAI版本更新到 0.9 啦,看看有什么新功能
施努卡:机器视觉定位技术 机器视觉定位原理
高级软考(网络规划设计师)该如何备考?
软考一般什么时候出成绩呢?在线蹬?
宁愿把简单的问题说一百遍,也不把复杂的问题做一遍
IDA中常见快捷键
How much review time does it usually take to take the intermediate soft exam?