当前位置:网站首页>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
边栏推荐
- openinstall与虎扑达成合作,挖掘体育文化产业数据价值
- BUUCTF---Reverse---reverse1
- Network engineer test questions and answers in May of the first half of 2022
- 施努卡:机器人视觉抓取工作原理 机器视觉抓取
- Summary of router development knowledge
- Schnuka: working principle of robot visual grasping machine visual grasping
- MySQL insert data create trigger fill UUID field value
- Online hard core tools
- seata 1.3.0 四种模式解决分布式事务(AT、TCC、SAGA、XA)
- What does intermediate software evaluator test
猜你喜欢
Prototype and prototype chain
中级软件评测师考什么
leetcode-304:二维区域和检索 - 矩阵不可变
1324: [example 6.6] integer interval
Pre knowledge reserve of TS type gymnastics to become an excellent TS gymnastics master
China Southern Airlines pa3.1
ArrayList线程不安全和解决方案
P2788 math 1 - addition and subtraction
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
简单易修改的弹框组件
随机推荐
Some online academic report websites and machine learning videos
String formatting
Typescript interface inheritance
【PyTorch 07】 动手学深度学习——chapter_preliminaries/ndarray 习题动手版
2022年上半年5月网络工程师试题及答案
2022.7.6DAY598
MONAI版本更新到 0.9 啦,看看有什么新功能
Schnuka: working principle of robot visual grasping machine visual grasping
The difference between monotonicity constraint and anti monotonicity constraint
IO model review
[pro test feasible] error while loading shared libraries solution
书签整理-程序员常用网站导航
【推薦系統 01】Rechub
Différences entre les contraintes monotones et anti - monotones
关于easyflash v3.3使用过程的记录
How to get hardware information in unity
Multithreaded asynchronous orchestration
Installation and configuration of slurm resource management and job scheduling system
[STM32] solution to the problem that SWD cannot recognize devices after STM32 burning program
如何顺利通过下半年的高级系统架构设计师?