Isolation level of DB2

Source: Internet
Author: User

Article Source: http://blog.csdn.net/msoso_______1988/article/details/9248535

In DB2, there are four isolation levels: Rs,rr,cs,ur. Below are some descriptions of four isolation levels, along with the results of individual tests. Isolation level is an important part of the locking strategy, it directly affects the lock range and the duration of the lock. Two applications, even if the same operation is performed, may result in different locking results due to the different isolation levels chosen.

In DB2, there are four isolation levels: Rs,rr,cs,ur. Here are some descriptions of the four isolation levels.

Read reliability (Rs-read stability)
If this isolation level is used, the NS lock is added to all rows that have been read in a transaction until the transaction is committed or rolled back, and the locks on the row are freed. This guarantees that the resulting value will not change even if the same row is read multiple times in a transaction.

But other transactions can be inserted, which prevents DB2 from being defined by non-repeatable reads, but has a phantom read problem. That is, if you use this isolation level, the result set may change in a transaction if you reopen a cursor that has already been processed using the same search criteria. (Some rows may be added, which are called Phantom Rows (Phantom)). This is because the RS isolation level cannot prevent new rows from being added to the result set through an INSERT or update operation.

Personal notes:

? According to the actual test situation, RS mode: After the query is complete, the records in the result set that satisfy the condition are locked and the conditions are not locked.

? You can update a record that does not meet the criteria, or you can insert a new record. Others can query for records that are already locked, but they cannot be updated.

Repeat read (Rr-repeat read)
If this isolation level is used, the S lock is added to all rows that have been read in a transaction, knowing that the transaction is committed or rolled back, and the locks on the row are freed. This guarantees that the resulting value will not change even if the same row is read multiple times in a transaction.

Also, the resulting set of results will not change if the processed cursor is reopened with the same search criteria in the same transaction. Repeated reads have a greater range of lock-out relative to read reliability.

Resolve Phantom reads. Locks the read transaction in any way that references all rows, plus s locks throughout the table. Equivalent to serializable read-write lock mutex

For read reliability, the application locks only all rows that meet the requirements, and for repeated reads, the application locks all rows that have been scanned. For example, if an application scans 10000 rows of data in a table, it eventually finds 100 result rows that match the search criteria. If the application uses a read-reliability isolation level, the application will lock only 100 rows that meet the criteria, and if the application uses a duplicate read isolation level, the application will lock the 10000 rows that were scanned.

Personal notes

? According to the actual test situation, RR mode: After the query is completed, you can not update the conditions are not satisfied, you can not insert a new record. The possible reason is that if someone is allowed to update a record or insert a new record, it may cause damage to the original result set, and the re-reading time is different from the previous one.

? Select for update with RR/RS is a record lock that can be used to implement. is a special case. Even RR, you can still operate on other records.

Cursor Reliability (cs-cursor stability)
If this isolation level is used, in a transaction, only the row being read in the result set (the line the cursor points to) is added to the NS lock, and the other rows that are not processed are not locked. This isolation level only guarantees that the value of the row being processed will not be changed by other concurrent programs. The isolation level is the DB2 default isolation level. prevent dirty reads. Other transactions cannot update/delete the row currently referenced by the cursor. The DB2 definition of non-repeatable read and Phantom reads may occur.

Personal notes

This is a very weak isolation state only when the cursor is locked at that line.

Uncommitted read (ur-uncommitted read)
If this isolation level is used, no row locks are added for read-only operations. Typical read-only operations include:

? The result set of the SELECT statement is read-only (for example, the ORDER BY clause is included in the statement);

The definition cursor is specified as a for FETCH only.

This isolation level can improve the performance of your application while allowing for maximum concurrency. However, the data integrity of the application is compromised. If you need to read UNCOMMITTED data, the isolation level is the only option.

Personal notes

It is completely unrestricted to read, and is not guaranteed for the integrity of the same row of records.

Summarize

The locking range and duration of the isolation level mentioned above are for read operations.

For a change operation, an X lock is added to the modified line, and the X lock is not released until it is committed or rolled back, regardless of the isolation level used.

DB2 Isolation Level

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.