A non-selective query may cause different programmatic elements (like an Apex trigger or batch Apex class) to fail. When querying large objects, special design considerations must be taken into consideration.
SOQL (Salesforce Object Query Language) is the query language used to search and retrieve data from Salesforce objects. The performance of a SOQL query depends on the presence of a selective filter. If a SOQL query contains at least one selective filter, the query is said to be selective. If the SOQL query doesn't contain a selective filter, the query is said to be non-selective and will require a full table scan.
When querying Accounts with custom filter criteria, such as finding all accounts created this year with a specific industry type, you need to ensure your query uses indexed fields efficiently. For example, if you're querying a custom object like Appointment__c with 240,000 records and filtering by CreatedDate and Status__c, understanding which fields are indexed and how selective they are determines whether your query performs well or times out.
The complexity of the SOQL query has a massive influence on whether a field is suitable for indexing. We strongly recommended reviewing the following materials to fully understand how standard and custom indexes are different, and how they're employed.
Keep in mind - While every effort has been made to ensure this article explained how the Salesforce SOQL query optimizer works at a high level, its behavior can change without notice to accommodate additional performance enhancements. Developers are advised to use the Query Plan view (available since Summer '14) in the Developer Console, to be able to tune unselective queries.
The performance of a SOQL will depend on the presence of a selective filter. If a SOQL query contains at least 1 selective filter, the query is said to be selective. If the SOQL query doesn't contain a selective filter, the query is said to be un-selective and will require a full table scan.
From the perspective of the query optimizer, a filter can be simple or composite. A simple filter would be each of the field expressions (<field> <operator> <value>) in a condition expression that uses the "AND" operator. In contrast, the result of joining 2 or more field expressions via the "OR" operator is a composite filter.
To Custom Index a field - Create a new case and provide the affected SOQL query, and user Id that can be used for testing, as well as the values of any binding variables used.
Custom indexes, when used improperly, can actually slow query results. It's best to create filter conditions that are selective so Force.com scans only the rows necessary in the objects your queries target. Force.com query optimizer doesn't use an index to drive queries containing non-selective filter conditions, even if the fields those filter conditions reference already have indexes on them.
Checklist of details to include in Support case for a custom index
Be sure that you include this information in your request, the reason why this information needs to be provided is outlined below.
What happens if more than one simple filter is selective? The query optimizer will choose the one with lower cost to drive the execution plan of the query.
How do you know if a composite filter is selective? The optimizer will determine if each of the simple filters is selective, and if in aggregate the number of returned records doesn't exceed the thresholds mentioned above. If these conditions are met, the filter will be selective.
000385218

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.