Repository navigation
fix(query): preserve subquery limit after offset skips - #730
Conversation
📝 WalkthroughWalkthroughProtocol version v3 now enables ChangesSubquery Offset-Consumed-Empty Limit Fix
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #730 +/- ##
===========================================
+ Coverage 92.37% 92.40% +0.03%
===========================================
Files 280 282 +2
Lines 86307 86482 +175
===========================================
+ Hits 79724 79913 +189
+ Misses 6583 6569 -14
🚀 New features to boost your workflow:
|
789d5ff to
5687dce
Compare
* feat(version): add GROVE_V4, behaviourally identical to V3 GROVE_V3 is live, so a fix that changes an accepted/rejected outcome, a committed root hash, or a tracked cost cannot be applied unconditionally — nodes carrying it would diverge from nodes that do not. There is currently nowhere for such a fix to land, which has left several of them stuck: - #776: overwriting an indexed tree with a bare Reference skips the per-axis secondary cleanup. Closing it costs an extra stored-element read on EVERY reference overwrite (+1 seek, +79 storage_loaded_bytes, measured by the refresh-reference cost tests), and references over plain trees are shipped functionality. - Batch DeleteTree treats the caller-declared tree type as authoritative when selecting cleanup namespaces. Reading the stored element instead fixes both an indexed type-confusion and a live CommitmentTree wrong-emptiness-path bug, but adds a read to a released path. - Per project notes, five audit-fix PRs (#726, #730, #732, #734, #739) are gated on v3 and need re-gating before they can merge. This adds the version and nothing else. Every method-version slot is copied from V3 unchanged, so activating protocol version 4 today is a no-op; each gate is a deliberate, separately-reviewable slot bump. Verified rather than assumed: registering V4 changes what `GroveVersion::latest()` resolves to, and the whole test suite defaults to latest. The full workspace suite passes with V4 as latest (2459 grovedb + 705 merk + the rest), and the only two failures were the version registry's own self-describing tests — `grove_version_latest_returns_v3` and `grove_versions_count` — which are updated here. That is the evidence the change is inert. Adds `grove_v4_is_behaviourally_identical_to_v3_until_a_gate_is_added`, which compares every slot and fails the moment one is bumped. That failure is the intended prompt to document the gate rather than let V4 accrete behaviour silently. Co-Authored-By: Claude Fable 5 <[email protected]> * test(version): drop the V3/V4 slot-identity assertion It pinned V4's initial state as inert, which was worth verifying once but becomes churn the moment a gate is added — and the DeleteTree read and #776 are both queued to gate on V4 next, so it would fail immediately and be deleted anyway. The evidence it provided is preserved where it belongs: the PR description records that the full workspace suite passed with V4 as latest and that only the registry's own self-describing tests changed. Co-Authored-By: Claude Fable 5 <[email protected]> --------- Co-authored-by: Claude Fable 5 <[email protected]>
…uery-offset-limit
GROVE_V3 is live in production, so the fixed accounting moves to GROVE_V4: v4 sets element.path_query_push = 1 (offset-consumed empty subqueries no longer eat a limit slot) while v3 keeps the legacy behavior. The legacy regression test now pins the real GROVE_V3 instead of a hand-mutated version struct. Co-Authored-By: Claude Fable 5 <[email protected]>
…uery-offset-limit
…ispatch
Move the implementation into element/path_query_push/{mod.rs,v0.rs,v1.rs}:
v0 freezes the legacy limit/offset accounting for GROVE_V1..GROVE_V3, v1
(GROVE_V4+) carries the issue #690 fix as its own implementation, and the
ElementQueryExtensions::path_query_push trait method becomes the match
dispatcher, replacing the inline version check. Also document the gate in
the GROVE_V4 module doc.
Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
Version-matrix tests run the subquery_path (all result types + offset skip), raw-tree, non-tree, and empty-subquery_path branches under both GROVE_V3 (v0) and GROVE_V4 (v1) and assert identical results, proving the implementations agree everywhere outside the gated issue #690 accounting; plus a dispatcher unknown-version rejection test. Co-Authored-By: Claude Fable 5 <[email protected]>
Summary
Fixes #690: when an
offsetconsumed all of a subquery's inner results, the outerlimitwas decremented anyway, so e.g.limit=2, offset=1over a range of trees could return a single element when the first inner match was skipped rather than absent.The fix only charges the outer limit for an empty subquery result when nothing was skipped (
skipped == 0): true no-match emptiness still consumes a limit slot (preserving thedecrease_limit_on_range_with_no_sub_elementsDoS protection — offset is finite, so skips can't make empty-tree walks free), while offset-consumed emptiness leaves the limit untouched.Versioning
Gated to GROVE_V4 (
element.path_query_push: 1); GROVE_V1..GROVE_V3 are live in production and keep the legacy accounting bug-for-bug. Structured as the standard versioned dispatch (same shape asadd_element_on_transactionandterminal_keys):grovedb/src/element/path_query_push/mod.rs— module doc + version tablegrovedb/src/element/path_query_push/v0.rs— frozen legacy implementation (GROVE_V1..V3)grovedb/src/element/path_query_push/v1.rs— fixed accounting (GROVE_V4+)ElementQueryExtensions::path_query_pushinelement/query.rsis the match dispatcher (unknown versions →UnknownVersionMismatch)The two implementations differ only in the
skipped == 0guard on the empty-subquery limit decrement; the delta is marked inline at the change site in both files. The gate is also documented in theGROVE_V4module doc.path_query_pushis trusted-read only: proof generation rejects non-zero offsets and never calls it, so no proof surface changes.Tests
GROVE_V3still returns the old (short) result setpath_query_pushbranch (subquery_path with all three result types, subquery_path offset skip, raw tree push, non-tree push, empty-subquery_path error) under both GROVE_V3 and GROVE_V4, asserting identical results — proving v0 and v1 agree everywhere outside the gated accountingVerification
cargo test -p grovedb— full suite green (2800+ tests)cargo test -p grovedb subquery_offset_consumed/across_path_query_push_versionscargo clippy -- -D warnings,cargo fmt --check🤖 Generated with Claude Code