I'm trying to get some records from a CustomObject. This is my object relationships:
Object A [ObjectA__c]
-- Child Object B (master-detail link) [ObjectB__c]
My query is like this:
Set<Id> SetOfObjectA_Ids
prepared from this Query first using following query: Select MasterField__c From ObjectB__c Where User__c =: CurrentUserId
SELECT Id, Name, XyzFields__c FROM ObjectA__c
WHERE (ID IN: SetOfObjectA_Ids) OR (OwnerId =: CurrentUserId)
Now my query above with OR condition in filter is taking almost 41 seconds
(via JS Remoting call).
Now, if I keep everything above intact and just change the filtering criteria like these:
Query 1:
SELECT Id, Name, XyzFields__c FROM ObjectA__c WHERE (ID IN: SetOfObjectA_Ids)
Query 2:
SELECT Id, Name, XyzFields__c FROM ObjectA__c WHERE (OwnerId =: CurrentUserId)
Both these queries are individually taking almost 2.7 seconds
only (via JS Remoting).
Can anyone tell me does including OR condition in SOQL makes the query this much slow?
If anyone is considering how much data exists in these two Objects then here are the stats:
ObjectA__c = 34,433 records.
ObjectB__c = 78,128 records.