function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
YiQin HeYiQin He 

Query efficiency issue with User object

Hi

Recently, I have a issue that bugging me for several weeks. We have a email system that uses a custom object for saving emails. The total data amount is alreay around 1M and each of the user has an average of 10K records. When user login, we show the email page and by default we display 10 email records on the page. My query was originally using OwnerId as criteria to filter in user's records and it takes so long to get the reponse back and sometime get a transaction timeout error. Yesterday, I changed the criteria to use Owner.Email and this time it's improving drastically! (with only 10 secs) So I am really confused about the result. Does anyone has idea on this?
sandeep reddy 37sandeep reddy 37
whats the error  you got explain breafly about issue and requerment please?
 
YiQin HeYiQin He
This was my query to get first 10 emails to show on user's page:

SELECT Id, Subject__c, CreatedDate
FROM Email__c
WHERE OwnerId = UserInfo.GetUserId();
ORDER BY CreatedDate DESC LIMIT 10

this is running so slow that sometimes I will get 'No response from the server' error.

Now I changed it to:

SELECT Id, Subject__c, CreatedDate
FROM Email__c
WHERE Owner.Email = UserInfo.GetEmail();
ORDER BY CreatedDate DESC LIMIT 10

and this is working great.

So I'm very confused, why using email runs faster than using Id