AI engineering glossary · SQL databases
What is n+1 query problem?
N+1 query problem: A performance trap where code runs one query to get a list, then one more query per item to get related data, giving N+1 queries. It is fixed with a join or by loading related rows in a single batch.
N+1 query problem: an example
Fetching 100 orders and then querying each order's customer separately makes 101 queries instead of one join.
Related terms
More SQL databases terms
- Non-repeatable read
- Normalization
- NoSQL
- NOT NULL
- NULL
- Object-relational mapper
- One-to-many relationship
- ORDER BY
Where you learn it
N+1 query problem is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.