当前位置:网站首页>Demonstration and solution of dirty reading, unrepeatable reading and unreal reading
Demonstration and solution of dirty reading, unrepeatable reading and unreal reading
2022-07-29 08:37:00 【Soup key.tj】
Catalog
Dirty reading
Question presentation
- First set the isolation level to read uncommitted
- Then open two windows
- Operate on a table at the same time
- Both open transactions
- Such as : Li Si wants to borrow Zhang San 500 element


-- Set the transaction isolation level to read uncommitted SET GLOBAL TRANSACTION ISOLATION LEVEL READ uncommitted; -- Open transaction START TRANSACTION; -- Transfer accounts UPDATE account SET money=money-500 WHERE name=' Zhang San '; UPDATE account SET money=money+500 WHERE name=' Li Si '; -- Inquire about account surface SELECT * FROM account; -- Roll back ROLLBACK;- Problem analysis
- At this time, Zhang San turns to Li Si 500 了 , But not submitted
- And ask Li Si to inquire
- Li Si checked again that the money had indeed arrived
- Then Zhang San said he needed Li Si to fight 500 Your IOU
- Li Si gave him an IOU , This has already taken effect in the legal sense
- After Zhang San got the IOU , Rolled back
- After the rollback is completed, the data is restored again
- After a while , Li Si goes to get the money 1500 element , Insufficient balance can be found
- At this time, Li Si went to check the balance and returned to 1000 element
- In this way, Li Si not only didn't receive the money , I also wrote a note to Zhang San 500 Your IOU
- This is a problem caused by dirty reading :
- Data in another uncommitted transaction was read during one transaction
solve
- Modify the transaction isolation level to read committed

-- Set the transaction isolation level to read committed SET GLOBAL TRANSACTION ISOLATION LEVEL read committed; -- Open transaction START TRANSACTION; -- Transfer accounts UPDATE account SET money=money-500 WHERE name=' Zhang San '; UPDATE account SET money=money+500 WHERE name=' Li Si '; -- Inquire about account surface SELECT * FROM account; -- Roll back ROLLBACK;It can't be read repeatedly
Question presentation
- First set the isolation level to read committed
- Then open two windows
- Operate on a table at the same time
- Both open transactions
- Such as : Li Si wants to borrow Zhang San 500 element

- Problem analysis
- For example, the boss of the company asked Xiao Wang to inquire about the revenue of the company in that year
- What Xiao Wang found in the morning was 100 ten thousand
- It's time for the meeting , Will take this 100 Wan told the boss
- But it changed again in the afternoon , Turned into 80 ten thousand
- What Xiao Wang told his boss was 100 ten thousand , The data queried by the boss is 80 ten thousand
- This shows that the data queried many times is different
- : Read the data modified and submitted in another thing during the processing of one thing
solve
- Modify the transaction isolation level to repeatable read

-- Set the transaction isolation level to repeatable read SET GLOBAL TRANSACTION ISOLATION LEVEL REPEATABLE read; -- Open transaction START TRANSACTION; -- Transfer accounts UPDATE account SET money=money-500 WHERE name=' Zhang San '; UPDATE account SET money=money+500 WHERE name=' Li Si '; -- Inquire about account surface SELECT * FROM account; -- Commit transaction COMMIT;- If you want to see the modified data in window 2
- Window 2 is also required commit, Again select see
Fantasy reading
Question presentation
- First set the isolation level to repeatable read
- Then open two windows
- Operate on a table at the same time
- Both open transactions
- window 1 First, only add records without submitting
- And then to the window 2 Check it out
- Discovery window 2 There are no newly added records
- So in the window 2 Add a new record again
- But there is no way to add , Will be stuck
- Back to the window 1 After the commit transaction
- window 2 Immediately report the wrong , Unable to add
- Then in the window 2 Do commit transactions
- At the window 2 Query again and find that
solve
- Set the isolation level to serializable
- After modification, the window 2 When you inquire, you will get stuck
- Then in the window 1 Do commit transactions , window 2 You can immediately query successfully
- So you don't have to be in the window 2 Stuck when adding
- There is no need to think that there is no such operation as adding
边栏推荐
- Pnpm install appears: err_ PNPM_ PEER_ DEP_ ISSUES Unmet peer dependencies
- MySQL中的时间函数
- Noise monitoring and sensing system
- Cmake setting vs Startup running environment path
- 为了速率创建线程池,启动核心线程
- 深度学习(2):图片文字识别
- 分组背包
- Requests library simple method usage notes
- ROS common instructions
- Play Parkour with threejs Technology
猜你喜欢

C language sorts n integers with pointers pointing to pointers

The first week of postgraduate freshman training: deep learning and pytorch Foundation

Chrony time synchronization

Basic shell operations (Part 2)

6.2 function-parameters

Count the list of third-party components of an open source project

Reading papers on false news detection (4): a novel self-learning semi supervised deep learning network to detect fake news on

pnpm install出现:ERR_PNPM_PEER_DEP_ISSUES Unmet peer dependencies

7.3-function-templates

Day5: PHP simple syntax and usage
随机推荐
Node: file write data (readfile, WriteFile), two modes: overwrite and increment
Flask reports an error runtimeerror: the session is unavailable because no secret key was set
Windows 安装 MySQL 5.7详细步骤
Detailed steps of installing MySQL 5.7 for windows
leetcode hot 100(刷题篇9)(301/45/517/407/offer62/MST08.14/)
Intelligent temperature control system
Transaction management in SQL Server
Vs2019 compilation cryengine failure problem handling
Ar virtual augmentation and reality
Second week of postgraduate freshman training: convolutional neural network foundation
用户身份标识与账号体系实践
Sword finger offer 32 - ii Print binary tree II from top to bottom
集群使用规范
Reading papers on false news detection (4): a novel self-learning semi supervised deep learning network to detect fake news on
Basic shell operations (Part 2)
ML.NET相关资源整理
Osgsimplegl3 combined with renderdoc tool
Hal learning notes - Advanced timer of 7 timer
New energy shared charging pile management and operation platform
深度学习(2):图片文字识别




