What is Repeatable Read isolation level

Theory

What is Repeatable Read isolation level

In database systems, isolation level refers to the degree to which the actions of one transaction are isolated from the actions of other transactions. Isolation levels are used to prevent different transactions from interfering with each other and to ensure that the results of a transaction are consistent with the database's state.

In MySQL, the REPEATABLE READ isolation level is one of four isolation levels available. It is generally considered to be a middle ground between the higher-concurrency READ COMMITTED isolation level and the lower-concurrency SERIALIZABLE isolation level.

One of the main features of the REPEATABLE READ isolation level is that it prevents non-repeatable reads. A non-repeatable read occurs when a transaction reads a row, and then another transaction updates or deletes that row before the first transaction is finished. If the first transaction reads the row again, it will get a different result than it did the first time, which can cause inconsistencies in the data.

The REPEATABLE READ isolation level prevents this by holding a shared lock on rows that are read during a transaction. This means that other transactions cannot update or delete the locked rows until the first transaction is finished. However, other transactions can still insert new rows or update or delete rows that have not been locked.

Another feature of the REPEATABLE READ isolation level is that it prevents phantom reads. A phantom read occurs when a transaction reads a set of rows that match certain criteria, and then another transaction inserts a new row that also matches the criteria. If the first transaction reads the rows again, it will see the new row, even though it was not present when the transaction began.

The REPEATABLE READ isolation level prevents this by holding a shared lock on the entire range of rows that are read during a transaction. This means that other transactions cannot insert new rows that match the criteria until the first transaction is finished. However, other transactions can still update or delete rows that have already been read.

One potential downside of the REPEATABLE READ isolation level is that it can cause contention and reduce concurrency. Since it holds shared locks on rows and ranges of rows, it can block other transactions from accessing the locked data. This can lead to slower performance and increased wait times for transactions to complete.

Overall, the REPEATABLE READ isolation level is a good choice for transactions that need to read data multiple times and need to ensure that the data is consistent. It is particularly useful for transactions that need to generate reports or perform analysis on large sets of data, as it ensures that the data will not change while the transaction is running. However, it may not be the best choice for transactions that need to update or delete data frequently, as it can cause contention and reduce concurrency.

Show comments

Laravel

5 min

How to make Laravel authentication

Laravel provides a neat function that quickly generates a scaffold of routes, views, and controllers used for authentication.

Laravel

7 min

How to install Laravel application

This article will cover how to install and create a local development environment for your Laravel application. There are only a couple of steps that needs to be done.

Laravel

3 min

How to set appropriate Laravel permissions on Linux server

After publishing your Laravel application to a real web server, you discover then some of your functionalities are failing.

Codinary