简体   繁体   English

可序列化的事务隔离锁

[英]serializable transaction isolation lock

I have set a serializable transaction isolation lock for a transaction.But i am observing some results which are not expected. 我为事务设置了可序列化的事务隔离锁。但是我正在观察一些不期望的结果。

My query is 我的疑问是

update tabl1 set col2 = 10 where col1 > 10 and col1 < 20

Here col1 is primary key.Here rows with col1 having value 10,11,12....19,20 are locked for update/insert. 这里col1是主键。具有值10,11,12 .... 19,20的col1的行被锁定以进行更新/插入。 In where condition i have given conditions as col1>10 and col1<20 but still rows having col1=10 and col1=20 gets locked. 在条件为i的条件下,col1> 10且col1 <20,但仍然有col1 = 10且col1 = 20的行被锁定。

If i give 如果我给

update tabl1 set col2 = 10 where col1 => 10 and col1 <= 20

then rows with col2 having values from 9 to 21 gets locked.So why col1 having 9 and 21 gets locked here? 然后col2值为9到21的行被锁定。那么为什么col1有9和21被锁定在这里?

For the below query full table gets locked.Here col3 is a non-primary column.Can't i set lock if the column in where condition is not a primary key? 对于下面的查询,全表被锁定。这里col3是非主列。如果where条件中的列不是主键,我不能设置锁定吗?

update tabl1 set col2 = 10 where col3 > 10 and col3 < 20

For key range locking SQL Server must use an index to satisfy the range condition so regarding your last query you would need an index on col3 (and possibly query hints to force its use if the plan does not use it) 对于键范围锁定,SQL Server必须使用索引来满足范围条件,因此关于上一个查询,您需要col3上的索引(如果计划不使用,可能会查询提示以强制使用它)

Also it does not just lock the specific range in your WHERE clause. 此外,它不仅仅锁定WHERE子句中的特定范围。 It locks keys. 它锁定钥匙。 A range lock on a key protects the range from that key downwards to the next key so the exact range that will be blocked depends upon what keys exist in the index. 密钥上的范围锁定保护从该密钥向下到下一个密钥的范围,因此将被阻止的确切范围取决于索引中存在哪些密钥。

More details/links are in my answer here 更多细节/链接在我的答案中

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

相关问题 TRANSACTION ISOLATION LEVEL SERIALIZABLE是否创建READ锁定 - Does TRANSACTION ISOLATIoN LEVEL SERIALIZABLE create READ lock 具有多个语句的可序列化事务隔离 - Serializable transaction isolation with multiple statements 具有可序列化隔离级别的事务中的死锁 - Deadlock in transaction with isolation level serializable 归因于隔离级别可序列化的SQL事务失败的一般处理 - Generalized handling of SQL transaction failures due to isolation level serializable 事务级别之间的差异:读可写和可隔离级别 - Differences between TRANSACTION's levels: READ WRITE and ISOLATION LEVEL SERIALIZABLE 是否可以在数据库级别设置无锁或“事务隔离级别未提交读”? - Is it possible to set no lock or TRANSACTION ISOLATION LEVEL READ UNCOMMITTED at database level? SQL事务隔离级别可序列化与在开发与生产中提交的读取 - SQL Transaction Isolation Level Serializable vs Read Committed in Dev vs Production 可序列化事务隔离级别是否保证非数据库代码也被序列化? - Do serializable transaction isolation level guarantee that non-DB code is also serialised? Redshift:表上的可序列化隔离冲突 - Redshift: Serializable isolation violation on table 如何检测可序列化的隔离违规? - How are serializable isolation violations detected?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM