Repository navigation
[core] Cache BTree index readers across table scans - #1497
Draft
XiaoHongbo-Hope wants to merge 1 commit into
Draft
XiaoHongbo-Hope wants to merge 1 commit into
XiaoHongbo-Hope wants to merge 1 commit into
Conversation
XiaoHongbo-Hope
marked this pull request as draft
November 22, 2026 15:17
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
Reuse opened BTree global-index readers across scans of the same
Tablehandle. Repeated queries currently create a new global-index scanner and reopen the same immutable BTree shards, including their footer and index block.btree-index.cache-sizesetting; clear idle readers when that setting changes.Why this change
In the 16-clip descriptor investigation, repeated global-index planning remained the main warm-read cost. The existing BTree reader cache lives only as long as one scanner, so a second query on the same table opens the same index shards again. A BTree reader also owns a FileRead created from the current token-bound storage operator. Reusing the entire reader after a data-token refresh could therefore keep using old credentials; the credential generation changes only when RESTTokenFileIO rebuilds its underlying FileIO, and lets the cache drop or reject readers from the previous generation. A valid token is checked locally without a new token request on every query.
Lance keeps a cache of opened indices and index data in its Dataset Session. Repeated scans of one Dataset can reuse that cache; callers can also share a Session across Dataset handles. The paired benchmark reused one Lance Dataset for its cold and immediate warm queries. This is relevant precedent for cross-query index reuse, but the benchmark did not isolate Lance's cache contribution. This PR uses a narrower lifetime: one Paimon
Tablehandle and its copies, not a process-wide cache shared by unrelated tables.A five-seed follow-up measured 113 ms median warm query time with the old wheel, 45 ms with an experimental wheel containing a table-level reader cache, and 57 ms for indexed Lance. Both Rust wheels included the #1475 ordered-prefetch patch. The experimental wheel also included #1478 OR batching, an additional redundant-index-evaluation shortcut, and an index-manifest cache. Therefore, 113 to 45 ms is a combined-patch result, not an isolated speedup for this PR.
That benchmark used descriptor-only
TableRead.read(..., ordered=True, parallelism=64); it did not read BLOB payload. The direct Rust API defaults toordered=False, and the separate unordered full-BLOB benchmark is not evidence for this reader cache. This PR extracts only cross-scan BTree reader reuse, with a byte budget and credential-generation invalidation; it does not include the OR, manifest, or ordered-read changes. This exact PR has not yet been benchmarked on the ECS workload, so it does not claim a measured win over Lance.Validation
cargo test -p paimon --lib test_btree_reader_cache -- --nocapturecargo test -p paimon --lib test_initial_token_skips_first_request_and_still_refreshes -- --nocapturecargo fmt --all --checkgit diff --checkAssumptions and limits
This is an AI-assisted change. It assumes index-file paths identify immutable contents. The 128 MiB reader budget uses an estimate of retained heap bytes; opaque storage-reader allocations are not measured. A query already using a reader when credentials expire has the same in-flight behavior as before this PR.