The N + 1 query problem occurs when an initial query retrieves N records and the application then issues one additional query for each record. The resulting N + 1 queries can create significant latency. section 6.3.2
Investigate the pattern by asking:
- How many times does each SQL query execute? section 6.3.2
- Does a framework fetch related table data in one composed query or issue a query per retrieved record? section 6.3.2
- Can a profiler reveal execution time and query counts more clearly than logs or a debugger? section 6.3.2
Figure 6.15 Even when working with a framework, the profiler can still intercept the SQL queries. This makes your investigation a lot easier because you can’t copy the query directly from the code like when using JDBC and native queries.
Use profiler interception to inspect SQL generated behind a persistence framework, including execution time and execution count. section 6.3.2



