Stop the N+1 nightmare, supercharge batch performance with Query object.
We have already tackled SQL Indexing and SIFT. But there’s another silent performance killer hiding in many extensions: the N+1 problem.
Are you still using repeat…until on table A, only to perform a Get or SetRange on table B inside that loop? You are making thousands of round-trips to the SQL server. It’s time to move from Record variables to Query Objects.
⚠️ The Problem: The N+1 Query Trap
Every time you call Get inside a loop, you’re opening a new “conversation” with SQL. If you loop through 1,000 records, that’s not one query, it’s 1,001 separate queries.
This pattern looks harmless in code, but in practice it floods the database with roundtrips, slowing down your extension and frustrating users.

🛠️ The Fix: Query Objects with SQL Joins
Instead of hammering the database with Get calls inside a loop, let SQL do the heavy lifting. A Query object performs an Inner Join or Left Outer Join directly at the SQL level. The result: one flattened dataset, delivered in a single trip to the server. With Query Objects, you batch your data retrieval, eliminate the N+1 problem, and keep your extensions fast.

➡️ Pro Tip: Query + Temp Table = Flexibility at Scale
Sometimes a Query alone can’t handle complex business logic. The trick? Run the Query first, pipe the results into a Temporary Table, and then process that temp table with AL.
👉 This way, you get the speed of SQL joins with the flexibility of AL logic, batching data efficiently while still applying custom rules.
💡 The Bottom Line
If you’re reading data from multiple related tables in a batch, stop relying on Record loops.
Use a Query Object to collapse thousands of roundtrips into one. Your execution time can drop substancially.