当前位置:网站首页>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
边栏推荐
- The gun startles the dragon, and the crowd "locks" Zhou Zhi
- 【PyTorch 07】 动手学深度学习——chapter_preliminaries/ndarray 习题动手版
- 2022.7.3DAY595
- 使用U2-Net深层网络实现——证件照生成程序
- How to prepare for the advanced soft test (network planning designer)?
- 软考中级电子商务师含金量高嘛?
- ThreadLocal会用可不够
- seata 1.3.0 四种模式解决分布式事务(AT、TCC、SAGA、XA)
- Schnuka: machine vision positioning technology machine vision positioning principle
- CAS mechanism
猜你喜欢
Using tansformer to segment three-dimensional abdominal multiple organs -- actual battle of unetr
BUUCTF---Reverse---reverse1
The difference between monotonicity constraint and anti monotonicity constraint
Mendeley--免费的文献管理工具,给论文自动插入参考文献
How to prepare for the advanced soft test (network planning designer)?
软考信息处理技术员有哪些备考资料与方法?
openinstall与虎扑达成合作,挖掘体育文化产业数据价值
南航 PA3.1
[installation system] U disk installation system tutorial, using UltraISO to make U disk startup disk
1323: [example 6.5] activity selection
随机推荐
Operation method of Orange Pie orangepi 4 lts development board connecting SATA hard disk through mini PCIe
SQL Server 知识汇集9 : 修改数据
Applet jump to H5, configure business domain name experience tutorial
Monai version has been updated to 0.9. See what new functions it has
【实战】霸榜各大医学分割挑战赛的Transformer架构--nnFormer
【STM32】实战3.1—用STM32与TB6600驱动器驱动42步进电机(一)
2021 summary and 2022 outlook
String formatting
南航 PA3.1
Trajectory planning for multi robot systems: methods and Applications Overview reading notes
The width of table is 4PX larger than that of tbody
SQL Server 知识汇集11 : 约束
路由器开发知识汇总
中级软件评测师考什么
Summary of router development knowledge
Deep understanding of Apache Hudi asynchronous indexing mechanism
[pro test feasible] error while loading shared libraries solution
P1031 [noip2002 improvement group] average Solitaire
P1223 queuing for water /1319: [example 6.1] queuing for water
长列表性能优化方案 memo