Newer Version Available

This content describes an older version of this product. View Latest

Get Feedback on Query Performance (Beta)

To get feedback on how Salesforce executes your query, report, or list view, use the Query resource along with the explain parameter. Salesforce analyzes each query to find the optimal approach to obtain the query results. Depending on the query and query filters, Salesforce uses an index or internal optimization. To return details on how Salesforce optimizes your query, without actually running the query, use the explain parameter. Based on the response, decide whether to fine-tune the performance of your query, like adding filters to make the query more selective.

This feature is a Beta Service. Customer may opt to try such Beta Service in its sole discretion. Any use of the Beta Service is subject to the applicable Beta Services Terms provided at Agreements and Terms.

Note

The response contains one or more query execution plans, sorted from most optimal to least optimal. The most optimal plan is the plan that’s used when the query, report, or list view is executed.

For more details on the fields returned when using explain, see the explain parameter in Query Options Headers. For more information on making queries more selective, see Working with Very Large SOQL Queries in the Apex Developer Guide.

Example: Feedback on Query Performance

The following performance feedback query uses Merchandise__c:

1curl https://MyDomainName.my.salesforce.com/services/data/v57.0/query/?explain=
2SELECT+Name+FROM+Merchandise__c+WHERE+CreatedDate+=+TODAY+AND+Price__c+>+10.0

The response body for a performance feedback query looks like this:

1{
2  "plans" : [ {
3    "cardinality" : 1,
4    "fields" : [ "CreatedDate" ],
5    "leadingOperationType" : "Index",
6    "notes" :  [ {
7      "description" : "Not considering filter for optimization because unindexed",
8      "fields" : [ "IsDeleted" ],
9      "tableEnumOrId" : "Merchandise__c"
10    } ],
11    "relativeCost" : 0.0,
12    "sobjectCardinality" : 3,
13    "sobjectType" : "Merchandise__c"
14  }, {
15    "cardinality" : 1,
16    "fields" : [ ],
17    "leadingOperationType" : "TableScan",
18    "notes" :  [ {
19      "description" : "Not considering filter for optimization because unindexed",
20      "fields" : [ "IsDeleted" ],
21      "tableEnumOrId" : "Merchandise__c"
22    } ],
23    "relativeCost" : 0.65,
24    "sobjectCardinality" : 3,
25    "sobjectType" : "Merchandise__c"
26  } ]
27}

This response indicates that Salesforce found two possible execution plans for this query. The first plan uses the CreatedDate index field to improve the performance of this query. The second plan scans all records without using an index. If the query is executed, the first plan is used. Both plans note that there’s no secondary optimization for filtering out records marked as deleted because the IsDeleted field isn’t indexed.