I have an SOQL query between two custom objects, let's call them A__c and B__c, where A__c has a Lookup field called B__c that references a B__c instance and B__c has two fields X__c and Y__c like:
SELECT Id, B__r.Id, B__r.X__c, B__r.Y__c FROM A__c
When I have instances of B__c "shared" between the queried instances of A__c, i.e. where multiple A__c instances refer to the same B__c instance(s), does each A__c have its own copy of the related B__c or is SOQL smart enough to optimize the B__c instances so two or more returned A__c's actually use the same in-memory B__c as needed?
Empirically, it appears that the common B__c instances are actually shared (I can update the B__c instances obtained via A__c.B__r in different ways, based on other A__c values, and get the expected results). However, I can't find any official documentation about this. Can anyone point me to some documentation that states this as expected behaviour?