Indexing Flashcards
In what order does Salesforce perform indexed searches?
- Searching indexes
- Narrow results based on access permissions, search limits and other filters (which produces a result set)
- After the result set reaches a predetermine size, the remaining records are discarded.
- Result set is then used to query the records from the database to retrieve the fields that a user sees
List the 6 steps that the Lightning Platform Query Optimizer follows
- Determines the best index from which to drive the query based on the query filters
- Determines the best table to drive the query from if no good index is available
- Determines how to order the remaining tables to minimize cost
- Injects Custom Foreign key value tables as needed for efficient join paths
- Influences the execution plan for the remaining joins, including sharing joins, to minimize database IO
- Updates statistics
How often does the Salesforce statistics gathering process runs?
Nightly
Which fields does Salesforce not support for custom indexes?
- Multi-select picklists
- Currency fields in a multicurrency organization
- Text areas (long and rich)
- Non-deterministic formula fields
- Binary fields (Blob, file or Encrypted text)
- New data types added by Salesforce
Are external ID fields indexed?
Yes. The query optimizer will consider external ID fields
What data types can be External Ids?
- Auto Number
- Number
- Text
The Salesforce multi-tenant architecture makes the underlying data table for custom fields unsuitable for indexing. How does Salesforce overcome this limitation?
The platform creates an index table that contains a copy of the data, along with information about the data types.
It then builds a standard database index on this index table.
The index table places upper limits on the number of records that an indexed search can effectively return.
What about null records in the index table? Are they included or not?
By default they do not include records that are null (or have empty values).
BUT, you can work with Salesforce Customer Support to create custom indexes that include null rows
How does the query optimizer know that an index won’t work (or will return too many rows)
The query optimizer maintains a table containing statistics about the distribution of data in each index.
It then uses this table to pre-query to determine whether using the index can speed up the query
When will standard indexed fields be used?
If the filter matches
less than 30% of the first million records
and less than 15% of remaining records
up to a maximum of 1 million records
When will custom indexed fields be used?
If the filter matches
less than 10% of the first million records
and less than 5% of the remaining records
up to a maximum of 333,333 records
For a standard index, if the query is executed against a table with 2 million records, what is the maximum number of records returned that will allow the index to be used?
450,000 records
For a standard index, if the query is executed against a table with 5 million records, what is the maximum number of records returned that will allow the index to be used?
900,000 records
For a custom index, if the query is executed against a table with 500,000 records, what is the maximum number of records returned that will allow the index to be used?
50,000 records
For a custom index, if the query is executed against a table with 5 million records, what is the maximum number of records returned that will allow the index to be used
333,333 records
When a query contains AND, the query optimizer will use the custom indexes unless ONE of them returns more than what % of the object’s records up to how many total records?
Answer in the format of: x% of the object’s records or y total records
The index will be used unless one of them returns more than 20% of the object’s records or 666,666 total records
100When a query contains OR, the query optimizer will use the custom index unless they ALL return more than what % of the object’s records, or total records?
Answer in the format of: x% of the object’s records or y
The index will be used unless they all return more than 10% of the object’s records or 333,333 total records
How can you create a custom index?
Contact Salesforce Customer support
Are custom indexes copied to all sandbox environments?
Yes (if the sandbox is created from the production copy that has the custom index)
Salesforce typically maintains indexes on which fields? (For most objects that is)
Indexed Standard Fields on All objects:
- Id
- Name
- Division
- OwnerId
- CreatedDate
- Systemmodstamp
- RecordType (indexed for all standard objects that feature it)
- Master-Detail fields
- Lookup fields
- Email (Leads and Contacts)
Other indexed fields:
- Unique fields
- External ID fields
For an OR clause, must all the fields be index for any index to be used?
Yes, all the fields must be indexed.
What does the Lightning query optimizer do with a LIKE filter value (if that field has a custom index on it)
The query optimizer does not use its internal statistics table. Instead, it samples up to 100,000 records of actual data to decide whether to use the custom index
Which type of formula fields can be used in custom indexes?
Deterministic formula fields.