Use this tool to investigate any SOQL query that executes slowly. The tool shows each available plan and its cost relative to the selectivity threshold. If your filtered field is indexed, the tool shows the index plan cost compared to a full table scan cost. If the table scan is cheaper, further analysis is needed to improve selectivity — such as adding additional indexed filters.
A filter is selective when it has an index and would return a small enough percentage of records:
The Query Plan tool returns a table with the following columns:
Cardinality |
Fields |
Leading Operation Type |
Cost |
sObject Cardinality |
sObject Type |
|---|---|---|---|---|---|
|
The estimated number of records that the leading operation type would return.
For example, the number of records returned if using an index table. | The indexed field(s) used by the Query Optimizer. If the leading operation type is Index, the fields value is Index. Otherwise, the fields value is null. |
The primary operation type that Salesforce will use to optimize the query.
| The cost of the query compared to the Force.com Query Optimizer’s selectivity threshold. Values above 1 mean that the query won’t be selective. |
The approximate record count for the queried object.
|
The name of the queried.
|
Each plan has a Cost value derived from database statistics on the table. The plan with the lowest cost is used. A Cost above 1 means the filter is not selective and a full table scan will be used.
An indexed field only appears as a plan option when a supported operation is used against it. Custom indexes are never used for the following operations: NOT EQUAL TO comparisons, null value comparisons (e.g., Name = ''), leading wildcard searches (e.g., Name LIKE '%Smith'), or OR comparisons where any involved field is non-indexed or above the 10% threshold.
Note: OR filters using indexes appear as "Other" in the explain plan output.
The Query Plan tool only shows indexed field statistics — it does not suggest which fields could be indexed. For guidance on indexing candidates, consult the article "How to make my SOQL query selective."
The following examples use two indexed fields on the Account object: a checkbox field InActiveAcc__c and a picklist field Account_Hierarchy__c.
SELECT count() FROM Account WHERE Account_Hierarchy__c = 'Parent'
Scenario: An indexed field with a selective binding variable
SELECT count() FROM Account WHERE InActiveAcc__c = true AND Account_Hierarchy__c = 'Parent'
Scenario: 2 Indexed fields, 1 selective
SELECT count() FROM Account WHERE InActiveAcc__c = true AND Account_Hierarchy__c != 'Parent' **NOTE: Using unsupported operation on index**
Scenario: 2 indexed fields, 1 selective BUT using an unsupported operation
SELECT count() FROM Account WHERE Account_Hierarchy__c = 'Child'
Scenario: 1 indexed field using an non-selective binding variable (>10% of sObject's row count)
000386864

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.