Repository navigation
Conversation
Copying a selection that includes advisories looped over them to find the packages and modules they reference: get_pkglist() and get_module_list() issued their own queries per advisory, followed by a NEVRA or NSVCA match query, so child detection cost grew with the number of advisories. Resolve the whole selection with one set-based query per content type: match the version's packages against the selected advisories' collection packages through the existing relations, and the modules against their collection NSVCAs. The queries are evaluated with nested loops disabled so PostgreSQL must use a hash or merge semi-join; the cardinality estimate for the version-content subquery can otherwise make a quadratic nested-loop plan look cheap. Both plans are linear in the inputs and spill to disk beyond work_mem. On a 2,059-advisory selection over a 7,656-package version, child detection takes 90% less time with identical destination content. At 468k collection-package rows the join remains a hash semi-join; with a small work_mem it spills across 1,024 batches and still resolves correctly. The old and new implementations return the same child sets for every advisory across three repository versions (4,431 single-advisory cases and 84 multi-advisory selections). Co-Authored-By: Claude Code <noreply@anthropic.com>
pablomh
force-pushed
the
batched-child-detection
branch
from
December 1, 2026 19:30
9ffdfb4 to
e320566
Compare
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.
Problem
Copying a selection that contains advisories finds the packages and modules they
reference by looping over the advisories. Each iteration runs
get_pkglist()andget_module_list(), then a NEVRA/NSVCA match query, so child detection costsO(advisories) round trips. This is the path Katello incremental updates take by
default, since
resolve_dependenciesdefaults to false.Change
Resolve the selection with one query per content type:
Existsbetween the version's packages and theUpdateCollectionPackagerows reached throughUpdateCollection.update_record;moduleJSON, extracting the NSVCAfields with
KeyTextTransform.The two queries evaluate inside a scoped
_hash_join_only()context that disablesnested-loop plans and restores the previous setting in
finally. PostgreSQLestimates the advisory subquery at a handful of rows, which allowed a quadratic
nested-loop plan for a broader queryset shape than the caller builds. With nested
loops off the planner must use a hash or merge semi-join, both linear in their
inputs and spilled to disk beyond
work_mem.Measurements (Alma 9 AppStream repository version)
work_memEquivalence: old and new implementations return identical child sets for every
advisory across three repository versions (4,431 single-advisory cases and 84
multi-advisory selections, packages and modules). All 144 module collections
carry the five expected NSVCA keys; the 22,288 collection-package rows contain no
duplicate tuples.
Tests
pytest --pyargs pulp_rpm.tests.unit: 144 passed, 1 skippedmain'sget_pkglist|get_module_listN+1 exemptiontest_advisory_copy_child_detection: passedruff check/ruff format --check: cleanNo API, schema or migration changes.
Behavior note
A malformed
UpdateCollection.modulemissing one of the five NSVCA keys used toraise
KeyError; it now matches nothing. No such row exists in the audited data,and validation belongs at advisory ingestion.
🤖 Generated with Claude Code