Faz parte do material de SQL / PostgreSQL que eu montei a partir das minhas entrevistas. Abaixo, a resposta em inglês e, quando existe, a pegadinha mais comum.
One query fetches N records, followed by one additional query per record for related data. Loading 100 orders and then each order's customer separately can issue 101 queries.
Use a join, suitable eager loading, or batched lookups. The result may be one query or a small bounded set, depending on the ORM and pagination. DataLoader only groups keys, so the batch function must actually batch the database work.
Inspect query logs and row volume. Replacing N+1 with a huge join that duplicates many rows is not automatically an improvement.
Ler é o primeiro passo. No app, essa pergunta vira flashcard com repetição espaçada, e o módulo tem quiz e simulado para testar o que ficou.
Treinar essa pergunta no app