Gry*_*nix 5 sql-server-2008 locking blocking
运行 SQL Server 2008;Mgmt Studio 2008。我正在处理我们为 MS CRM 4.0 实施创建的 MS SQL 作业。对于熟悉 CRM 的任何人来说,这项工作每晚清除 aSyncOperationBase 表以节省数据库大小。这是工作代码:
Begin Transaction T1
Declare @p30Days as DateTime
Declare @p3Years as DateTime
Set @p30Days = DateAdd(d, -30, GetDate())
Set @p3Years = DateAdd(d, -1095, GetDate())
update AsyncOperationBase
set deletionstatecode=2
where deletionstatecode = 0 and
statecode = 3 and
completedon is not null and
completedon < @p30Days
and OperationType <> 10
update AsyncOperationBase
set deletionstatecode=2
where deletionstatecode = 0 and
statecode = 3 and
completedon is not null and
completedon < @p3Years
and OperationType = 10
delete from workflowlogbase
where AsyncOperationid in (select AsyncOperationid from AsyncOperationBase where deletionstatecode=2)
update DuplicateRecordBase
set DeletionStateCode = 2
where asyncoperationid in
(select DuplicateRecordBase.asyncoperationid
from DuplicateRecordBase
left join asyncoperationbase on (DuplicateRecordBase.asyncoperationid=asyncoperationbase.asyncoperationid and
asyncoperationbase.deletionstatecode = 0)
where asyncoperationbase.asyncoperationid is null)
update BulkDeleteOperationBase
set DeletionStateCode = 2
where asyncoperationid in
(select BulkDeleteOperationBase.asyncoperationid
from BulkDeleteOperationBase
left join asyncoperationbase on (BulkDeleteOperationBase.asyncoperationid=asyncoperationbase.asyncoperationid and
asyncoperationbase.deletionstatecode = 0)
where asyncoperationbase.asyncoperationid is null)
delete from asyncoperationbase
where deletionstatecode = 2 and
completedon < @p30Days
commit transaction T1
Run Code Online (Sandbox Code Playgroud)
我最近注意到的问题是,这个工作从凌晨 4 点开始,运行了至少 4 个小时并且没有完成。当我尝试针对 1 条记录运行第一个更新语句时,SQL 进程没有完成并成为进程链中的主要阻塞器。有没有人对可能导致这种行为的原因有任何想法?我查看了活动监视器,没有其他进程导致重大阻塞。
小智 2
检查这些语句是否相互阻塞。因为它们属于同一笔交易。他们是否以某种方式锁定冲突的行?
update AsyncOperationBase
set deletionstatecode=2
where deletionstatecode = 0 and
statecode = 3 and
completedon is not null and
completedon < @p30Days
and OperationType <> 10
update AsyncOperationBase
set deletionstatecode=2
where deletionstatecode = 0 and
statecode = 3 and
completedon is not null and
completedon < @p3Years
and OperationType = 10
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2024 次 |
最近记录: |