[HLAPI] Improve search performance #21639
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist before requesting a review
Description
When the HLAPI does a search in the database, the process is to first fetch the main items and the foreign keys and then fetch the required data based on the foreign keys and merged with the initial results (More information can be found in the developer documentation).
The issue this PR resolves is that during the first query, the fields within the main table are fetched and then they are fetched a second time during the hydration step.
In my test searching Users with 1014 results returned, performance improved by 50% with this fix. This was the best case scenario though where there was only one or two extra DB queries needed for hydration since they were mostly empty users that had been bulk created.
This optimization cannot be applied to union searches because only the foreign key information is fetched in the initial search.