Skip to content

fix(query): preserve subquery limit after offset skips#730

Open
QuantumExplorer wants to merge 1 commit into
developfrom
codex/fix-690-subquery-offset-limit
Open

fix(query): preserve subquery limit after offset skips#730
QuantumExplorer wants to merge 1 commit into
developfrom
codex/fix-690-subquery-offset-limit

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented May 20, 2026

Copy link
Copy Markdown
Member

Summary

  • only decrement the outer limit for an empty subquery result when no rows were skipped by offset
  • add forward and reverse regressions where offset consumes the first inner result before limit accounting begins

Fixes #690.

Verification

  • cargo test -p grovedb subquery_offset_consumed_empty --lib
  • cargo test -p grovedb test_get_range_query_with_unique_subquery --lib
  • cargo test -p grovedb query_tests --lib

Summary by CodeRabbit

  • Bug Fixes

    • Fixed query limit behavior when subqueries return empty results, improving consistency across protocol versions.
  • Tests

    • Added test coverage for query offset and limit interactions under different protocol configurations.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fdb3ec7e-bf3e-452f-9848-d192ababb0ca

📥 Commits

Reviewing files that changed from the base of the PR and between a2129a9 and 5687dce.

📒 Files selected for processing (3)
  • grovedb-version/src/version/v3.rs
  • grovedb/src/element/query.rs
  • grovedb/src/tests/query_tests.rs

📝 Walkthrough

Walkthrough

Protocol version v3 now enables path_query_push v1, which implements versioned behavior for subquery offset/limit handling. The query logic conditionally gates limit decrement on version and skipped count to fix offset-consumed-empty subquery behavior; three new tests validate both v1 and legacy v0 modes.

Changes

Subquery Offset-Consumed-Empty Limit Fix

Layer / File(s) Summary
Version contract and query logic versioning
grovedb-version/src/version/v3.rs, grovedb/src/element/query.rs
GROVE_V3 bumps path_query_push to version 1. Query logic reads this version, validates with check_grovedb_v0_or_v1_with_cost!, and gates the limit-decrement behavior in empty-subquery branches on path_query_push_version == 0 || skipped == 0.
Forward, reverse, and legacy version test coverage
grovedb/src/tests/query_tests.rs
Three tests validate offset-consumed-empty behavior: forward and reverse direction with v1 expect two returned elements and skipped = 1 without limit decrease; legacy v0 test expects one element with the original decrement behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A subquery offset once played a trick,
Consuming the limit, oh how quick!
Now versioned in v3, the fix rings true—
Skip-aware decrement, a behavior made new! 🌿

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: preserving subquery limit after offset skips, which directly addresses the core issue in the PR.
Linked Issues check ✅ Passed The PR implements the exact fix suggested in issue #690: only decrement the outer limit when no rows were skipped by offset, with new forward/reverse tests.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing issue #690: version bump for path_query_push, conditional limit decrement logic, and regression tests.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-690-subquery-offset-limit

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented May 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.43%. Comparing base (60f2968) to head (5687dce).
⚠️ Report is 3 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #730      +/-   ##
===========================================
+ Coverage    91.42%   91.43%   +0.01%     
===========================================
  Files          236      236              
  Lines        67053    67116      +63     
===========================================
+ Hits         61305    61370      +65     
+ Misses        5748     5746       -2     
Components Coverage Δ
grovedb-core 88.95% <100.00%> (+<0.01%) ⬆️
merk 92.26% <ø> (ø)
storage 86.36% <ø> (ø)
commitment-tree 96.43% <ø> (ø)
mmr 96.79% <ø> (+0.03%) ⬆️
bulk-append-tree 89.39% <ø> (+0.13%) ⬆️
element 97.38% <ø> (+0.01%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@QuantumExplorer QuantumExplorer changed the title Preserve subquery limit after offset skips fix(query): preserve subquery limit after offset skips May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[audit][medium] Subquery offset can consume limit without returning a result

1 participant