[PR #8135/b3c4388d backport][3.119] Improve the performance of the latest publication lookup when serving content from a repository-backed distribution. - #8138
Open
patchback[bot] wants to merge 1 commit into
Conversation
Distribution.get_repository_publication_and_version() resolves the newest publication for a repository-backed distribution with repository_version__in=repository.versions.all(). Django renders that as a subquery joined on pulp_id, which hides repository_id from the planner. It cannot use the (repository_id, number) unique index and instead scans the global index on number, filtering each row by repository. Since number is a per-repository counter and that index is global, the work is set by the total number of repository versions across all repositories rather than by the size of the repository being served. On an installation with a large number of repository versions this scans a substantial portion of core_repositoryversion to return a single row, and every repository degrades as any of them grow. Filtering with repository_version__repository selects the same rows but keeps repository_id visible, so the planner uses the (repository_id, number) index and the lookup becomes a short index scan. The same query also pulled repository_version.content_ids in via select_related. Nothing on this path reads it, and it holds every content unit UUID in the version, so defer it. closes #1995 Assisted-by: Claude Opus 5 (GitHub Copilot) (cherry picked from commit b3c4388)
4 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This is a backport of PR #8135 as merged into main (b3c4388).
Distribution.get_repository_publication_and_version() resolves the newest publication for a repository-backed distribution with repository_version__in=repository.versions.all(). Django renders that as a subquery joined on pulp_id, which hides repository_id from the planner. It cannot use the (repository_id, number) unique index and instead scans the global index on number, filtering each row by repository.
Since number is a per-repository counter and that index is global, the work is set by the total number of repository versions across all repositories rather than by the size of the repository being served. On an installation with a large number of repository versions this scans a substantial portion of core_repositoryversion to return a single row, and every repository degrades as any of them grow.
Filtering with repository_version__repository selects the same rows but keeps repository_id visible, so the planner uses the (repository_id, number) index and the lookup becomes a short index scan.
The same query was also hydrating
repository_version.content_idsthroughselect_related, which nothing on this path reads; it is now deferred.closes #1995
Assisted-by: Claude Opus 5 (GitHub Copilot)
📜 Checklist
See: Pull Request Walkthrough