Skip to main content

Notifications

Announcements

No record found.

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?
////
  • Martin Dráb Profile Picture
    Martin Dráb 230,514 Most Valuable Professional on at
    BPCheckNestedLoopinCode : Nested data access loop found in method
    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;
        {
        }
    }
  • Suggested answer
    Layan Jwei Profile Picture
    Layan Jwei 7,278 Super User 2024 Season 2 on at
    BPCheckNestedLoopinCode : Nested data access loop found in method
    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
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,514 Most Valuable Professional on at
    BPCheckNestedLoopinCode : Nested data access loop found in method
    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.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,820 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,514 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans