Dark Horse day11 dirty read data & amp; solution, dark horse day11

Source: Internet
Author: User

Dark Horse day11 dirty Data Reading & Solutions, dark horse day11

Database:

Create table account (
Id int primary key auto_increment,
Name varchar (20 ),
Money double
);

Insert into account values (null, 'a, 100 );

Insert into account values (null, 'B', 100 );


1. Demonstrate dirty reading

Open two client windows. The level of client A is the default Repeatable read of the database-this can prevent dirty read/non-repeated read problems, but cannot prevent virtual read (phantom read) problems. Changing the level of client B to the Read uncommitted level with the highest efficiency cannot solve the dirty Read problem.

Window:

Start transaction: start transaction;

Account a transfers RMB 10 to account B: update account set money = money-10 where name = 'a ';

Add 10 RMB to account B: update account set money = money + 10 where name = 'B ';

Do not submit transactions;

Window B:

Start transaction: start transaction;

Query account B data in the database: select * from account;


Window:

Rollback transaction: rollback;

Window B:

Query data: select * from account;


Dirty read data is generated.

Solution:

Change the isolation level of window B to Read committed.



Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.