OrderByDescending served by an index returns tied keys in reverse insertion order, unlike LINQ and the non-indexed path
Maintainers usually reply within 2 days
A pull request for this has already been merged.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
Research direction
The payload names no files, so start by reproducing the mismatch: insert 300 documents with Age = i % 50 and index Age, then compare OrderByDescending(p => p.Age).Take(3) against the non-indexed OrderByDescending(p => p.Age + 0).Take(3). Find the backward index scan in the query path and check how it orders equal keys. The issue leaves open whether to document ties as undefined or match the forward order, so settle that with the maintainer before writing code. Done means both paths agree or the chosen contract is documented and tested.
Written by the indexing model from the issue text.
Description
Version: main (efacaf4).
What happens
When OrderByDescending is served by a secondary index, documents with equal keys come back in exactly the reverse of the ascending order, i.e. reverse insertion order. LINQ's OrderByDescending is a stable sort and keeps source order for ties, and so does BLite's own non-indexed path (OrderByDescending(p => p.Age + 0)).
300 documents, Age = i % 50, names p000..p299, Age indexed:
| query | result |
|---|---|
OrderByDescending(p => p.Age).Take(3) (index) |
p149, p299, p099 |
OrderByDescending(p => p.Age + 0).Take(3) (no index) |
p249, p199, p049 |
With Take(n) ending inside a run of ties, the two paths select different documents, not just a different order. Ascending order matched LINQ in all three datasets tried (sequential inserts, ObjectIds in reverse insertion order, relocated documents).
Expected
Either document that ties have no defined order (and accept that the two paths differ), or read each run of equal keys forward when scanning the index backwards so both paths agree.
- Dominant language
- C#
- Stars
- 66
- Forks
- 6
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 58
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from EntglDb/BLite
-
GdprMode.Strict warns that deleted documents are not zeroed, but every delete zero-fills themPossibly taken @CaffeinatedCoder claimed this today. Openbug gdpr package/core severity/low
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
EntglDb/BLite#299 · 1 comment ·
Maintainers usually reply within 2 days
-
bug package/core severity/medium triage
Difficulty 4/5 3-5 days Newbie friendliness 54/100
Maintainers usually reply within 2 days
-
bug package/core severity/medium
Difficulty 4/5 3-5 days Newbie friendliness 48/100
EntglDb/BLite#322 · 1 comment ·
Maintainers usually reply within 2 days
-
enhancement package/core
Difficulty 4/5 3-5 days Newbie friendliness 48/100
EntglDb/BLite#320 · 1 comment ·
Maintainers usually reply within 2 days
-
BLiteSession.Rollback() does not await the rollback: it returns while the transaction is still active, and failures go unobservedPossibly taken @CaffeinatedCoder claimed this today. Openbug package/core severity/medium
Difficulty 3/5 1-2 days Newbie friendliness 78/100
EntglDb/BLite#307 · 1 comment ·
Maintainers usually reply within 2 days
Similar issues
-
Backend enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
dimitar-radenkov/Pointframe#271 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
qew21/Genshin-Subtitles#45 ·
-
bug priority: P2
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
space-wizards/RobustToolbox#7158 ·
Maintainers usually reply within 1 day