简体   繁体   English

在SQL Server上为rowversion / timestamp列建立索引的后果

[英]Consequences of Indexing the rowversion/timestamp column on SQL Server

Related to my prior question about having a sequence without interim holes (a guarantee that the numbers that are visible to readers are always incrementing) enter link description here I'd like to ask if a solution I devised makes sense. 与我先前的问题有关,即序列中没有临时孔(保证读者可见的数字始终递增),请在此处输入链接描述。我想问一下我设计的解决方案是否有意义。

I created a table with a rowversion column. 我创建了一个带有rowversion列的表。 If I understand this correctly, SQL Server guarantees that the values will be always incrementing. 如果我正确理解这一点,SQL Server保证值将始终递增。 Because this is just a bunch of bytes, queries like WHERE RowVer > 1567 would requires a cast and hence would cause table scan. 因为这只是一堆字节,所以WHERE RowVer > 1567类的WHERE RowVer > 1567将需要WHERE RowVer > 1567 ,因此将导致表扫描。

So I created an index view that would do the cast and I am querying the view. 因此,我创建了一个索引视图来执行强制转换,并且正在查询该视图。 On the surface level it works (the query plan shows index seek) but I am not sure if the always incrementing guarantee still holds true if I go through the index. 从表面上看,它起作用(查询计划显示索引查找),但是我不确定如果通过索引, 始终递增的保证是否仍然成立。 Please help. 请帮忙。

Edit 编辑
It seems to work fine when debugging but inserting to my table block any selects against it. 调试时似乎工作正常,但将任何选择插入到我的表块中。 Need to investigate what kind of locks are being hold. 需要调查持有什么样的锁。

No, it doesn't make sense 不,没有道理

rowversion/timestamp is database unique, not table unique. rowversion/timestamp数据库唯一的,而不是表唯一的。 And it will be changed by UPDATEs to row(s), not just INSERTs. 而且它将被UPDATE更改为行,而不仅仅是INSERT。 Therefore, this is not strictly monotonically increasing as you want. 因此,这并不是您想要的严格单调增加。

Note that the number is not guaranteed to start at any particular value 请注意,该数字不能保证以任何特定值开头

Edit, what is "database unique"? 编辑,什么是“数据库唯一”?

MSDN says for rowversion (timestamp) MSDN表示行版本 (时间戳)

Each database has a counter that is incremented for each insert or update operation that is performed on a table that contains a rowversion column within the database. 每个数据库都有一个计数器,该计数器针对在数据库中包含rowversion列的表上执行的每个插入或更新操作递增。 This counter is the database rowversion 这个计数器是数据库的rowversion

The current value is in @@DBTS 当前值在@@DBTS

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM