Apex Governor Limits docs state that:
In a SOQL query with parent-child relationship subqueries, each parent-child relationship counts as an extra query.
However, when a query with a single subquery is run, for example:
List<Parent_Object__c> parents = [Select Id, (Select Id from Child_Objects__r) from Parent_Object__c];
the debug log shows that just 1 SOQL query was spent. That makes sense since subqueries are (left) joins.
It's the actual count, not just the count display because I can run 51 queries and limits won't be hit (if two queries would be counted and just one displayed, this would be 51 * 2 = 102 > 100
SOQLs).
So what's correct for total of N parents?
- 1 extra query for each parent record (1 + N SOQLs in total)
- 1 extra query for entire relationship (1 + 1 SOQLs in total)
- no extra queries (1 SOQL in total, as indicated by debug log)