Skip to content

perf(mongodb): classify metadata-backed :missing parameters once per query - #2211

Open
mauripunzueta wants to merge 1 commit into
mainfrom
perf/2007-mongo-missing-classify-once
Open

mauripunzueta wants to merge 1 commit into
mainfrom
perf/2007-mongo-missing-classify-once

Conversation

@mauripunzueta

Copy link
Copy Markdown
Contributor

Closes #2007.

What

On MongoDB, the check for whether a :missing parameter is answered from missing_params ran again at every stage of a search. Each run took the tenant registry read lock and built a new SearchParameterExtractor. This PR classifies the parameters once per query and passes the result through planning and execution.

  • New MissingSupport (in search_impl.rs), built by MongoBackend::classify_missing(tenant, resource_type, query). It takes one registry read lock and builds one extractor per query. It stores the (name, param_type) pairs that missing_params answers. The old check depended only on those two fields (plus the index-ready flag), so the stored set gives the same answers it did.
  • supports_indexed_missing and is_missing_resource_parameter are gone. Their callers use MissingSupport::supports and MissingSupport::is_resource_parameter instead.
  • The value is passed through resource_filter_plan, plan_or_matching_ids, matching_resource_ids (and its seeded, complement-only and candidate-retention helpers), build_resource_filter, resource_order_page, sparse_page_id_set, search_param_sorted/resource_level_ids and count_standard_with_facts.
  • search_inner computes it once. Its total count reuses that value and the same database handle, where it used to call get_database() again.
  • retain_matching_candidates now receives the caller's db and no longer calls self.get_database() for each metadata-backed missing parameter.
  • The planner and the executor now read the same classification. Before, a registry reload in the middle of a query could make them disagree.
  • The _contained=both top-level filter is classified against the contained type, which is the type it already used.
  • The storage.rs conditional-match callers only pass _id / _lastUpdated parameters, so they use MissingSupport::none(). Behaviour there is unchanged.

Acceptance criteria

  • One classification per parameter per query
  • No get_database() inside per-parameter loops
  • Existing missing-index and resource-page tests still pass (see Testing)

Testing

Locally, against a single-node MongoDB 8.0.13 replica set, with HFS_TEST_REQUIRE_MONGODB=1 so that no Mongo-backed test could skip:

  • cargo test -p helios-persistence --features mongodb --lib backends::mongodb → 486 passed, 0 failed. This includes the planner's execution_tests and resource_page_tests.
  • cargo test -p helios-persistence --features mongodb --test mongodb_tests → 506 passed, 0 failed, 2 ignored (the #[ignore]d benchmarks).
  • cargo clippy -p helios-persistence --features mongodb --tests: no new warnings. The only warnings in the files touched are existing collapsible_if lints from the newer local toolchain, none of them on lines this PR changes.

No new test is added. The change is a refactor that should not change behaviour, and the existing missing-index tests cover each branch that now reads MissingSupport.

…rs once per query

Whether a :missing parameter is answered from missing_params was
recomputed at every planning and execution stage, each time taking the
tenant registry read lock and building an extractor. A registry reload
mid-query could also make the planner and executor disagree.

Classify once into MissingSupport (keyed by name and type, which is all
the check depended on) and pass it, with the database handle, through
planning and execution. retain_matching_candidates no longer calls
get_database() per metadata-backed missing parameter, and the search
total reuses the page's handle and classification.

Closes #2007
@codecov

codecov Bot commented Oct 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.10417% with 19 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...es/persistence/src/backends/mongodb/search_impl.rs 93.52% 11 Missing ⚠️
crates/persistence/src/backends/mongodb/storage.rs 20.00% 8 Missing ⚠️

📢 Thoughts on this report? Let us know!

@mauripunzueta
mauripunzueta marked this pull request as ready for review October 21, 2026 20:38

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mongodb search: classify metadata-backed :missing parameters once per query

1 participant