Database isolation level and its implementation principle

Source: Internet
Author: User

The corresponding principles of my 4 isolation levels are summarized as follows:

The principle of read_uncommited:
    • The transaction does not lock the data currently being read;
    • When a transaction updates the moment of a data (that is, the moment the update occurs), it must be added to the row-level shared lock until the end of the transaction is released.

Performance:

    • Transaction 1 reads a row record, transaction 2 can also read, update, and when transaction 2 updates the record, transaction 1 reads the record again, and can read the modified version of transaction 2 to the record, even if the modification has not yet been committed.
    • When transaction 1 updates a row record, transaction 2 cannot update the row record until the end of transaction 1.
The principle of read_commited:
    • The transaction adds a row-level shared lock to the data currently being read (locking when read), and once the line is read, the row-level shared lock is released immediately;
    • When a transaction updates the moment of a data (that is, the moment the update occurs), it must be added to the exclusive lock on the row until the end of the transaction is released.

Performance:

    • Transaction 1 reads a row of records, transaction 2 can also read, update, and when transaction 2 updates the record, transaction 1 reads the record again, read only the version before the transaction 2 is updated, or the version after transaction 2 commits.
    • When transaction 1 updates a row record, transaction 2 cannot update the row record until the end of transaction 1.
The repeatable READ principle:
    • When a transaction reads a data in an instant (that is, the moment it begins to read), it must be shared with a row level lock until the end of the transaction is released;
    • When a transaction updates the moment of a data (that is, the moment the update occurs), it must be added to the exclusive lock on the row until the end of the transaction is released.

Performance:

    • Transaction 1 reads a row of records, transaction 2 can also read, update, and when transaction 2 updates the record, transaction 1 reads the record again, and the read is still the version that was read for the first time.
    • When transaction 1 updates a row record, transaction 2 cannot update the row record until the end of transaction 1.
The principle of SERIALIZABLE:
    • When a transaction reads data, it must first be shared with a table-level lock until the end of the transaction is released;
    • When a transaction updates data, it must first add a table-level exclusive lock until the end of the transaction is released.

Performance:

    • When transaction 1 is reading a record in Table A, transaction 2 can also read the a table, but cannot update, add, delete, and end the a table until transaction 1.
    • When transaction 1 is updating the records in table A, transaction 2 cannot read any records of table A, and it is more unlikely that the a table will be updated, added, deleted until the end of transaction 1.

Database isolation level and its implementation principle

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.