Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Big O of SetRange()

(0) ShareShare
ReportReport
Posted on by 4
I was wondering if SetRange() goes through all lines in a record to find the lines that match the range or if SetRange works differently?
  • gdrenteria Profile Picture
    gdrenteria 13,278 Most Valuable Professional on at
  • Suggested answer
    Alexander Drogin Profile Picture
    Alexander Drogin 187 on at
    Big O of SetRange()
    In short: it depends on the table and its indexes, as well as the filters applied.
     
    SetRange function itself basically does not analyze any records, it only modifies the state of the record variable on which it is called, so the next time you invoke a FindFirst/FindLast/FindSet function, it will apply the selected filters. The purpose of SetRange is to add the the search predicates to the the SQL query that one of the Find* functions will issue. Condition added in SetRange is directly translated to the WHERE clause of the SELECT query.
    And now this ties back to my first statement. The way the query is executed depends on the indexes, exact filter values, data statistics, and so on. SQL Server's query optimizer will decide on the best way to execute the query: it may scan all records, so the complexity will be O(n), or may use an appropriate index and reduce the complexity to O(log n).
  • Martin Dráb Profile Picture
    Martin Dráb 230,605 Most Valuable Professional on at
    Big O of SetRange()
    Moved from Integration, Dataverse, and general topics forum.
  • ME-14012249-0 Profile Picture
    ME-14012249-0 4 on at
    Big O of SetRange()
    I completely forgot to mention that, it's for Business Central
  • Martin Dráb Profile Picture
    Martin Dráb 230,605 Most Valuable Professional on at
    Big O of SetRange()
    Which D365 product are you using? The D365 brand covers quite a few things, such as Finance and Operations, Business Central or Customer Engagement.

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,904 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,605 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans