rowversion/timestamp 是否会显着影响性能?
我计划添加到数据库行版本中的大多数表以跟踪这些表中的更改。我知道添加它会影响查询的性能。
有谁知道它是否会稍微影响性能(慢几个百分点),或者我不应该向许多表添加行版本,因为它会使数据库慢得多。
I plan to add to most tables in my DB rowversion to track changes in those tables. I know that adding it will affect performance of queries.
Does anyone knows if it affect performance a little bit (few percent slower) or I should not to add rowversion to many tables, because it make DB much slower.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅添加 rowversion/timestamp 列的性能差异在于您的行现在宽了 8 个字节。
当您开始实际使用它们时,实际的性能差异就会出现。但正如我在回答类似问题时指出的那样: RowVersion 和 Performance
因此,仅检查行以确保自应用程序上次读取以来未更新该行时的性能将是微不足道的性能差异(无论如何它都必须读取该行来更新它)。
但是,当尝试使用 rowversion/timestamp 列作为获取自上次检查以来所有更新项目的方法时,性能将非常差。
Performance difference of just adding a rowversion/timestamp column is that your rows are now 8 bytes wider.
The actual performance difference comes when you start actually using them for something. But as I point out in my answer to a similar question: RowVersion and Performance
So performance when just checking the row to make sure that it's not been updated since the application last read is going to be trivial performance difference (it has to read the row to update it anyway).
But performance when trying to use a rowversion/timestamp column as a means to get all updated items since last time we checked is going to be very poor.
我感兴趣的是,我们使用的版本控制是由触发器填充的,所以当我看到这个时,我必须了解更多有关性能的信息。因此,我开始设置一个测试场景。我想将我们当前使用的(触发器)与 rowversion 列与另一个没有版本控制的表进行比较。
毫不奇怪,触发器的性能肯定比 rowversion 差。 Rowversion 本质上与没有版本控制的表上的更新时间相同;一些运行显示没有版本控制的表更快,但大约相同的 # show rowversion 更快。对我来说,这意味着使用它的开销非常小,随机 CPU 和磁盘 I/O 隐藏了真正的性能差异。
Of interest to me, the versioning we use is populated by trigger, so when I saw this I had to learn more about the performance. So, I set about setting up a test scenario. I wanted to compare what we currently use (trigger) versus a rowversion column versus another table with no versioning.
Not surprisingly, the trigger definitely performed worse than the rowversion. Rowversion was essentially identical to the update time on a table with no versioning; Some runs show the table with no versioning is faster, but about an equal # show rowversion to be faster. To me this means that there is so little overhead in using it, that random CPU and disk I/O hide the real performance difference.