What happens if I set the transaction isolation level arbitrarily in the source code?

Asked 1 years ago, Updated 1 years ago, 469 views

As for how to set the transaction isolation level, Spring can be set casually by adding @Transactional for each method, or Rails can be set casually by ApplicationRecord.transaction (isolation:read_committed) do end.

Transaction isolation levels - Wikipedia lists "phenomena and anomaly" that can occur when parallel transactions are arranged.

It is often explained on the Internet that neither dirty lead nor fuzzy lead nor phantom lead will occur by referring to examples of SERIALIZABLE to each other. What do you think about designing a SERIALIZABLE transaction?I see. Even if there are many, 4*4=16 streets?)

How to set the transaction isolation level in Rails - Hack Your Design!
Transaction Management with Spring - Qiita

ruby-on-rails sql database spring

2022-09-30 21:49

1 Answers

This issue depends on how each DBMS is designed to control concurrency.First, answer about PostgreSQL and MySQL that you know.

MySQL has a different logical effect on update queries (Insert/delete/update) and reference queries (select). MySQL uses MVCC, but generally

  • select—Enables MVCC to take snapshots against them.
  • Update: Regardless of the snapshot above, the latest buffer pool value at that time will be updated.The updated table (location) is written locked.

Yes, and with this in mind, each isolation level has only a difference in how select is made.

  • READ UNCOMITED:get the latest value of the buffer pool at that time
  • READ COMMITTED: Read snapshot just before running that statement in Tx (not the beginning of Tx)
  • REPEATABLE READ:Tx Start
  • SERIALIZABLE—Rewrites all select to select for update.In this sense, it is the same as strict2 phase commit and cannot be executed without a lock.

Operates on snapshot isolation.Browse: https://ja.wikipedia.org/wiki/Snapshot_isolation

Simply put, data references work against snapshots at some point in the database, and data update systems are first-come-first-served and slow-served.

  • READ UNCOMITED—None present.Same behavior as READ COMMITTED
  • READ COMMITTED: Each sentence moves as if it were a single Tx.
  • REPEATABLE READ: Data is retrieved for the first data manipulation/reference of Tx as snapshot.
  • SERIALIZABLE:^, in order to achieve serializable, monitor the read-write relationship between serializable Txs to the same data, and rollback one or the other as it is likely to become serializable when circulated.

PostgreSQL and MySQL have MVCC/Snapshot Isolation, and the isolation level works in terms of how to retrieve data. In MVCC, data retrieval is performed on snapshot, so there is not much control of behavior by combination of isolation levels, and each Tx is current
The main difference is when you are updating data to see snapshots.

However, serializable cannot be achieved only with snapshot isolation (write skew/read only skew),

  • MySQL gets the lock even if it's read.
  • PostgreSQL monitors rw dependencies between serializable.


2022-09-30 21:49

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.