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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

BPCheckNestedLoopinCode : Nested data access loop found in method

(1) ShareShare
ReportReport
Posted on by
Hi guys, 
I have this warning: Nested data access loop found in X method for this part (attached bellow), and I am not really sure how to get rid of it. Also I couldn't have find anything useful.
Could you please help me with that?
////
I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at
    It warns your about a performance problem. Let's say your outer query returns five records and the inner one returns ten for each localX.xId. Then you'll run 5*10 more queries than necessary. This can easily cause a huge problem.
     
    The fix of this bug is simple - use a join to fetch both table at once in a single query.
  • Suggested answer
    Layan Jwei Profile Picture
    8,112 Super User 2025 Season 2 on at
    Hi User,

    As Martin said you need to replace the 2 whiles with a join -- for better performance
    while select firstonly xId from localX order by y desc
        where localX.ItemId == table.Iteml
        join local where local.xId == localX.xId
    {
    }

    Thanks,
    Layan Jweihan
  • Martin Dráb Profile Picture
    237,959 Most Valuable Professional on at
    Only now I've noticed that the first loop uses firstOnly keyword, therefore there doesn't have to a be any loop at all. You can do something like this:
    select firstonly xId from localX
        order by y desc
        where localX.ItemId == table.ItemId;
        
    if (localX.xId)
    {
        while select local
            where local.xId == localX.xId;
        {
        }
    }

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 592 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 478 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 305 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans