- 论坛徽章:
- 0
|
在昨天的回贴中提到大的update一定要用小批量(small batch size),感觉有必要专门发一贴。
Update用Small batch size对高并发的系统相当关键;否则,会造成不良后果,比如:
1、填满logsegment
比如你的logsegment只有2G,需要更改的数据集有10G。即便你更改的数据集没有日志段大,但如果一直hold住syslogs,和其他事务一起也有可能填满日志段,这是为什么后面的例子强调index scan也很关键。
2、阻塞其他进程。如果阻塞发生在关键表上,系统将不可用。
在缺省设置下,更改超过200 rows or pages,行级/页级锁就会升级成表锁而阻塞其他进程读写,详细信息请看lock promotion HWM。
http://infocenter.sybase.com/hel ... /locking/X20061.htm
3、导致out of locks,因为这个进程hold住了locks,其他进程在同一表上的锁不能提升到表锁。
To avoid the overhead of managing hundreds of locks on a table, Adaptive Server uses a lock promotion threshold setting. Once a scan
of a table accumulates more page or row locks than allowed by the lock promotion threshold, Adaptive Server tries to issue a table lock. If it succeeds, the page or row locks are no longer necessary and are released.
When lock promotion is denied due to conflicting locks, a process can accumulate page or row locks in excess of the lock promotion threshold and
may exhaust all available locks in Adaptive Server.
4、导致死锁
5、降低复制系统性能
下面是使用的例子。
1、bcp in
bcp ...in ..... -b 2000
2、update 最好保证你的update使用 index scan(当然如果涉及80%以上的记录要用表扫描, optimizer considers table scan when 40% of the records are involved)
declare @errorStatus int, @rowsProcessed int
set rowcount 2000
select @rowsProcessed = 1
while (@rowsProcessed != 0)
begin
begin tran
update ...
from ...
where ...
select @rowsProcessed = @@rowcount, @errorStatus = @@error
if (@errorStatus != 0)
begin
raiserror ....
rollback tran
return -1
end
commit tran
end
set rowcount 0
|
|