What are the isolation levels for a database?

Source: Internet
Author: User
Tags ming ticket

 1.READ uncimmitted (read not submitted)

Changes in the transaction, even if not committed, can be seen in other transactions, such as the above two steps of this phenomenon is called dirty read, this isolation level will cause a lot of problems, if not necessary, do not use casually

Example: or a ticketing system, Xiao Ming and Floret is the conductor, they are two different window of staff, now the ticket system only left 3 tickets, at this time a to the small China here to buy 3 tickets, b to Xiao Ming ticket, small Hua check to the more than the ticket also to take the order, to implement the third step, Xiao Ming received a request for B to inquire whether there is more than After seeing Xiao Hua sell 3 tickets, he refused to sell the tickets. But the system went wrong, the third step failed, the database to ensure atomicity, the data was rolled back, that is, a ticket has not been sold.

Summary: This is the fact that the transaction has not yet been committed, and other transactions can see the consequences of the data he has modified, that is, dirty reading.

  

  2.READ COMMITTED (Submit read)

The default isolation level for most database systems is read COMMITTED, which is the beginning of a transaction that can only see the results of a transaction that has been completed and is being executed that cannot be seen by other transactions. This level will show the phenomenon of reading old data

Example: or Wing Minghua sales, 3, A to the small wah there to request 3 tickets, the small China to accept orders, to sell 3 tickets, the above sales step in the execution of the time, B also came to Xiao Ming there to buy tickets, because of the sales of the small business in half, Xiao Ming business did not see the affairs of the Small Wah, read the number of votes Ready to accept the order, the sales of the business completed, at this time, Xiao Ming's system turned to show 0 tickets, Xiao Ming just want to press the mouse click to accept orders hand and quickly shrink back.

Summary: This is the business of the small China to execute half, and xiaoming can not see the operation he performed, so see the old data, that is, invalid data

  3.REPEATABLE Read (Repeatable Read)

Repeatable read solves the problem of dirty reads, which ensures that the results of each row of records are consistent, that is, the above-mentioned reading of the old data problem, but can not solve another problem, magic Line, as the name implies is suddenly jumped out of the row data. Refers to a transaction reading a range of data, but another transaction to this range of data to insert data, resulting in multiple reads, the number of rows of data is inconsistent.

Example: The sales department has provisions, if the sales record is lower than the specified value, to deduct wages, at this time the manager in the back-end console to see the sales records of Xiao Ming, found that the sales record does not reach the specified number of times, the heart Anxi, ready to print a good sales list, righteously and Xiao Ming proposed, Did not expect to print out when found in the sales list of sales increased a few, just just to meet the requirements, the Gas manager tore the list of paper. It turned out that Xiaoming had sold a few tickets at the moment he was about to print, thus avoiding the blood-light disaster of reducing wages.

Summary: While reading the same data guarantees consistency, there is no guarantee that no new data will be inserted

  4.SERIALIZABLE (Serializable)

The serializable is the highest isolation level, which is performed serially by forcing transactions (note serial), avoiding the previous phantom read, and because of his large number of locks, which causes a large number of requests to time out, so performance is compared to the bottom, This isolation level may be considered in particular when data consistency is required and concurrency does not need to be that large

What are the isolation levels for a database?

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.