Oracle statement restart Principle

Source: Internet
Author: User

SQL code
Update test set x = 1 where y = 1;
Delete from test where y = 1;
It is divided into two steps:
1. Locate the data rows that meet the Update Conditions in the table based on the where condition;
2. Update the x value of the data row found in step 1.

If the test table is large, update takes several minutes, And someone changes the value of y in a row to 2 during step 1, then in step 2, will the row with y = 2 be updated with column x?
In this case, Oracle selects "restart" to update.

In fact, Oracle uses two different methods to read data blocks when executing DML statements:
1. consistent read: When you find the data to be modified, the consistent read
2. current read: When "getting" data blocks to actually update data, the current read
Oracle uses this method to determine whether a restart is required.

In the above example, Oracle will first use consistent read to find all data rows with y = 1, therefore, even if another session modifies the y value of a row during the read period (for example, from y = 1 to y = 2 ), oracle will also use undo data to restore column y of the row to the value at the read time (y = 1), so this row will still be read. Then, when you want to update this row, Oracle will use the current read to obtain the latest version of the data block. Because it has been submitted, the value of y read is 2, it is inconsistent with y = 1 in the previous consistent read. Therefore, Oracle knows that the "restart" update operation is required.

Oracle restart process:
1. modification operations before rollback
2. Enter select for update mode and lock the row to be modified
3. Modify the locked row
(This process refers to a ORA-08177 error in SERIALIZABLE mode at the Oracle default read commited isolation level)

Related Article

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.