fix(query-planner): out-of-schema-range $gt/$lt silently drops boundary documents#8601
Open
sravan27 wants to merge 1 commit into
Open
fix(query-planner): out-of-schema-range $gt/$lt silently drops boundary documents#8601sravan27 wants to merge 1 commit into
sravan27 wants to merge 1 commit into
Conversation
A `$gt`/`$lt` bound that lies outside the indexed field's schema minimum/maximum was clamped to the boundary when building the index string but kept exclusive, so the boundary document was silently dropped from index-based results: e.g. `$gt: -10` on a field with `minimum: 0` excluded the doc with value 0, and `$lt: 110` with `maximum: 100` excluded 100. Storages that resolve the query purely from the index (memory, localstorage, foundationdb, denokv) returned wrong results with no error. Treat a lower bound below the field minimum as INDEX_MIN (inclusive) and an upper bound above the field maximum as INDEX_MAX (inclusive). Exact-boundary exclusives ($gt at minimum, $lt at maximum) and all in-range bounds are unchanged. Validated end-to-end against the memory storage; adds a query-correctness regression test. Co-Authored-By: Claude Opus 4.8 <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.
Summary
A
$gt/$ltrange bound that lies entirely outside the indexed field's schemaminimum/maximumsilently drops the boundary document. The out-of-range bound is clamped to the boundary when the index string is built (getNumberIndexString), but the bound stays exclusive — so the boundary document is excluded. Storages that resolve the query purely from the index (selectorSatisfiedByIndex: true— memory, localstorage, foundationdb, denokv) return wrong results with no error and no matcher fallback.Reproduce
Field
scorewith{ minimum: 0, maximum: 100 }, docsscore ∈ {0, 1, 50, 99, 100}:$gte: -10/$lte: 110are unaffected, because the inclusive bound includes the clamped boundary — which is why this slipped through (the existing boundary test only checks bounds at the limit, not beyond it).Fix
In the query planner, a lower bound below the field
minimumbecomesINDEX_MIN(inclusive) and an upper bound above the fieldmaximumbecomesINDEX_MAX(inclusive). Exact-boundary exclusives ($gtat the minimum,$ltat the maximum) and all in-range bounds are unchanged.Tests
Adds a
rx-storage-query-correctnesscase covering both bug cases plus regression guards ($gtat minimum still excludes it,$ltat maximum still excludes it, in-range bounds unchanged). Validated end-to-end against the memory storage before/after the fix.