我有这段代码,当尝试从Azure S2 MSSQL DB上的Acumatica中的一个特定用户执行网格超时时,该网格超时。
使用Azure S3 MSSQL DB不会超时。
public class CTInquiriesCollecteur : PXGraph<CTInquiriesCollecteur>
{
[PXFilterable]
public PXSelectJoin<POOrder,
InnerJoin<Contact,
On<Contact.bAccountID, Equal<POOrder.vendorID>>,
InnerJoin<CROpportunity,
On<CROpportunity.opportunityID, Equal<POOrderExt.usrBSD>,Or<CROpportunityExt.usrEBDR,Equal<POOrderExt.usrBRD>>>>>,
Where<Contact.userID, Equal<Current<AccessInfo.userID>>>> poCollecteur;
}
}
它与其他用户一起使用(但返回的记录少于使它崩溃的记录) 当我使用SQL Manager尝试查询时,它可以正常工作并返回我想要的1743行:
Select * from POOrder inner Join Contact on Contact.BaCcountID=POOrder.VendorID Inner join CROpportunity
on ( CROpportunity.opportunityID=POOrder.usrBSD or CROpportunity.opportunityID=POOrder.UsrBRD)
Where poorder.CompanyID=5 and Contact.companyID=5 and CROpportunity.CompanyID=5 and Contact.contactID=12688
此查询返回所有行(不对contactID进行过滤)可以正常工作(但返回的行数比对contactID进行过滤的行数多):
public class CTInquiriesEmployes : PXGraph<CTInquiriesEmployes>
{
[PXFilterable]
public PXSelectReadonly2<POOrder, InnerJoin<CROpportunity,
On<CROpportunity.opportunityID, Equal<POOrderExt.usrBSD>,Or<CROpportunityExt.usrEBDR,Equal<POOrderExt.usrBRD>>>>> po;
}
您是否有关于如何优化此查询的任何提示,这样我就不需要在Azure上使用S3 DB并且可以坚持使用S2?
编辑:
我查看了查询计划,看来这是代码示例生成的请求,并且该请求使我的数据库超时:
(@P0 uniqueidentifier,@P1 char(1))SELECT TOP (20) [POOrder].[BranchID], [POOrder].[OrderType], [POOrder].[OrderNbr], [POOrder].[VendorID], [POOrder].[VendorLocationID], [POOrder].[OrderDate], [POOrder].[ExpectedDate], [POOrder].[ExpirationDate], [POOrder].[Status], [POOrder].[Hold], [POOrder].[Approved], [POOrder].[Cancelled], [POOrder].[Receipt], [POOrder].[IsTaxValid], [POOrder].[IsOpenTaxValid], [POOrder].[NoteID], (SELECT TOP (1) [Note_s18].[NoteText] FROM [dbo].[Note] [Note_s18] WHERE [Note_s18].CompanyID IN (1, 5) AND 2 = SUBSTRING([Note_s18].CompanyMask, 2, 1) & 2 AND [Note_s18].[NoteId] = [POOrder].[NoteID]), (SELECT TOP (1) COUNT(*) FROM [dbo].[NoteDoc] [NoteDoc_s20] WHERE [NoteDoc_s20].CompanyID IN (1, 5) AND 2 = SUBSTRING([NoteDoc_s20].CompanyMask, 2, 1) & 2 AND [NoteDoc_s20].[NoteId] = [POOrder].[NoteID]), NULL, [POOrder].[CuryID], [POOrder].[CuryInfoID], [POOrder].[LineCntr], [POOrder].[VendorRefNbr], [POOrder].[CuryOrderTotal], [POOrder].[OrderTotal], [POOrder].[CuryControlTotal], [POOrder].[ControlTotal], [POOrder].[OrderQty], [POOrder].[CuryLineTotal], [POOrder].[LineTotal], [POOrder].[DiscTot], [POOrder].[CuryDiscTot], [POOrder].[CuryTaxTotal], [POOrder].[TaxTotal], [POOrder].[CuryVatExemptTotal], [POOrder].[VatExemptTotal], [POOrder].[CuryVatTaxableTotal], [POOrder].[VatTaxableTotal], [POOrder].[TaxZoneID], [POOrder].[TermsID], [POOrder].[RemitAddressID], [POOrder].[RemitContactID], [POOrder].[SOOrderType], [POOrder].[SOOrderNbr], [POOrder].[BLType], [POOrder].[BLOrderNbr], [POOrder].[RQReqNbr], [POOrder].[OrderDesc], [POOrder].[tstamp], [POOrder].[CreatedByID], [POOrder].[CreatedByScreenID], [POOrder].[CreatedDateTime], [POOrder].[LastModifiedByID], [POOrder].[LastModifiedByScreenID], [POOrder].[LastModifiedDateTime], [POOrder].[ShipDestType], [POOrder].[SiteID], [POOrder].[ShipToBAccountID], [POOrder].[ShipToLocationID], [POOrder].[ShipAddressID], [POOrder].[ShipContactID], [POOrder].[CuryOpenOrderTotal], [POOrder].[OpenOrderTotal], [POOrder].[CuryOpenLineTotal], [POOrder].[OpenLineTotal], [POOrder].[CuryOpenTaxTotal], [POOrder].[OpenTaxTotal], [POOrder].[OpenOrderQty], [POOrder].[EmployeeID], [POOrder].[OwnerWorkgroupID], [POOrder].[DontPrint], [POOrder].[Printed], [POOrder].[DontEmail], [POOrder].[Emailed], [POOrder].[FOBPoint], [POOrder].[ShipVia], [POOrder].[OrderWeight], [POOrder].[OrderVolume], [POOrder].[PrepaymentDocType], [POOrder].[PrepaymentRefNbr], [POOrder].[UsrObservation], [POOrder].[UsrBSD], [POOrder].[UsrBRD], [POOrder].[UsrTypePO], [POOrder].[UsrPAV], [POOrder].[UsrLicenseExport], [POOrder].[UsrCodeMouvement], [POOrder].[UsrNumeroContainer], [POOrder].[UsrDepartBateauDate], [POOrder].[UsrFiliere], [Contact].[DisplayName], [Contact].[ContactID], [Contact].[RevisionID], [Contact].[DefAddressID], [Contact].[Title], [Contact].[FirstName], [Contact].[MidName], [Contact].[LastName], [Contact].[Salutation], [Contact].[BAccountID], [Contact].[FullName], [Contact].[ParentBAccountID], [Contact].[EMail], [Contact].[WebSite], [Contact].[Fax], [Contact].[FaxType], [Contact].[Phone1], [Contact].[Phone1Type], [Contact].[Phone2], [Contact].[Phone2Type], [Contact].[Phone3], [Contact].[Phone3Type], [Contact].[DateOfBirth], [Contact].[NoteID], NULL, NULL, NULL, [Contact].[IsActive], [Contact].[NoFax], [Contact].[NoMail], [Contact].[NoMarketing], [Contact].[NoCall], [Contact].[NoEMail], [Contact].[NoMassMail], [Contact].[Gender], [Contact].[MaritalStatus], [Contact].[Anniversary], [Contact].[Spouse], [Contact].[Img], [Contact].[Synchronize], [Contact].[ContactType], CASE WHEN ( [Contact].[ContactType] = 'AP') THEN -10 WHEN ( ( [Contact].[ContactType] = 'SP')) THEN -5 WHEN ( ( [Contact].[ContactType] = 'EP')) THEN -1 WHEN ( ( [Contact].[ContactType] = 'PN')) THEN 0 WHEN ( ( [Contact].[ContactType] = 'LD')) THEN 10 END, [Contact].[DuplicateStatus], CASE WHEN ( [Contact].[DuplicateStatus] = 'PD' AND 1 = 0 ) THEN CONVERT(BIT, 1) ELSE CONVERT(BIT, 0) END, [Contact].[MajorStatus], [Contact].[Status], [Contact].[Resolution], [Contact].[AssignDate], [Contact].[QualificationDate], [Contact].[ClassID], [Contact].[Source], [Contact].[WorkgroupID], [Contact].[OwnerID], [Contact].[UserID], [Contact].[CampaignID], [Contact].[Method], [Contact].[IsConvertable], [Contact].[GrammValidationDateTime], [Contact].[ConvertedBy], [Contact].[CreatedByID], [Contact].[CreatedByScreenID], [Contact].[CreatedDateTime], [Contact].[LastModifiedByID], [Contact].[LastModifiedByScreenID], [Contact].[LastModifiedDateTime], '"' + ( [Contact].[DisplayName] + ( '"' + ( ' ' + ( '(' + ( [Contact].[EMail] + ')'))))), [Contact].[ExtRefNbr], [Contact].[tstamp], [Contact].[DeletedDatabaseRecord], [CROpportunity].[OpportunityNumber], [CROpportunity].[OpportunityID], [CROpportunity].[BranchID], [CROpportunity].[OpportunityAddressID], [CROpportunity].[OpportunityContactID], [CROpportunity].[AllowOverrideContactAddress], [CROpportunity].[BAccountID], [CROpportunity].[LocationID], [CROpportunity].[ContactID], [CROpportunity].[ConvertedLeadID], [CROpportunity].[CROpportunityClassID], [CROpportunity].[OpportunityName], [CROpportunity].[Description], [CROpportunity].[ParentBAccountID], [CROpportunity].[ProjectID], [CROpportunity].[CloseDate], [CROpportunity].[StageID], [CROpportunity].[StageChangedDate], [CROpportunity].[CampaignSourceID], [CROpportunity].[MajorStatus], [CROpportunity].[Status], [CROpportunity].[Resolution], [CROpportunity].[AssignDate], [CROpportunity].[ClosingDate], [CROpportunity].[WorkgroupID], [CROpportunity].[OwnerID], [CROpportunity].[CuryID], [CROpportunity].[CuryInfoID], [CROpportunity].[LineTotal], [CROpportunity].[CuryLineTotal], [CROpportunity].[IsTaxValid], [CROpportunity].[TaxTotal], [CROpportunity].[CuryTaxTotal], [CROpportunity].[ManualTotalEntry], [CROpportunity].[Amount], CASE WHEN ( [CROpportunity].[ManualTotalEntry] = CONVERT(BIT, 1)) THEN [CROpportunity].[Amount] ELSE [CROpportunity].[LineTotal] END, [CROpportunity].[CuryAmount], [CROpportunity].[DiscTot], [CROpportunity].[CuryDiscTot], [CROpportunity].[ProductsAmount], [CROpportunity].[CuryProductsAmount], [CROpportunity].[CuryVatExemptTotal], [CROpportunity].[VatExemptTotal], [CROpportunity].[CuryVatTaxableTotal], [CROpportunity].[VatTaxableTotal], [CROpportunity].[TaxZoneID], [CROpportunity].[ARRefNbr], [CROpportunity].[OrderType], [CROpportunity].[OrderNbr], [CROpportunity].[NoteID], NULL, NULL, NULL, (SELECT TOP (1) CASE WHEN ( [CRActivityStatistics_s217].[LastIncomingActivityDate] IS NOT NULL AND [CRActivityStatistics_s217].[LastOutgoingActivityDate] IS NULL) THEN [CRActivityStatistics_s217].[LastIncomingActivityDate] WHEN ( [CRActivityStatistics_s217].[LastOutgoingActivityDate] IS NOT NULL AND [CRActivityStatistics_s217].[LastIncomingActivityDate] IS NULL) THEN [CRActivityStatistics_s217].[LastOutgoingActivityDate] WHEN ( [CRActivityStatistics_s217].[LastIncomingActivityDate] > [CRActivityStatistics_s217].[LastOutgoingActivityDate]) THEN [CRActivityStatistics_s217].[LastIncomingActivityDate] ELSE [CRActivityStatistics_s217].[LastOutgoingActivityDate] END FROM [CRActivityStatistics] [CRActivityStatistics_s217] WHERE [CRActivityStatistics_s217].CompanyID = 5 AND [CRActivityStatistics_s217].[NoteID] = [CROpportunity].[NoteID] ORDER BY CASE WHEN ( [CRActivityStatistics_s217].[LastIncomingActivityDate] IS NOT NULL AND [CRActivityStatistics_s217].[LastOutgoingActivityDate] IS NULL) THEN [CRActivityStatistics_s217].[LastIncomingActivityDate] WHEN ( [CRActivityStatistics_s217].[LastOutgoingActivityDate] IS NOT NULL AND [CRActivityStatistics_s217].[LastIncomingActivityDate] IS NULL) THEN [CRActivityStatistics_s217].[LastOutgoingActivityDate] WHEN ( [CRActivityStatistics_s217].[LastIncomingActivityDate] > [CRActivityStatistics_s217].[LastOutgoingActivityDate]) THEN [CRActivityStatistics_s217].[LastIncomingActivityDate] ELSE [CRActivityStatistics_s217].[LastOutgoingActivityDate] END), [CROpportunity].[Source], [CROpportunity].[tstamp], [CROpportunity].[CreatedByScreenID], [CROpportunity].[CreatedByID], [CROpportunity].[CreatedDateTime], [CROpportunity].[LastModifiedByID], [CROpportunity].[LastModifiedByScreenID], [CROpportunity].[LastModifiedDateTime], [CROpportunity].[ProductCntr], [CROpportunity].[UsrObservation], [CROpportunity].[UsrDateCollecte], [CROpportunity].[UsrDateReprise], [CROpportunity].[UsrCollecteur], [CROpportunity].[UsrTraiteur], [CROpportunity].[UsrEBDR], CASE WHEN [POOrder].[OrderType] = 'RO' THEN 'Normal' END AS orderby_case_s232
FROM [POOrder] [POOrder]
INNER JOIN [Contact] [Contact] ON [Contact].CompanyID = 5 AND [Contact].[DeletedDatabaseRecord] = 0 AND [Contact].[BAccountID] = [POOrder].[VendorID]
INNER JOIN [CROpportunity] [CROpportunity] ON [CROpportunity].CompanyID = 5 AND ([CROpportunity].BranchID IS NULL OR [CROpportunity].BranchID = 25) AND ([CROpportunity].[OpportunityID] = [POOrder].[UsrBSD] OR [CROpportunity].[UsrEBDR] = [POOrder].[UsrBRD])
WHERE [POOrder].CompanyID = 5 AND ([POOrder].BranchID IS NULL OR [POOrder].BranchID = 25) AND [Contact].[UserID] = @P0 AND [POOrder].[Status] = @P1
ORDER BY [POOrder].[OrderNbr], orderby_case_s232 OPTION(OPTIMIZE FOR UNKNOWN)
编辑2:
查看表POOrder的数据库,我已经有一些索引,一个在主键上,一个在供应商上,一个在NoteID上,还有一个奇怪的索引:
CREATE NONCLUSTERED INDEX [nci_wi_POOrder_35EBA31CDEA74D944FD7F833E2CF9116] ON [dbo].[POOrder]
(
[BranchID] ASC,
[CompanyID] ASC,
[UsrBSD] ASC
)
INCLUDE ( [Approved],
[BLOrderNbr],
[BLType],
[Cancelled],
[ControlTotal],
[CreatedByID],
[CreatedByScreenID],
[CreatedDateTime],
[CuryControlTotal],
[CuryDiscTot],
[CuryID],
[CuryInfoID],
[CuryLineTotal],
[CuryOpenLineTotal],
[CuryOpenOrderTotal],
[CuryOpenTaxTotal],
[CuryOrderTotal],
[CuryTaxTotal],
[CuryVatExemptTotal],
[CuryVatTaxableTotal],
[DiscTot],
[DontEmail],
[DontPrint],
[Emailed],
[EmployeeID],
[ExpectedDate],
[ExpirationDate],
[FOBPoint],
[Hold],
[IsOpenTaxValid],
[IsTaxValid],
[LastModifiedByID],
[LastModifiedByScreenID],
[LastModifiedDateTime],
[LineCntr],
[LineTotal],
[NoteID],
[OpenLineTotal],
[OpenOrderQty],
[OpenOrderTotal],
[OpenTaxTotal],
[OrderDate],
[OrderDesc],
[OrderQty],
[OrderTotal],
[OrderVolume],
[OrderWeight],
[OwnerWorkGroupID],
[PrepaymentDocType],
[PrepaymentRefNbr],
[Printed],
[Receipt],
[RemitAddressID],
[RemitContactID],
[RQReqNbr],
[ShipAddressID],
[ShipContactID],
[ShipDestType],
[ShipToBAccountID],
[ShipToLocationID],
[ShipVia],
[SiteID],
[soordernbr],
[soordertype],
[Status],
[TaxTotal],
[TaxZoneID],
[TermsID],
[tstamp],
[UsrBRD],
[UsrCodeMouvement],
[UsrDepartBateauDate],
[UsrFiliere],
[UsrLicenseExport],
[UsrNumeroContainer],
[UsrObservation],
[UsrPAV],
[UsrTypePO],
[VatExemptTotal],
[VatTaxableTotal],
[VendorID],
[VendorLocationID],
[VendorRefNbr]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
GO
我认为它是一个自动生成的索引(也许是Azure生成的?在自动调整历史记录中找不到),但是我不知道为什么以及是否应该保留它,而只对UsrBSD和UserBRD进行索引?
答案 0 :(得分:1)
要为PXGrid启用分页,请在Aspx中至少将其AllowPaging
属性设置为 True 或将属性SkinID
设置为具有{{ 1}}设置为 True (如 PrimaryInquire )。如果为 poCollecteur 数据视图定义了一个委托,那么您还必须遵循以下所示的方法来保存分页,并且每次从中选择数据时都不会从数据库中检索所有记录。 poCollecteur 数据视图。
AllowPaging