web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

while select notexists join behavior in runCalculationsForBpMissingCost

(0) ShareShare
ReportReport
Posted on by 1,501

It all started with performance issue while creating a batch order (Estimation part).  I end up finding that 

\Classes\PmfRecycledBpMissingCostCalc_Prod\runCalculationsForBpMissingCost

was taking a long time.  I debug this while select and I saw that i was browsing ProdIds that were different then the where clause should filter.  So I created a job to replicate and understand.  Turns out that just changing the position of the where clause change the behavior.  Below, you'll see that the first "while select" will scroll thru many ProdId, and the second "while select" will only browse the specified prodId (523464).  I though those 2 syntax were equal!

PmfProdCoBy                 pmfProdCoBy;
PmfCoByProdCalcTrans        pmfCoByProdCalcTrans;
BOMCalcProd_PmfCoByProduct  byProductCalc;

while select pmfProdCoBy
notexists join pmfCoByProdCalcTrans
where pmfProdCoBy.ProdId == '523464'
        &&  pmfCoByProdCalcTrans.PmfIdRefCoByRecId == pmfProdCoBy.RecId
{
    info(pmfProdCoBy.ProdId);
}
    
warning("2 where");
    
while select pmfProdCoBy
    where pmfProdCoBy.ProdId == '523464'        
notexists join pmfCoByProdCalcTrans    
    where pmfCoByProdCalcTrans.PmfIdRefCoByRecId == pmfProdCoBy.RecId
{
    info(pmfProdCoBy.ProdId);
}   

I don't know how this is translated to T-SQL, but from Ax point of view it looks the same.  Can someone explain this?

Second question : Browsing all those ProdId, like the first while do, is this then intended purpose of runCalculationsForBpMissingCost?  Because I don't see why you would browse all those prodId to Estimate only 1.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Mea_ Profile Picture
    60,284 on at
    RE: while select notexists join behavior in runCalculationsForBpMissingCost

    Hi Steeve,

    It looks like a bug for me. If you will go to Tools-> Oprions -> Sql tab and tick "SQL Trace" tick box and "Infolog" tick box in Multiply SQL statement group you will be able to see all T-SQL statements.

    So first statement will be

    SELECT ... FROM PMFPRODCOBY T1

    WHERE ((T1.PARTITION=5637144576) AND (T1.DATAAREAID=N'rcnz'))

    AND NOT (EXISTS (SELECT 'x' FROM PMFCOBYPRODCALCTRANS T2 WHERE (((T2.PARTITION=5637144576) AND (T2.DATAAREAID=N'rcnz')) AND ((T1.PRODID=?) AND (T2.PMFIDREFCOBYRECID=T1.RECID))))) 


    and second 

    SELECT ... FROM PMFPRODCOBY T1 
    WHERE (((T1.PARTITION=5637144576) AND (T1.DATAAREAID=N'rcnz')) AND (T1.PRODID=?)) AND NOT (EXISTS (SELECT 'x' FROM PMFCOBYPRODCALCTRANS T2
    WHERE (((T2.PARTITION=5637144576) AND (T2.DATAAREAID=N'rcnz')) AND (T2.PMFIDREFCOBYRECID=T1.RECID))))

    As you can see first one select all PMFPRODCOBY that does not have PMFCOBYPRODCALCTRANS  for selected prod id
    and second one selects PMFPRODCOBY for selected prod id.

  • Martin Dráb Profile Picture
    236,394 Most Valuable Professional on at
    RE: while select notexists join behavior in runCalculationsForBpMissingCost

    In addition to Ievgen's advice, you can use generateOnly keyword together with getSqlStatement() to see the actual SQL query. It's very helpful when debugging cases like this.

  • Steeve Gilbert Profile Picture
    1,501 on at
    RE: while select notexists join behavior in runCalculationsForBpMissingCost

    Thanks for your answers guys!

  • Community Member Profile Picture
    on at
    RE: while select notexists join behavior in runCalculationsForBpMissingCost

    hello Steeve ¡¡

    What was the solution to your problem? I have the same problem :(

  • Steeve Gilbert Profile Picture
    1,501 on at
    RE: while select notexists join behavior in runCalculationsForBpMissingCost

    Hi Denisse,

    I reported this back when we were migrating to Ax2012.  But now we are migrating to D365 and it is fixed, the "where" as been moved like I expected it to be.  Here's how it looks in D365 :

        public void runCalculationsForBpMissingCost()
        {
            PmfProdCoBy                 pmfProdCoBy;
            PmfCoByProdCalcTrans        pmfCoByProdCalcTrans;
            BOMCalcProd_PmfCoByProduct  byProductCalc;
        
            while select pmfProdCoBy
                where pmfProdCoBy.ProdId == prodParmBOMCalc.topMostProdTableCalc().ProdId
            notexists join pmfCoByProdCalcTrans
                where pmfCoByProdCalcTrans.PmfIdRefCoByRecId == pmfProdCoBy.RecId
            {
                byProductCalc = BOMCalcProd_PmfCoByProduct::newCoByProduct(
                                                pmfProdCoBy,
                                                prodParmBOMCalc.ProfitSet,
                                                prodParmBOMCalc.CalcDate,
                                                prodParmBOMCalc.References,
                                                true);
        
                byProductCalc.calc();
            }
        }

    There's probably a patch that was release for Ax2012 to fix that.  Check out LCS or contact your partner.

  • Ahmed Issa Profile Picture
    249 on at
    RE: while select notexists join behavior in runCalculationsForBpMissingCost

    Hi Steeve ,


    We tried your suggestion of swapping the where clause and it works in AX 2012 R3 CU13.

    We will investigate the consequences of the change and will post soon.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#3
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans