6

Given any SOQL query (which for the sake of this question we can assume doesn't use apex bind variables), how can I determine things like what indexes (if any) are being used, and if the query is selective?

8

There's a feature for doing just this in the salesforce REST API. In short, you hit the endpoint https://pod.salesforce.com/v34.0/query/?q={your URL encoded query} and it will return JSON describing query plans, relative cost, etc.

If you don't feel like invoking the REST API directly you can also do this from the developer console with a nice interface. However the feature is well hidden, you first need to go to the Help > Preferences menu in the developer console and check Enable Query Plan.Dev console preferences

Once this is done the Query Editor tab in the bottom of the dev console will have a new button enabled: "Query Plan", next to the normal Execute button.

Enter your query and press this and you'll get all the data the REST API would provide, but in a nice graphical format:

query plan results dialog

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.