English 中文(简体)
READ UNCOMMITTED/NOLOCK 在这种情况下是否安全?
原标题:Is READ UNCOMMITTED / NOLOCK safe in this situation?

我知道,光辉的孤立会解决这个问题,但我很想知道,在这种具体情况下,诺琴科是否安全,以便我能够避免间接费用。

我有一个这样的表格:

drop table Data

create table Data
(
    Id BIGINT NOT NULL,
    Date BIGINT NOT NULL,
    Value BIGINT,
    constraint Cx primary key (Date, Id)
)

create nonclustered index Ix on Data (Id, Date)

表格没有任何更新。 删除可能发生,但永远不应与选任考试委员会竞争,因为选举会影响到另一个较老的阶段。 插入是固定的,页数与(Id, 日期)指数相距甚远。

我在标准INSERT与专业考试委员会之间陷入僵局。

select top 1 Date, Value from Data where Id = @p0 order by Date desc

由于INSERT在Cx(Date, Id; Value)和随后的Ix(Id, 日期)上获得一个锁,但SélectT在Ix(Id, 日期)和随后Cx(Date, Id; Value)上获得一个锁。 这是因为选任考试委员会首先在Ix上进行,然后加入到Cx上。

取消分组和非分组指数将打破这一循环,但这不是一种可以接受的解决办法,因为它将与其他(更复杂的)选举制度一起实行周期。

如果我向选任考试委员会增加NLOCK,那么这个案件是否是错误的? 能够返回:

  1. More than one row, even though I asked for TOP 1?
  2. No rows, even though one exists and has been committed?
  3. Worst of all, a row that doesn t satisfy the WHERE clause?

I ve在网上做了许多读物,但只复制了超量或低度异常情况一,见,has a post about using NOLOCK that produced a good discussion. 我对Rick Townsend的评论特别感兴趣:

Secondly, if you read dirty data, the risk you run is of reading the entirely wrong row. For example, if your select reads an index to find your row, then the update changes the location of the rows (e.g.: due to a page split or an update to the clustered index), when your select goes to read the actual data row, it s either no longer there, or a different row altogether!

是否只有插入,而且没有更新? 如果是的话,那么我甚至想在一张只插入的桌子上就可能会有危险。


最新情况:

Im试图标出how snapshot separateworking。 似乎以增长为基础,交易读了表格(没有共同点!),发现它们感兴趣的是行文,然后看它们是否需要从温德布的版本库获得旧的行文。

但就我的情况而言,一行不会超过一个版本,因此该版本的储存似乎毫无意义。 如果发现该行没有共用锁,那么它如何不同于仅仅使用NOLOCK?

最佳回答

采用NOLOCK或READ UNCOMMITTED意味着你放弃任何一致性保障。 期间

如果您需要一致性,则不作ir。 您的全部解释依据的是无证行为,今后释放情况会发生变化,更糟糕的是,根据具体准入计划你预计会询问。 彩虹优化器可自由选择其认为合适的任何计划,任何假设均可在生产过程中打破。 因此,回到正轨:如果你不准备面对后果,就不作ir。

如果适用,不清楚你试图用你的询问/表实现什么,但或许本条可能有助于:。 将表格作为Quues

Updated
Where a NOLOCK read would read an inconsistent state (eg. read a stale non-clustered index key and chase it to a missing row in the clustered index) a snapshot read would find the missing row in the version store. For stable data, a snapshot read is identical with a nolock read. The magic of the version store comes into play whenever data is changed (uncommitted updates), because the snapshot read goes into the version store and finds the old values (stable and consistent) where the nolock read would go haywire and chase pointers into lala land.

问题回答

在该案中,你应当与挪威人民党安全。 另一种想法:在Ix指数中增加价值一栏,应消除Cx上的追求。

create nonclustered index Ix on Data (Id, Date) include (Value)




相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签