Introduction
Data Aggregation
Custom Search Functionality
Indexing with Nulls
Rendering Related Lists with Large Data Volumes
API Performance
Sort Optimization on a Query
Multi-Join Report Performance
Summary
Previous Versions
The customer designed a custom integration to synchronize Salesforce data with external customer applications.
The integration process involved:
The objects contained several million records. The integration also used a specific API user that was part of the sharing hierarchy to limit the records retrieved. The queries were taking minutes to complete.
In Salesforce, sharing is a very powerful mechanism for making certain records visible to a certain user, and it works very well for UI interactions. However, when used as a high-volume data filter in a SOQL query, performance can suffer because data access is more complex and difficult to process when you use sharing as a filter, especially if you are trying to filter out records in a large data volume situation.
The solution was to give the query access to all the data, and then to use selective filters to get the appropriate records. For example, using an administrator as the API user would have provided access to all of the data and prevented sharing from being considered in the query.
An additional solution would have been to create a delta extraction, lowering the volume of data that needed to be processed.
You can find more information about how sharing can affect performance in Platform Sharing Architecture.