Analysis of MYSQLREPEATABLE-READ isolation level

Source: Internet
Author: User
The REPEATABLE-READ can be read again, and the content of the select table in the setautocommit0 or STARTTRANSACTION state will not change. This isolation level may cause the read to have been modified. For example, in session 1, read a field and a line a1. In Session 2, modify this line a0, and submit the word "update" in session 1.

The REPEATABLE-READ can be read repeatedly, and the contents of the select table in the set autocommit = 0 or start transaction state will not change. This isolation level may cause the read to have been modified. For example, in session 1, read a field and a = 1. In Session 2, modify the field a = 0, and submit the word "update" in session 2.

The REPEATABLE-READ can be read repeatedly, and the contents of the select table in the set autocommit = 0 or start transaction state will not change. This isolation level may cause the read to have been modified.

For example:

Session 1 reads a field with a line a = 1

In Session 2, this field is modified to a = 0 and submitted.

When the field a = 0 is updated in session 1, it will find that the number of affected rows is 0, so that you can determine whether the modification is successful based on whether the number of affected rows is 0 or 1!

This is useful in some programs!

Session 1:

Mysql> set autocommit = 0;
Query OK, 0 rows affected (0.00 sec)

Mysql> select * from test. dd where id = 1;
+ ---- + ------ +
| Id | aa |
+ ---- + ------ +
| 1 | 2 |
+ ---- + ------ +
1 row in set (0.00 sec)

Session 2:

Mysql> update test. dd set aa = 1 where id = 1;
Query OK, 1 row affected (0.09 sec)
Rows matched: 1 Changed: 1 Warnings: 0

Session 3:

Mysql> select * from test. dd where id = 1;
+ ---- + ------ +
| Id | aa |
+ ---- + ------ +
| 1 | 2 |
+ ---- + ------ +
1 row in set (0.00 sec)

Mysql> update test. dd set aa = 1 where id = 1;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0

The number of affected rows here is 0. We can determine whether the update is successful based on this value. This is useful when you need to change the status bit of some rows!

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.