Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to set MySQL isolation to “Read Uncommitted” (dirty reads) for typical Web usage? Even with replication?

I'm working on a website with typical CRUD web usage pattern: similar to blogs or forums where users create/update contents and other users read the content.

Seems like it's OK to set the database's isolation level to "Read Uncommitted" (dirty reads) in this case. My understanding of the general drawback of "Read Uncommitted" is that a reader may read uncommitted data that will later be rollbacked.

In a CRUD blog/forum usage pattern, will there ever be any rollback? And even if there is, is there any major problem with reading uncommitted data?

Right now I'm not using any replication, but in the future if I want to use replication (row-based, not statement-based) will a "Read Uncommitted" isolation level prevent me from doing so?

What do you think? Has anyone tried using "Read Uncommitted" on their RDBMS?

like image 492
Continuation Avatar asked Jan 08 '10 05:01

Continuation


People also ask

What is set isolation to dirty read?

SET ISOLATION provides the same functionality as the ISO/ANSI-compliant SET TRANSACTION statement for isolation levels of DIRTY READ (called UNCOMMITTED in SET TRANSACTION), COMMITTED READ, and REPEATABLE READ (called SERIALIZABLE in SET TRANSACTION).

What is the use of set transaction isolation level read uncommitted?

Specifies that statements can read rows that have been modified by other transactions but not yet committed. Transactions running at the READ UNCOMMITTED level do not issue shared locks to prevent other transactions from modifying data read by the current transaction.

Which isolation level prevents dirty non-repeatable and phantom reads?

Repeatable read with pessimistic locking The repeatable read transaction isolation level is the default. This isolation level prevents dirty reads and non-repeatable reads, but does not prevent phantom reads.

Which of the following isolation levels allow dirty reads?

Read Uncommitted – Read Uncommitted is the lowest isolation level. In this level, one transaction may read not yet committed changes made by other transactions, thereby allowing dirty reads. At this level, transactions are not isolated from each other.


2 Answers

MySQL 5.1 is stricter when using read-uncommitted and binlogging (needed for replication) - so you can get errors on some simple update/delete statements that you wouldn't get in the default isolation level REPEATABLE READ. I have seen simple PK updates such as:

Update foo set bar=1 where id=1234;

Error with: mysql_real_query error 1598 message : Binary logging not possible. Message: Transaction level 'READ-UNCOMMITTED' in InnoDB is not safe for binlog mode 'STATEMENT'

So you must be prepared to deal with this by switching back to repeatable reads when modifying data, or using separate connections for reads and writes, with their own isolation levels. The latter can get handy when/if your project scales and replication is needed, so you can send select to a read-only slave and writes on the master.

OTOH, using read-uncommitted for reads can be a real gain, if consistent reads aren't strictly needed, as Innodb has less locks to take.

As for the question regarding if rollbacks are possible, I think you're the best person to tell us about it, as you are the one coding it :).

like image 180
ggiroux Avatar answered Nov 02 '22 05:11

ggiroux


This isolation level means that you may read inconsistent data. There is no gurantee that data you read is from a consistent view of the database.

Whethere this is an issue or not is not a MySQL question, but an application question, which involves an assessment of the risk of using/returning inconsistent data.

On an Internet banking app it would ne a no-go. On a game it may be OK. It depends.

I have used both "read uncommitted" and replication, and have had no issues.

like image 37
Phil Wallach Avatar answered Nov 02 '22 06:11

Phil Wallach