Newer Version Available
Get Feedback on Query Performance
The response contains one or more query execution plans that, 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.
See the explain parameter in Query for more details on the fields returned when using explain. See Working with Very Large SOQL Queries in the Apex Developer Guide for more information on making your queries more selective.
Example
- Example usage for getting performance feedback on a query that uses Merchandise__c
-
1/services/data/v46.0/query/?explain= 2SELECT+Name+FROM+Merchandise__c+WHERE+CreatedDate+=+TODAY+AND+Price__c+>+10.0 - Example response body for executing a performance feedback query
-
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. The first plan is used if the query is executed. Both plans note that a secondary optimization used when filtering out records marked as deleted was not used because the IsDeleted field is not indexed.
Example
- Example usage for getting performance feedback on a report
-
1/services/data/v46.0/query/?explain=00OD0000001hCzMMCU - Example response body for getting performance feedback on a report
-
1{ 2 "plans" : [ { 3 "cardinality" : 1, 4 "fields" : [ ], 5 "leadingOperationType" : "TableScan", 6 "notes" : [ { 7 "description" : "Not considering filter for optimization because unindexed", 8 "fields" : [ "IsDeleted" ], 9 "tableEnumOrId" : "Merchandise__c" 10 } ], 11 "relativeCost" : 0.65, 12 "sobjectCardinality" : 3, 13 "sobjectType" : "Merchandise__c" 14 } ] 15}This response indicates that Salesforce found one possible execution plan for the query behind this report. The plan scans all records without using an index. It can’t apply a secondary optimization when filtering out records marked as deleted, because the IsDeleted field is not indexed.