[英]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.