简体   繁体   English

rowversion 是用于捕获表数据更改的事务一致值吗

[英]is rowversion a transactionally-consistent value to capture table data changes

If an ETL process attempts to detect data changes on system-versioned tables in SQL Server by including rows as defined by a rowversion column to be within a rowversion "delta window", eg:如果 ETL 进程尝试通过将rowversion列定义的行包含在rowversion “增量窗口”中来检测 SQL 服务器中系统版本表上的数据更改,例如:

where row_version >= @previous_etl_cycle_rowversion
  and row_version < @current_etl_cycle_rowversion

.. and the values for @previous_etl_cycle_rowversion and @current_etl_cycle_rowversion are selected from a logging table whose newest rowversion gets appended to said logging table at the start of each ETL cycle via: .. 和@previous_etl_cycle_rowversion@current_etl_cycle_rowversion的值是从一个日志表rowversion选择的,该表的最新行版本在每个 ETL 周期开始时通过以下方式附加到所述日志表:

insert into etl_cycle_logged_rowversion_marker (cycle_start_row_version)
select @@DBTS

... is it possible that a rowversion of a record falling within a given "delta window" (bounded by the 2 @@DBTS values) could be missed/skipped due to rowversion 's behavior vis-à-vis transactional consistency? ...是否有可能由于rowversion的行为相对于事务一致性而错过/跳过落入给定“增量窗口”(由 2 个@@DBTS值限制)内的记录的rowversion - ie, is it possible that rowversion would be reflected on a basis of "eventual" consistency? - 即,是否可能基于“最终” rowversion来反映行版本?

I'm thinking of a case where say, 1000 records are updated within a single transaction and somehow @@DBTS is "ahead" of the record's committed rowversion yet that specific version of the record is not yet readable...我正在考虑这样一种情况,即在单个事务中更新了 1000 条记录,并且不知何故@@DBTS比记录的已提交rowversion “领先”,但该记录的特定版本尚不可读......

(For the sake of scoping the question, please exclude any cases of deleted records or immediately consecutive updates on a given record within such a large batch transaction.) (为了确定问题的范围,请排除在如此大的批量事务中删除记录或立即连续更新给定记录的任何情况。)

If you make sure to avoid row versioning for the queries that read the change windows you shouldn't miss many rows.如果您确保避免对读取更改 windows 的查询进行行版本控制,您不应该错过很多行。 With READ COMMITTED SNAPSHOT or SNAPSHOT ISOLATION an updated but uncommitted row would not appear in your query.使用 READ COMMITTED SNAPSHOT 或 SNAPSHOT ISOLATION 更新但未提交的行不会出现在您的查询中。

But you can also miss rows that got updated after you query @@dbts.但是您也可能会错过查询@@dbts 后更新的行。 That's not such a big deal usually as they'll be in the next window.这通常没什么大不了的,因为它们将出现在下一个 window 中。 But if you have a row that is constantly updated you may miss it for a long time.但是,如果您有一个不断更新的行,您可能会错过很长时间。

But why use rowversion?但为什么要使用 rowversion? If these are temporal tables you can query the history table directly.如果这些是临时表,您可以直接查询历史表。 And Change Tracking is better and easier than using rowversion, as it tracks deletes and optionally column changes.并且更改跟踪比使用 rowversion 更好、更容易,因为它可以跟踪删除和可选的列更改。 The feature was literally built for to replace the need to do this manually which:该功能实际上是为了取代手动执行此操作的需要:

usually involved a lot of work and frequently involved using a combination of triggers, timestamp columns, new tables to store tracking information, and custom cleanup processes通常涉及大量工作,并且经常涉及使用触发器、时间戳列、存储跟踪信息的新表和自定义清理过程的组合

. .

Under SNAPSHOT isolation, it turns out the proper function to inspect rowversion which will ensure contiguous delta windows while not skipping rowversion values attached to long-running transactions is MIN_ACTIVE_ROWVERSION() rather than @@DBTS .在 SNAPSHOT 隔离下,结果是正确的 function 来检查rowversion ,这将确保连续的增量 windows 而不会跳过附加到长时间运行事务的rowversion值是MIN_ACTIVE_ROWVERSION()而不是@@DBTS

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

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