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
china.leafchina.leaf 

Non-selective query against large object type (more than 100000 rows)

this is my code:

List<string> flstImport = new List<string>();

//add items to flstImport

List<InventoryCheckItem__c> flstInventoryCheckItem = [Select i.ImportId__c, i.Id From InventoryCheckItem__c i where i.ImportId__c in : flstImport];

it works well in sandbox, when deploy, i get the error message:

caused by: 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)

Note:

1.there are 402965 records in table InventoryCheckItem__c.
2.i already set ImportId__c "external ID"

My English is very poor, who can help me!~~~~~




SuperfellSuperfell
make sure flstImport doesn't contain any null values.
china.leafchina.leaf
thank you, SimonF

System.debug('■flstImport■'+flstImport);

■flstImport■(9999999991022722009-1, 9999999991022722009-2);

but table "InventoryCheckItem__c" exist records where ImportId__c is null

is this the reason?

Best Regards
JimRaeJimRae
In order for your external ID field to be an effective index, it should be non-null and unique, as a true keyed index would be.
china.leafchina.leaf
thank you, i will try it again.