Skip to content

recentIterateRange: narrow DB query to exclude file range#20362

Merged
sudeepdino008 merged 2 commits intomainfrom
sudeep/rir_db_files
Apr 7, 2026
Merged

recentIterateRange: narrow DB query to exclude file range#20362
sudeepdino008 merged 2 commits intomainfrom
sudeep/rir_db_files

Conversation

@sudeepdino008
Copy link
Copy Markdown
Member

Closes #20358

  • Adjust recentIterateRange DB query bounds to skip txNums already covered by frozen files
  • For ascending: raise the inclusive lower bound (from) to filesEndTxNum
  • For descending: raise the exclusive lower bound (to) to filesEndTxNum-1 (so value > filesEndTxNum-1value >= filesEndTxNum)
  • Add TestInvertedIndex_IdxRange_SkipsFileRange: builds files for 2 steps, prunes DB entries in the file range, verifies IdxRange still returns correct results for both asc and desc

Test plan

  • New test TestInvertedIndex_IdxRange_SkipsFileRange passes
  • All existing TestInvIndex* / TestInvertedIndex* tests pass
  • make lint clean
  • make erigon integration builds

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the inverted index DB-range iteration logic to avoid querying MDBX for txNum ranges that are already covered by frozen snapshot files, addressing #20358 (prunable data should not be required for correctness/iteration).

Changes:

  • Narrow recentIterateRange’s RangeDupSort bounds so DB iteration excludes the frozen-file-covered txNum prefix for both ascending and descending iteration.
  • Add a regression test that builds frozen files, prunes DB entries in the file-covered range, and verifies IdxRange still returns correct results for asc/desc.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
db/state/inverted_index.go Adjusts DB iterator bounds in recentIterateRange to skip the frozen-file-covered txNum range.
db/state/inverted_index_test.go Adds TestInvertedIndex_IdxRange_SkipsFileRange to validate IdxRange behavior after pruning DB entries covered by files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread db/state/inverted_index.go
Comment thread db/state/inverted_index_test.go
@sudeepdino008 sudeepdino008 added this pull request to the merge queue Apr 7, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 7, 2026
@sudeepdino008 sudeepdino008 added this pull request to the merge queue Apr 7, 2026
Merged via the queue into main with commit ab035f3 Apr 7, 2026
35 checks passed
@sudeepdino008 sudeepdino008 deleted the sudeep/rir_db_files branch April 7, 2026 14:06
github-merge-queue Bot pushed a commit that referenced this pull request Apr 11, 2026
…st (#20444)

Fixes #20355

- Skip DB entries whose step falls within the file range (`step.ToTxNum
< files.EndTxNum()`) in both the initial DB cursor push and the advance
loop — they are never loaded into the heap
- Matches the "don't query DB for data in files" pattern from #20360,
#20361, #20362
- Add `TestDomain_IteratePrefix_PrefersFilesOverDB` that simulates
partial lexicographic prune and verifies file values win

Follow-up: #20474 applies the same fix to
`DomainLatestIterFile.initCursorMDBX()` and `advanceInFiles()`

## Test plan
- [x] New test passes with fix, fails without it
- [x] `make lint` clean
- [x] `make erigon integration` builds
sudeepdino008 added a commit that referenced this pull request Apr 13, 2026
Closes #20358

- Adjust `recentIterateRange` DB query bounds to skip txNums already
covered by frozen files
- For ascending: raise the inclusive lower bound (`from`) to
`filesEndTxNum`
- For descending: raise the exclusive lower bound (`to`) to
`filesEndTxNum-1` (so `value > filesEndTxNum-1` ≡ `value >=
filesEndTxNum`)
- Add `TestInvertedIndex_IdxRange_SkipsFileRange`: builds files for 2
steps, prunes DB entries in the file range, verifies IdxRange still
returns correct results for both asc and desc

## Test plan
- [x] New test `TestInvertedIndex_IdxRange_SkipsFileRange` passes
- [x] All existing `TestInvIndex*` / `TestInvertedIndex*` tests pass
- [x] `make lint` clean
- [x] `make erigon integration` builds
sudeepdino008 added a commit that referenced this pull request Apr 13, 2026
Closes #20358

- Adjust `recentIterateRange` DB query bounds to skip txNums already
covered by frozen files
- For ascending: raise the inclusive lower bound (`from`) to
`filesEndTxNum`
- For descending: raise the exclusive lower bound (`to`) to
`filesEndTxNum-1` (so `value > filesEndTxNum-1` ≡ `value >=
filesEndTxNum`)
- Add `TestInvertedIndex_IdxRange_SkipsFileRange`: builds files for 2
steps, prunes DB entries in the file range, verifies IdxRange still
returns correct results for both asc and desc

## Test plan
- [x] New test `TestInvertedIndex_IdxRange_SkipsFileRange` passes
- [x] All existing `TestInvIndex*` / `TestInvertedIndex*` tests pass
- [x] `make lint` clean
- [x] `make erigon integration` builds
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.

recentIterateRange (inverted index): DB query reads data within file range (prunable data)

3 participants