The "N+1 selects problem"

Does anybody have a more detailed explanation of the “N+1 selects problem”? I’m newbie. I just understand that it has something do to with having to make a lot of database queries.

Leon
thanks

Hey,

I’m a newbie as well and trying to figure things out. However, here’s the super simple guide to solve the N+1 SELECT problem:

*Pre-fetch the records in batches which helps us to reduce the problem of N+1 to (N/K) + 1 where K refers to the size of the batch.

  • Subselect the fetching strategy
  • As a last resort, try to avoid or disable lazy loading altogether.

Additionally, I found this resource/answer on InterviewBit. For your reference, you can find the detailed answer on Stackoverflow