Loading

Developer Console Query Plan Tool FAQ

Дата публикации: Jun 25, 2026
Описание
The Query Plan tool in the Salesforce Developer Console helps you optimize SOQL queries that run over large data volumes. When queries time out or perform slowly, the Query Plan tool shows you the available execution plans and their relative costs, helping you determine whether your query is using an index or performing a full table scan.

Enable and Use the Query Plan Tool

  1. In the Developer Console, click Help | Preferences.
  2. Set Enable Query Plan to TRUE.
Once enabled, the Query Plan tool is available in the Query Editor tab of the Developer Console. Enter a SOQL query and press Query Plan to see all available execution plans and their costs.
Решение

Reasons to Use the Query Plan Tool

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.

Determining if a Filter is Selective

A filter is selective when it has an index and would return a small enough percentage of records:

  • Standard index fields include primary keys (Id, Name, OwnerId), foreign keys (CreatedById, LastModifiedById, lookup and master-detail relationship fields), and audit fields (CreatedDate, SystemModstamp). The selectivity threshold for standard indexes is 30% of the first million records and 15% beyond that, capping at 1 million total targeted records.
  • Custom index fields include fields marked as Unique or External ID. The selectivity threshold is 10% of the first million records and 5% beyond, capping at 333,333 targeted records.
  • If a filter has no index or exceeds the threshold, the Query Optimizer does not use it for optimization.

Understanding the Query Plan Table

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.
  • Index - The query will use an index on the queried object.
  • Sharing - The query will use an index based on the sharing rules associated with the user who is executing the query. If there are sharing rules that limit which records that user can access, Salesforce can use those rules to optimize the query.
  • TableScan - The query will scan all records for the queried object.
  • Other - The query will use optimizations internal to Salesforce.
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.
 

How Cost is Determined

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.

Indexed Field Does Not Appear in the List of Plans

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."

 

Examples and How to Interpret Query Plan Results

The following examples use two indexed fields on the Account object: a checkbox field InActiveAcc__c and a picklist field Account_Hierarchy__c.

 

Example Query 1

SELECT count() FROM Account WHERE Account_Hierarchy__c = 'Parent'


Scenario: An indexed field with a selective binding variable

The “Account_Hierarchy__c” field is indexed so it was considered for a Plan with Leading Operation Type as “Index”. The indexed field has a lower cost than the TableScan, so the index will be used by the Query Optimizer for this query on the Account Object of 50,088 rows.

 

Example Query 2

SELECT count() FROM Account WHERE InActiveAcc__c = true AND Account_Hierarchy__c = 'Parent'


Scenario: 2 Indexed fields, 1 selective

What happens if more than one simple filter is selective? If more than one filter are found to be selective, the query optimizer will choose the one with lower cost to drive the execution plan of the query.

 

Example Query 3

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

The index on Account_Hierarchy__c is not used or considered due to the unsupported operation of “!=”.  Also note that the InActiveAcc__c will be used but is higher cost than 1. As mentioned earlier, the filter is not selective but will be used.

 

Example Query 4

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)

Here, the indexed field Account_Hierarchy__c shows a much higher cost than a full table scan. The reason for this is that the Index is not selective with the binding variable "Child" resulting in more than 10% of the full table. The DB will execute a full table scan for this query, which, depending on the full table size, could result in poor performance.
 

 

Номер статьи базы знаний

000386864

 
Загрузка
Salesforce Help | Article