You need to sign in to do that
Don't have an account?
tf_ianr
Too many query rows exception
I'm getting the "Too Many Query Rows Exception" even though the combined queries in my code aren't returning more than about 2000 rows.
I ran a debug log. There are a two queries higher up that return about 700 rows each, then this one that returns 24 and triggers the error:
19:12:35.172|SOQL_EXECUTE_BEGIN|[165]|Aggregations:0|select id, LogType__c, UserLoginName__c, MachineName__c, TimeStamp__c, LogNotes__c from MyCustomTable__c where Event__c = :this.m_eventID and LogType__c in ('Download','Upload') and Attendance__c = null 19:12:35.196|SOQL_EXECUTE_END|[165]|Rows:24 19:12:35.196|EXCEPTION_THROWN|[165]|System.Exception: Too many query rows: 10001
This is confusing me. I understand that the limits apply to all queries exectued in the handling of a request, but does Salesforce count the rows that are actually returned for the queries, or is it counting the rows that the queries 'look at'?
In other words, how does this exception work exactly?
I suspect the issue is the query with the 2 group by's:
select UserLoginName__c, MachineName__c from TF_Events_Scanning_Log__c where Event__c = :this.m_eventID group by UserLoginName__c, MachineName__c
Could be that it's making some sort of cartesian product there and querying 752*752 rows, or maybe 752*9. Why are you grouping by those things anyway if you're not using any aggregate functions on them?
All Answers
Hi,
Please verify your debug logs once again and check where more queries are returning.
Total number of query rows 10000 is per context.
It counts the rows only that are actually returned for the queries.
Thanks,
Kodisana
Do you perhaps have a query further up that's doing a COUNT or some other aggregate function? That can eat lots of query rows without seeming to return much. Obviously it's going to error out on the last query it does though, that's the stick that breaks the camel's back, but it probably isn't the true culprit.
Thanks for your suggestions. Perhaps you can figure it out from the debug log?
Here's my complete debug log for the request that causes the error:
There are six queries and they return return:
I suspect the issue is the query with the 2 group by's:
select UserLoginName__c, MachineName__c from TF_Events_Scanning_Log__c where Event__c = :this.m_eventID group by UserLoginName__c, MachineName__c
Could be that it's making some sort of cartesian product there and querying 752*752 rows, or maybe 752*9. Why are you grouping by those things anyway if you're not using any aggregate functions on them?
Yeah, you're right, it was the group by queries. They were hitting a lot more rows than I originally thought they were, but it only gives you the count of the final result so its hard to track down. Fixed now, thanks.
(edit: I'm using the group-by without aggregates as an alternative to 'select distinct' which afaik SOQL cannot do)