当前位置:网站首页>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
边栏推荐
- ML.NET相关资源整理
- Osg3.6.5 failed to compile freetype
- 110 MySQL interview questions and answers (continuously updated)
- Gan: generate adversarial networks
- Multifunctional signal generator based on AD9850
- 【Transformer】ATS: Adaptive Token Sampling For Efficient Vision Transformers
- Intel将逐步结束Optane存储业务 未来不再开发新产品
- [[first blog]p controller implementation instructions in UDA course]
- RPC and rest
- Day15 (day16 extension): file contains vulnerability
猜你喜欢
What constitutes the smart charging pile system?
ROS common instructions
DC motor control system based on DAC0832
Four pin OLED display based on stm32
信息系统项目管理师必背核心考点(五十三)质量等级
110道 MySQL面试题及答案 (持续更新)
Ga-rpn: recommended area network for guiding anchors
The computer video pauses and resumes, and the sound suddenly becomes louder
Intel will gradually end the optane storage business and will not develop new products in the future
C language sorts n integers with pointers pointing to pointers
随机推荐
AES 双向加密解密工具
Day5: PHP simple syntax and usage
Multifunctional signal generator based on AD9850
Day15 (day16 extension): file contains vulnerability
The computer video pauses and resumes, and the sound suddenly becomes louder
DAC0832 waveform generator based on 51 single chip microcomputer
The first week of postgraduate freshman training: deep learning and pytorch Foundation
Search and recall classic questions (eight queens)
Week 2: convolutional neural network basics
Sword finger offer 50. the first character that appears only once
【Transformer】SegFormer:Simple and Efficient Design for Semantic Segmentation with Transformers
Deep learning (2): image and character recognition
Third week weekly report resnet+resnext
Clickhouse learning (I) Clickhouse?
Clickhouse learning (III) table engine
Txt plain text operation
ML.NET相关资源整理
【Transformer】ATS: Adaptive Token Sampling For Efficient Vision Transformers
Clickhouse learning (II) Clickhouse stand-alone installation
Source code compilation pytorch pit