Sort fix - #185
Draft
mikehquan19 wants to merge 3 commits into
Draft
Conversation
mikehquan19
marked this pull request as draft
August 29, 2026 21:54
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.
Overview
Remove manual course sorting to avoid
Instead, programmatically create indexes to the courses collection on upload so the query's results can be sorted based on expected order. Note that indexes are idempotent, so on every upload, if index already exists, it will not be created again.
Over Nebula-API, course query should explicitily have expected ordering:
SetSort defines the ordering required by the query; it does not necessarily mean Mongo will perform an in-memory sort.
If the index satisfies the requested ordering, Mongo can read the results directly in index order and avoid in-memory sort. Otherwise, it can retrieve the matching documents first and then perform in-memory sort.
Use explain("executionStats") to verify whether it uses index order or performs in-memory sort. If the plan has
IXSCANstage and notSORTstages, it uses index order. Otherwise, it has performed blocking in-memory sort on the filtered docs.Example:
Note
I added unique indexes on course, which verfied that courses' compound indexing on
subject_prefix,course_number,catalog_year.