In a SOQL query with parent-child relationship sub-queries, each
parent-child relationship counts as an additional query. These types
of queries have a limit of three times the number for top-level
queries.
Understanding Execution Governors and Limits
but when I run the query like
[select id, (select id from childs__r) from parent]
it is printed that: Number of SOQL queries: 1 out of 100
but based on the previous statement it should be 2
And what the statement means:
These types
of queries have a limit of three times the number for top-level
queries
Best Answer
If you look at a Test Runner, you'll see different types of SOQL query reports, not just lines returned. I always see something that looks like this:
I have similar "related" subqueries and always see them reported as "Aggregations" not as parent-child queries as in the example below:
In many cases, something may be a "related" to another object, making it act as "child". I suspect the documentation is referring to a parent-child relationship where one is the Master and the other the Detail; not the situation where one object is the related object of another and thus behaves as a child but is not the child in a Master-Detail relationship.
Edit
The point I'm trying to make is that many related relationships can be unclear and it appears to me that SF is reporting them all as
Aggregations
regardless of whether they're the direct child of a parent or simply on a related object. In the example above,Events
is obviously a related object, but not a direct child ofOpportunity
. The same applies toRecap_Forms_New__r
. However,Opportunity
is the parent ofR00N40000001pm1JEAQ
, yet all 3 are shown asAggregations
. When I study what's reported as the log progresses, only the query rows increase because of theAggregations
, not the number of SOQL queries.