[[diagnosing-n-plus-1]]
= Diagnosing n+1 Issues

:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


(As of DN 4.1) set a break point in `FetchRequest#execute(...)`:

image::hints-n-tips/diagnosing-n-plus-1.png[width="800px"]

The "Variables" pane will tell you which field(s) are being loaded, and the stack trace should help explain why the field is required.

For example, it may be that an object is being loaded in a table and the initial query did not eagerly load that field.
In such a case, consider using fetch groups in the initial repository query to bring the required data into memory with just one SQL call.
See xref:pjdo:ROOT:hints-and-tips.adoc#typesafe-queries-and-fetchgroups[this hint/tip] for further details.
