gpt4 book ai didi

sql-server - 更新具有相同值的表会增加事务日志文件的大小吗?

转载 作者:行者123 更新时间:2023-12-04 00:48:32 25 4
gpt4 key购买 nike

还是事务日志仅包含差异?

这两个脚本之间的日志文件是否存在差异:

DECLARE @f1 INT ,
@f2 INT

CREATE TABLE #t ( int F1, int f2 )
UPDATE #t
SET f1 = ISNULL(@f1, f1) ,
f2 = ISNULL(@f2, f2)

--or
IF @f1 IS NOT NULL
UPDATE #t
SET f1 = ISNULL(@f1, f1)

IF @f2 IS NOT NULL
UPDATE #t
SET f2 = ISNULL(@f2, f2)

最佳答案

仅当更新是集群 key 的一部分时。

看看这个 article标题为“非更新更新的影响”,讨论了这个问题。

Summary

SQL Server contains a number of optimisations to avoid unnecessary logging or page flushing when processing an UPDATE operation that will not result in any change to the persistent database.

  • Non-updating updates to a clustered table generally avoid extra logging and page flushing, unless a column that forms (part of) the cluster key is affected by the update operation.
  • If any part of the cluster key is ‘updated’ to the same value, the operation is logged as if data had changed, and the affected pages are marked as dirty in the buffer pool. This is a consequence of the conversion of the UPDATE to a delete-then-insert operation.
  • Heap tables behave the same as clustered tables, except they do not have a cluster key to cause any extra logging or page flushing. This remains the case even where a non-clustered primary key exists on the heap. Non-updating updates to a heap therefore generally avoid the extra logging and flushing (but see below).
  • Both heaps and clustered tables will suffer the extra logging and flushing for any row where a LOB column containing more than 8000 bytes of data is updated to the same value using any syntax other than ‘SET column_name = column_name’.
    • Simply enabling either type of row versioning isolation level on a database always causes the extra logging and flushing. This occurs regardless of the isolation level in effect for the update transaction.

关于sql-server - 更新具有相同值的表会增加事务日志文件的大小吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24994843/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com