Microsoft Dynamics CRM 2016 - 两个MSCRM数据库具有相同的配置 - 一个具有良好的性能,而另一个具有低性能

时间:2017-02-23 13:57:09

标签: sql dynamics-crm

突然,在Dynamics MSCRM数据库中运行的查询的运行时间迅速增加。索引或之前存在的任何其他配置都没有变化。查询过去需要花费30秒才能运行,现在它需要超过4分钟。

查询:

SELECT 
  Filterederi_salesengagement.eri_salesengagementnumber ,
  Filterederi_salesengagement.eri_name ,
  Filterederi_salesengagement.eri_salestrackname ,
  Filterederi_salesengagement.eri_salesstagename ,
  Filterederi_salesengagement.eri_statusofbusinessname ,
  Filterederi_salesengagement.eri_statusofsalesprocessname ,
  Filterederi_salesengagement.eri_totaldealvalue_base 
FROM 
  Filterederi_salesengagement
WHERE 
  Filterederi_salesengagement.eri_statusofbusinessname='Ongoin‌​g'

1 个答案:

答案 0 :(得分:0)

如果AsyncOperationBase表变得太大,性能会降低。尝试在Organization_MSCRM DB上运行以下脚本。

IF EXISTS (SELECT name from sys.indexes
WHERE name = N'CRM_AsyncOperation_CleanupCompleted')
      DROP Index AsyncOperationBase.CRM_AsyncOperation_CleanupCompleted
GO
CREATE NONCLUSTERED INDEX CRM_AsyncOperation_CleanupCompleted
ON [dbo].[AsyncOperationBase] ([StatusCode],[StateCode],[OperationType])
GO

while(1=1)
begin
declare @DeleteRowCount int = 10000
declare @rowsAffected int
declare @DeletedAsyncRowsTable table (AsyncOperationId uniqueidentifier not null primary key)
insert into @DeletedAsyncRowsTable(AsyncOperationId)
Select top (@DeleteRowCount) AsyncOperationId from AsyncOperationBase
where 
  OperationType in (1, 9, 12, 25, 27, 10) 
  AND StateCode = 3 
  AND StatusCode in (30, 32)

 select @rowsAffected = @@rowcount 
 delete poa from PrincipalObjectAccess poa 
   join WorkflowLogBase wlb on
    poa.ObjectId = wlb.WorkflowLogId
   join @DeletedAsyncRowsTable dart on
    wlb.AsyncOperationId = dart.AsyncOperationId
delete WorkflowLogBase from WorkflowLogBase W, @DeletedAsyncRowsTable d
where 
  W.AsyncOperationId = d.AsyncOperationId             
 delete BulkDeleteFailureBase From BulkDeleteFailureBase B, @DeletedAsyncRowsTable d
where 
  B.AsyncOperationId = d.AsyncOperationId
delete BulkDeleteOperationBase From BulkDeleteOperationBase O, @DeletedAsyncRowsTable d
where 
  O.AsyncOperationId = d.AsyncOperationId
delete WorkflowWaitSubscriptionBase from WorkflowWaitSubscriptionBase WS, @DeletedAsyncRowsTable d
where 
  WS.AsyncOperationId = d.AsyncOperationID 
 delete AsyncOperationBase From AsyncOperationBase A, @DeletedAsyncRowsTable d
where 
  A.AsyncOperationId = d.AsyncOperationId
/*If not calling from a SQL job, use the WAITFOR DELAY*/
if(@DeleteRowCount > @rowsAffected)
  return
else
  WAITFOR DELAY '00:00:02.000'
end