Index ontology_class_set on is_obsolete and name (closes #14)#30
Merged
Conversation
`MongoDBLoader.upsert_ontology_data` previously only declared the `id` index on `ontology_class_set`. Common downstream query patterns — filter out obsoletes, lookup by label — would full-collection-scan at NCBITaxon scale (~2.7M docs). Add `is_obsolete` and `name` indexes alongside the existing `id` index. Both are non-unique. Index maintenance during inserts has a small write cost; the speedup for downstream readers is much larger. A text/substring index on `name` + `alternative_names` is deferred until specific search use cases land (per #14's own note). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves MongoDB query performance for large ontologies (e.g., NCBITaxon scale) by adding additional indexes to the ontology_class_set collection during MongoDBLoader.upsert_ontology_data.
Changes:
- Add a non-unique index on
is_obsoleteinontology_class_set. - Add a non-unique index on
nameinontology_class_set. - Keep existing
idand relation compound index behavior unchanged.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
214
to
216
| @@ -216,6 +216,8 @@ def upsert_ontology_data( | |||
| relation_collection = self.db.create_collection(relation_collection_name, recreate_if_exists=False) | |||
Member
Author
There was a problem hiding this comment.
Implemented in commit 2e67c83 — replaced the misleading comment with an accurate description of what create_collection(recreate_if_exists=False) + the index calls actually do.
…iption Addresses Copilot review on #30: the previous comment claimed the collections and indexes were set up during initialization. In reality this method calls create_collection (idempotent, recreate_if_exists= False) and (re)declares each index right here. Rewrite the comment to match the actual behavior. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Member
|
I don't think the is_obsolete index will help much here (low cardinality and low selectivity) name is ok - could we remove the is_obsolete index? |
The is_obsolete field is low cardinality / low selectivity, so an index on it provides little query benefit while still adding write overhead. Keep the name index, which supports label lookups. Co-Authored-By: Claude <noreply@anthropic.com>
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.
Why
MongoDBLoader.upsert_ontology_dataonly declared theidindex onontology_class_set. Common downstream query patterns — filtering out obsoletes, looking up terms by label — would full-collection-scan at NCBITaxon scale (~2.7M docs).What
Add
is_obsoleteandnameindexes alongside the existingidindex. Both are non-unique:Index maintenance during inserts has a small write cost; the speedup for downstream readers is much larger.
A text/substring index on
name+alternative_namesis deferred until specific search use cases land (per #14's own note).Verification
make teststill passes (11 passed, 8 skipped). The index calls are idempotent — running against an existing collection just confirms the index is present.Closes #14.