简体   繁体   English

事务隔离级别如何处理读/写和读/写锁?

[英]How does transaction isolation level work with respect to read/writes and read/write locks?

I understand the dirty read, non-repeatable read and phantom read issue.我了解脏读、不可重复读和幻读问题。

Also I have read about isolation levels: read uncommitted, read committed, repeatable read, serializable.我还阅读了有关隔离级别的信息:未提交读、已提交读、可重复读、可序列化。

I also understand that reading results in a shared lock.我也明白读取会导致共享锁。 To get a shared lock there shouldnt already be an active exlcusive lock.要获得共享锁,不应该已经有一个活动的排他锁。 Where as insert/update/delete results in an exclusive lock.其中插入/更新/删除会导致排他锁。 To get an exclusive lock there shouldn't be any other exclusive or shared lock active.要获得排他锁,不应该有任何其他排他或共享锁处于活动状态。

For each level, none of the articles I have read explain the isolation level concept with respect to:对于每个级别,我读过的文章都没有解释隔离级别的概念:

  1. Whether the level is applicable to a read or write transaction or both.该级别是否适用于读取或写入事务或两者。

  2. Whether reading/writing enforces any read/write locks different to the above explanation读/写是否强制执行与上述解释不同的任何读/写锁

  3. Transaction is a all or nothing concept with regards to write.事务是关于写入的全有或全无的概念。 Whereas is transaction isolation level a concept with regards to reads only?而事务隔离级别是关于只读的概念吗?

If anyone can enlighten regarding these points for each level then it will be very helpful.如果有人可以就每个级别的这些要点进行启发,那将非常有帮助。

You might find these articles by Paul White to be very useful .您可能会发现Paul White 的这些文章非常有用

But in answer to your questions:但在回答您的问题时:

Firstly, Shared vs Exclusive locks define what is allowed to happen concurrently against the lock.首先,共享锁与排他锁定义了允许对锁同时发生的事情。 The isolation level defines how much is locked and how long for.隔离级别定义了锁定的数量和锁定时间。

  1. Isolation level is applicable to both types of transactions.隔离级别适用于这两种类型的事务。 SNAPSHOT in particular has different effects depending whether a write is involved or not. SNAPSHOT尤其具有不同的效果,具体取决于是否涉及写入。
  2. There are also Intent locks, which are equivalent versions of other locks and allow a lock to be escalated from Page or Row Lock to Table/Partition.还有 Intent 锁,它们是其他锁的等效版本,允许将锁从页锁或行锁升级到表/分区。
    You also have Schema Modification locks, which prevent anyone changing the table/column (or index) definitions from underneath you (this is applicable even to NOLOCK ).您还有模式修改锁,它可以防止任何人从您下面更改表/列(或索引)定义(这甚至适用于NOLOCK )。
  3. The isolation level defines how much gets locked, is it a row or a range?隔离级别定义了多少被锁定,是一行还是一个范围? It also indicates what happens to a lock after it has been used.它还指示锁在使用后会发生什么。 Is it held until the end of the transaction, or is released as soon as a commit happens?它是一直保留到事务结束,还是在提交发生后立即释放?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQL:在REPEATABLE READ隔离级别,是否在事务结束时持有UPDATE锁? - SQL: at REPEATABLE READ isolation level, are UPDATE locks held to the end of the transaction? 事务级别之间的差异:读可写和可隔离级别 - Differences between TRANSACTION's levels: READ WRITE and ISOLATION LEVEL SERIALIZABLE SQL隔离级别,读写锁 - Sql isolation levels, Read and Write locks TRANSACTION ISOLATION LEVEL SERIALIZABLE是否创建READ锁定 - Does TRANSACTION ISOLATIoN LEVEL SERIALIZABLE create READ lock 如何将事务隔离级别设置为用户的默认未提交读 - How to set transaction isolation level as read uncommitted as default for users “SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED”和观点 - “SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED” and views 具有READ UNCOMMITTED隔离级别的查询是否可能导致对其访问的表进行锁定? - Could an query with READ UNCOMMITTED isolation level cause locks on the tables it access? 是否可以在数据库级别设置无锁或“事务隔离级别未提交读”? - Is it possible to set no lock or TRANSACTION ISOLATION LEVEL READ UNCOMMITTED at database level? PostgreSQL是如何实现REPEATABLE_READ隔离级别的? - How does PostgreSQL implement the REPEATABLE_READ isolation level? 事务隔离级别大量写入 - Transaction Isolation level Massive number of Writes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM