您的位置:首页 > 数据库 > MySQL

MySQL 事务隔离级别相关官方文档翻译

2018-01-22 11:24 260 查看
来自MySQL官方文档: MySQL 5.7 Reference Manual :: MySQL Glossary

MySQL 5.7 Reference Manual :: MySQL Glossary

1.isolation level

One of the foundations of database processing. Isolation is the I in the acronym ACID; the isolation level is the setting that fine-tunes the balance between performance and reliability, consistency, and reproducibility of results when multiple transactions are making changes and performing queries at the same time.

From highest amount of consistency and protection to the least, the isolation levels supported by InnoDB are: SERIALIZABLE, REPEATABLE READ, READ COMMITTED, and READ UNCOMMITTED.

With InnoDB tables, many users can keep the default isolation level (REPEATABLE READ) for all operations. Expert users might choose the READ COMMITTED level as they push the boundaries of scalability with OLTP processing, or during data warehousing operations where minor inconsistencies do not affect the aggregate results of large amounts of data. The levels on the edges (SERIALIZABLE and READ UNCOMMITTED) change the processing behavior to such an extent that they are rarely used.

隔离级别

数据库处理的基础之一。隔离是ACID里的I;隔离级别是在多个事务同时进行更改和执行查询时,对性能与可靠性、一致性和可再现性之间的平衡进行微调的设置。

从一致性和保护的数量从高到底,InnoDB所支持的隔离级别是:SERIALIZABLE, REPEATABLE READ, READ COMMITTED, and READ UNCOMMITTED.

使用InnoDB表,许多用户可以为所有操作保留默认的隔离级别(REPEATABLE READ)。专家用户可能会选择READ COMMITTED的级别,因为他们使用OLTP处理推进可伸缩性的边界,或者在数据仓库操作中,小的不一致性不会影响大量数据的聚合结果。边缘的级别(SERIALIZABLE and READ UNCOMMITTED)将处理行为更改为很少使用的程度。

2.read phenomena

Phenomena such as dirty reads, non-repeatable reads, and phantom reads which can occur when a transaction reads data that another transaction has modified.

读取现象

当事务读取另一个事务已修改的数据时,脏读、不可重复读和虚读等现象会发生。

3.READ UNCOMMITTED

The isolation level that provides the least amount of protection between transactions. Queries employ a locking strategy that allows them to proceed in situations where they would normally wait for another transaction. However, this extra performance comes at the cost of less reliable results, including data that has been changed by other transactions and not committed yet (known as dirty read). Use this isolation level with great caution, and be aware that the results might not be consistent or reproducible, depending on what other transactions are doing at the same time. Typically, transactions with this isolation level only do queries, not insert, update, or delete operations.

读未提交

隔离级别,在事务之间提供最少的保护。查询使用一个锁定策略,允许它们在通常等待另一个事务的情况下进行处理。但是,这种额外的性能是以不可靠的结果为代价的,包括其他事务已经更改的数据,并且还没有提交(被称为“脏读”)。使用这个隔离级别非常谨慎,并且要注意,结果可能不一致或可重现,这取决于其他事务在同一时间做什么。通常,具有这种隔离级别的事务只执行查询,而不是插入、更新或删除操作。

4.dirty read

An operation that retrieves unreliable data, data that was updated by another transaction but not yet committed. It is only possible with the isolation level known as read uncommitted.

This kind of operation does not adhere to the ACID principle of database design. It is considered very risky, because the data could be rolled back, or updated further before being committed; then, the transaction doing the dirty read would be using data that was never confirmed as accurate.

Its opposite is consistent read, where InnoDB ensures that a transaction does not read information updated by another transaction, even if the other transaction commits in the meantime.

脏读

一种检索不可靠数据的操作,由另一个事务更新但尚未提交的数据。只有在被称为READ UNCOMMITTED的隔离级别才有可能。

这种操作不符合数据库设计的ACID原则。它被认为是非常危险的,因为数据可以回滚,或者在提交之前进行进一步的更新;然后,执行脏读操作的事务将使用从未被确认为准确的数据。

它的反面是一致的读取,InnoDB确保事务不会读取由另一个事务更新的信息,即使在此
a9c2
期间另一个事务提交。

5.READ COMMITTED

An isolation level that uses a locking strategy that relaxes some of the protection between transactions, in the interest of performance. Transactions cannot see uncommitted data from other transactions, but they can see data that is committed by another transaction after the current transaction started. Thus, a transaction never sees any bad data, but the data that it does see may depend to some extent on the timing of other transactions.

When a transaction with this isolation level performs UPDATE … WHERE or DELETE … WHERE operations, other transactions might have to wait. The transaction can perform SELECT … FOR UPDATE, and LOCK IN SHARE MODE operations without making other transactions wait.

读已提交

一个隔离级别,它使用锁定策略来放松事务之间的一些保护,以达到性能的目的。事务不能从其他事务中看到未提交的数据,但是它们可以看到在当前事务启动后由另一个事务提交的数据。因此,事务永远不会看到任何糟糕的数据,但是它所看到的数据可能在一定程度上取决于其他事务的时间。

当具有此隔离级别的事务执行更新时。,或删除…在操作中,其他事务可能需要等待。事务可以执行SELECT。用于更新,并锁住共享模式操作,而不需要其他事务等待。

6.non-repeatable read

The situation when a query retrieves data, and a later query within the same transaction retrieves what should be the same data, but the queries return different results (changed by another transaction committing in the meantime).

This kind of operation goes against the ACID principle of database design. Within a transaction, data should be consistent, with predictable and stable relationships.

Among different isolation levels, non-repeatable reads are prevented by the serializable read and repeatable read levels, and allowed by the consistent read, and read uncommitted levels.

不可重复读

当查询检索数据时,同一事务中稍后的查询将检索相同的数据,但是查询返回不同的结果(由另一个事务在此期间提交)。

这种操作违背了数据库设计的ACID原则。在事务中,数据应该是一致的,具有可预测和稳定的关系。

在不同的隔离级别中,可序列化的读和可重复的读级别阻止不可重复的读,并且可以通consistent read和READ UNCOMMITTED的级别。

7.REPEATABLE READ

The default isolation level for InnoDB. It prevents any rows that are queried from being changed by other transactions, thus blocking non-repeatable reads but not phantom reads. It uses a moderately strict locking strategy so that all queries within a transaction see data from the same snapshot, that is, the data as it was at the time the transaction started.

When a transaction with this isolation level performs UPDATE … WHERE, DELETE … WHERE, SELECT … FOR UPDATE, and LOCK IN SHARE MODE operations, other transactions might have to wait.

可重复读

InnoDB的默认隔离级别。它防止任何被查询的行被其他事务改变,因此阻塞了不可重复读,但是幻读不能。它使用一种适度严格的锁定策略,使事务中的所有查询都能从同一快照中查看数据,也就是说,数据与事务启动时的数据相同。

当具有此隔离级别的事务执行UPDATE… WHERE,DELETE … WHERE,SELECT … FOR UPDATE以及LOCK IN SHARE MODE模式运行时,其他事务可能需要等待。

8.phantom

A row that appears in the result set of a query, but not in the result set of an earlier query. For example, if a query is run twice within a transaction, and in the meantime, another transaction commits after inserting a new row or updating a row so that it matches the WHERE clause of the query.

This occurrence is known as a phantom read. It is harder to guard against than a non-repeatable read, because locking all the rows from the first query result set does not prevent the changes that cause the phantom to appear.

Among different isolation levels, phantom reads are prevented by the serializable read level, and allowed by the repeatable read, consistent read, and read uncommitted levels.

幻影

在查询一组结果中出现的行,但不是在之前查询的一组结果中出现的行。例如,如果一个查询在一个事务中运行两次,并且在此期间,另一个事务在插入新行或更新行之后提交,以便它与查询的WHERE子句相匹配。

这种现象被称为“幻读”。与不可重复的读取相比,它更难防范,因为从第一个查询结果集中锁定所有行不会阻止导致幻像出现的更改。

在不同的隔离级别中,可以通过SERIALIZABLE的读取级别阻止幻读,并允许可重复读取、一致读取和读取未提交的级别。

9.consistent read

A read operation that uses snapshot information to present query results based on a point in time, regardless of changes performed by other transactions running at the same time.

一个使用快照信息并根据时间点来显示查询结果的读取操作,而不考虑其他同时运行的事务所执行的更改。

If queried data has been changed by another transaction, the original data is reconstructed based on the contents of the undo log.

如果查询的数据被另一个事务更改,那么原始数据将根据undo log的内容进行重建。

This technique avoids some of the locking issues that can reduce concurrency by forcing transactions to wait for other transactions to finish.

这种技术可以避免一些锁定问题,通过强制事务等待其他事务完成,会减少并发性。

With REPEATABLE READ isolation level, the snapshot is based on the time when the first read operation is performed.

对于可重复读取隔离级别,快照基于第一次读取操作执行时的时间。

With READ COMMITTED isolation level, the snapshot is reset to the time of each consistent read operation.

通过读取已提交的隔离级别,快照将被重置到每个一致读取操作的时间。

Consistent read is the default mode in which InnoDB processes SELECT statements in READ COMMITTED and REPEATABLE READ isolation levels.

consistent read是InnoDB在READ COMMITTED 和 REPEATABLE READ隔离级别的过程中选择语句的默认模式。

Because a consistent read does not set any locks on the tables it accesses, other sessions are free to modify those tables while a consistent read is being performed on the table.

因为consistent read不会在它访问的表上设置任何锁,其他会话可以自由地修改这些表,虽然这些表上执行了consistent read操作。

10.SERIALIZABLE

The isolation level that uses the most conservative locking strategy, to prevent any other transactions from inserting or changing data that was read by this transaction, until it is finished. This way, the same query can be run over and over within a transaction, and be certain to retrieve the same set of results each time. Any attempt to change data that was committed by another transaction since the start of the current transaction, cause the current transaction to wait.

This is the default isolation level specified by the SQL standard. In practice, this degree of strictness is rarely needed, so the default isolation level for InnoDB is the next most strict, REPEATABLE READ.

可串行化

使用最保守的锁定策略的隔离级别,以防止任何其他事务插入或更改由该事务读取的数据,直到完成。通过这种方式,相同的查询可以在事务中一次又一次地运行,并且可以确保每次都检索相同的结果集。任何试图更改自当前事务启动以来由另一个事务提交的数据的尝试,导致当前事务等待。

这是SQL标准指定的默认隔离级别。在实践中,这种严格程度是不需要的,因此InnoDB的默认隔离级别是下一个最严格、可重复的读取。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: