MYSQL5.7 Read COMMITTED transaction ISOLATION LEVEL study-phantom read occurs

Source: Internet
Author: User

In the case of the transaction isolation level Read Committed:

Transaction 2 does not perform a commit and can read the newly added record to transaction 1. A phantom read is shown here.

When the transaction isolation level is changed to Repeatable-read, the ability to resolve the problem is to resolve the Phantom read.

Phantom Read definition: A transaction re-reads the previously retrieved data according to the same query criteria, but finds that other transactions have inserted new data that satisfies its query criteria.



Session1 Execution Transaction 1: Insert and commit only

Mysql> SELECT @ @global. tx_isolation;select @ @tx_isolation;

+-----------------------+

| @ @global. tx_isolation |

+-----------------------+

| read-committed |

+-----------------------+

1 row in Set (0.01 sec)


+----------------+

| @ @tx_isolation |

+----------------+

| read-committed |

+----------------+

1 row in Set (0.00 sec)


mysql> start transaction;

Query OK, 0 rows Affected (0.00 sec)


Mysql> select * from Sun;

+--------+------+

| name | Age |

+--------+------+

|   Summer | 26 |

+--------+------+

1 row in Set (0.00 sec)


Mysql> INSERT into sun values (' AA ', ' 88 ');

Query OK, 1 row Affected (0.00 sec)


Mysql> commit;


session2 execution Transaction 2: Query only

Mysql> SELECT @ @global. tx_isolation;select @ @tx_isolation;

+-----------------------+

| @ @global. tx_isolation |

+-----------------------+

| read-committed |

+-----------------------+

1 row in Set (0.00 sec)


+----------------+

| @ @tx_isolation |

+----------------+

| read-committed |

+----------------+

1 row in Set (0.00 sec)


mysql> start transaction;

Query OK, 0 rows Affected (0.00 sec)


Mysql> select * from Sun;

+--------+------+

| name | Age |

+--------+------+

|   Summer | 26 |

|   AA | 88 |

+--------+------+





MYSQL5.7 Read COMMITTED transaction ISOLATION LEVEL study-phantom read occurs

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.