I am getting the following error for a query I am running dynamically
System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)
The query is
SELECT Prior_Parent_Id__c, COUNT(Id) FROM Preferences__c WHERE Prior_Parent_Id__c in :originalIds GROUP BY Prior_Parent_Id__c
The originalIds list is populated and does not contain a null. What is more making this weird is that there are 0 records in the sandbox I am running this in for that object type.
I have raised a case with SFDC but wondered if anybody had any ideas why a query on an object with 0 rows returns such an exception.
I worked with Salesforce support on this one for a while but to no avail. The issue seemed to disappear after a week and we were unable to replicate it again. We performed an interim update changing the fields to external Ids to aid in resetting the indexes and counts for the queries.