Newer Version Available
Get Feedback on Query Performance
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:
1/services/data/v51.0/query/?explain=
2SELECT+Name+FROM+Merchandise__c+WHERE+CreatedDate+=+TODAY+AND+Price__c+>+10.0The 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.