Improve the performance of the latest publication lookup when serving content from a repository-backed distribution. - #8135
Merged
dralley merged 1 commit intoSep 25, 2026
Conversation
dralley
previously approved these changes
Sep 24, 2026
gerrod3
requested changes
Sep 24, 2026
Moustafa-Moustafa
force-pushed
the
fix/latest-publication-lookup-index
branch
from
September 24, 2026 21:57
6c9db75 to
c613d3a
Compare
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 pulp#1995 Assisted-by: Claude Opus 5 (GitHub Copilot)
Moustafa-Moustafa
force-pushed
the
fix/latest-publication-lookup-index
branch
from
September 24, 2026 22:01
c613d3a to
a85e39a
Compare
dralley
approved these changes
Sep 25, 2026
gerrod3
approved these changes
Sep 25, 2026
Backport to 3.119: 💚 backport PR created✅ Backport PR branch: Backported as #8138 🤖 @patchback |
4 tasks
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.
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