Once enabled in the Developer Console, you can access the Query Plan Tool in the 'Query Editor' tab of the console.
To use the Query Plan Tool, simply enter a query in the Query Editor and press Query Plan to displays all query operations and the cost of each for the SOQL provided.
Use this tool to check the Query Plan for any SOQL queries that execute slowly. It will provide you with insight on the different plans and should you have some of the filters indexed, provide the cost of using the index compared to a full table scan.
If the cost for the table scan is lower than the index, and the query is timing out, you will need to perform further analysis on using other filters to improve selectivity, or, if you have another selective filter in that query that is not indexed but is a candidate for one.
The Query Plan Tool will show a list of available plans that our Query Optimizer can use for the query provided and will be arranged by cost ascending.
Each Plan will contain information on Cardinality, Operation Type, Cost, sObject Type, and more. Each plan has a 'Leading Operation Type', for example, Field Index or Full Table Scan. The plan with the lowest cost is the plan that is used for driving the query execution.
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 its own Cost value. The cost value is derived from the latest gathered database (DB) statistics on the table and values. The plan with the lowest cost will be the plan used. If the Cost is above 1, it means that the query won’t be selective.
If the query you provided contains an Indexed field in the filters, the plan will be shown for that field only if you are using a supported operation against that field.
Here is a list of unsupported operations:
Note: OR filters that use indexes will appear as "Other" in the explain plan output.
The Query Plan tool will only show Indexed field statistics in the Plan’s section, not fields that could be indexed. This tool will not provide information on fields that can be indexed.
Please consult How to make my SOQL query selective on determining which fields can be indexed.
The following examples uses 2 indexed fields. A checkbox (InActiveAcc__c) and a Picklist (Account_Hierarchy__c) on the Account sObject.
Note: You can find more example queries at the original post on the Query Resource Feedback Parameter Pilot that this new Developer Console tool evolved from.
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.