I have a BAQ that suddenly started running like a dog. The user was getting a timeout error after 30 seconds. I increased the querytimout so that I could just let it run until it was complete and it took just over 10 minutes.
So I copied the SQL code from the BAQ and pasted it into SQL Management Studio and executed the Query…it took less that 1 second to run.
Anyone seen something like this before? It is not a complex BAQ, 5 tables with simple joins and grouping plus 1 calculated field.
select
[Customer].[Name] as [Customer_Name],
[OrderRel].[Plant] as [OrderRel_Plant],
[OrderHed].[OrderNum] as [OrderHed_OrderNum],
[OrderDtl].[OrderLine] as [OrderDtl_OrderLine],
[OrderHed].[EntryPerson] as [OrderHed_EntryPerson],
[OrderDtl].[PartNum] as [OrderDtl_PartNum],
[OrderDtl].[IUM] as [OrderDtl_IUM],
[OrderDtl].[SalesUM] as [OrderDtl_SalesUM],
[OrderDtl].[OrderQty] as [OrderDtl_OrderQty],
[PartPlant].[OrderIncr_c] as [PartPlant_OrderIncr_c],
(OrderDtl.OrderQty % PartPlant.OrderIncr_c) as [Calculated_Modulus]
from Erp.OrderHed as OrderHed
inner join Erp.OrderDtl as OrderDtl on
OrderHed.Company = OrderDtl.Company
and OrderHed.OrderNum = OrderDtl.OrderNum
and ( OrderDtl.OpenLine = 1 )
inner join Erp.OrderRel as OrderRel on
OrderDtl.Company = OrderRel.Company
and OrderDtl.OrderNum = OrderRel.OrderNum
and OrderDtl.OrderLine = OrderRel.OrderLine
inner join dbo.PartPlant as PartPlant on
PartPlant.Company = OrderRel.Company
and PartPlant.PartNum = OrderRel.PartNum
and PartPlant.Plant = OrderRel.Plant
and ( PartPlant.OrderIncr_c > 1 )
inner join Erp.Customer as Customer on
OrderHed.Company = Customer.Company
and OrderHed.BTCustNum = Customer.CustNum
where (OrderHed.OpenOrder = 1 and OrderHed.VoidOrder = 0)
and ((OrderDtl.OrderQty % PartPlant.OrderIncr_c) <> 0)
group by [Customer].[Name],
[OrderRel].[Plant],
[OrderHed].[OrderNum],
[OrderDtl].[OrderLine],
[OrderHed].[EntryPerson],
[OrderDtl].[PartNum],
[OrderDtl].[IUM],
[OrderDtl].[SalesUM],
[OrderDtl].[OrderQty],
[PartPlant].[OrderIncr_c],
(OrderDtl.OrderQty % PartPlant.OrderIncr_c)