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.

Level: advancedTopic: SQL databases

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

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.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.