Jack Casas
Jack Casas

Reputation: 994

Procedure performance. SQL Server, Dynamics AX 2012 R3 CU10

We runnning this code from our ERP application Dynamics AX 2012 R3 CU10, which is part of the upgrade process from AX 4.

 ttsbegin;        

    while select forupdate salesLine
        where salesLine.RemainSalesFinancial  != 0
           && salesLine.RemainInventFinancial == 0
    {
        salesLine.RemainInventFinancial = 0;
        select sum(Qty) from inventTrans
            where inventTrans.del_InventTransId == salesLine.InventTransId
               &&(inventTrans.StatusIssue       == StatusIssue::Deducted
               || inventTrans.StatusReceipt     == StatusReceipt::Received);

        salesLine.RemainInventFinancial = -inventTrans.Qty;
        salesLine.doUpdate();
    }
    ttscommit;

The thing is that we ran this process for 2 installations. In the first installation the entire procedure took 45 minutes to execute, however, on the second one it takes 24 hours.

I'm trying to find out where is the performance issue. This are my observations:

I'm not sure if OS o SQL server edition can have such an impact in execution time. I need to make sure this is the issue before ordering a software or OS change.

I don't know what else to check. Any ideas?

In case anyone wants to have a look, the code is in class.method: ReleaseUpdateDB401_Cust.updateSalesLineRemainInventFinancial

Upvotes: 2

Views: 653

Answers (1)

Jan B. Kjeldsen
Jan B. Kjeldsen

Reputation: 18061

As the question comments show the time difference can be explained by the difference in data regarding the remain fields.

To speed-up the proces use only one round-trip to the database:

salesLine.skipDataMethods(true);
update_recordset salesLine
    setting RemainInventFinancial = -inventTrans.Qty
    where salesLine.RemainSalesFinancial  != 0
       && salesLine.RemainInventFinancial == 0
    join sum(Qty) from inventTrans
    where inventTrans.del_InventTransId == salesLine.InventTransId
       &&(inventTrans.StatusIssue       == StatusIssue::Deducted
       || inventTrans.StatusReceipt     == StatusReceipt::Received);
info(int642str(salesLine.rowCount()); // Number of records updated

It will be two orders of manitude (10-100 times) faster.

Upvotes: 3

Related Questions