You need to sign in to do that
Don't have an account?
Cross Object Field vs Join Performance question
Hey,
This is more of a nitty gritty type question but a question that has come up nonetheless.
If I have a formula field that is doing a cross object join, will this perform faster than a join in a raw SOQL statement when retrieving the information (not filtering)? For example:
Contact has a lookup to Account
Formula field on Contact called Account_Name__c
If I query something like this:
Contact[] contactList = [ SELECT Account_Name__c FROM Contact ];
vs
Contact[] contactList = [ SELECT Account.Name FROM Contact ];
Would the first query be faster than the second? As far as I know, formula fields are always evaluated at point in time that the query is run and therefore should perform roughly the same. I am however being told otherwise and that a formula field will be more performant. Am I missing something here?
Normally I'd think they'd be roughly the same (since it's not a filter it is essentially doing the join for us). However, some benchmarks have been done and are showing that the formula field approach is significantly faster than the join approach.
Any other insight on why this might be would be appreciated.