Repository navigation
Conversation
…e index RowIdIndex::new walked every row id of every fragment whose sequence is not a plain Range, and get_row_id_index builds the index for the whole dataset, so one point lookup paid for the whole table. Keep one entry per fragment with per-segment bounds instead, and resolve on lookup. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: Peng Wang <[email protected]>
pengw0048
marked this pull request as draft
August 18, 2026 22:29
…eement Build a row-id to position map for U64Segment::Array, the one encoding whose position() walks the segment. Resolve get_many through get so the two APIs return the same address for a row id that two fragments claim. Charge the sequences, deletion vectors and position maps the index retains through its Arcs, so a cache that weighs the entry bounds what the entry keeps alive. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: Peng Wang <[email protected]>
…rlap new() checks again that no row id is live in two fragments, so the integrity boundary stays where it was. Two fragments can only claim an id where their row id ranges intersect, so the check walks the intersecting pairs and only the ids inside each intersection. Drops verify(), which no caller reached. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: Peng Wang <[email protected]>
A prefix maximum cannot stop a backward walk once one fragment covers a wide range, so a miss walked every fragment whose start sits below the id: 4.46 us per miss at 16,384 fragments against 2 ns before this branch. Descend a max-end tree instead, which holds at 233 ns as the fragment count grows. Fragments whose ranges interleave produce a quadratic number of intersecting pairs, and walking their ids cost 1.61 s at 2,048 fragments. Estimate that work first and skip it above a budget; validate() runs it on demand. Fill the array position table on first use so a table nobody looks up costs nothing, which returns deep_size_of to what it was before the table existed. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Signed-off-by: Peng Wang <[email protected]>
pengw0048
marked this pull request as ready for review
August 19, 2026 17:01
…cheap Keep the merged map for the shapes it serves well, and answer from a per-fragment probe otherwise. `new` reads each segment's bounds instead of every row id, and builds the merged map when that build is cheap or once probes have paid for it.
pengw0048
marked this pull request as draft
August 19, 2026 20:14
pengw0048
marked this pull request as ready for review
August 20, 2026 14:45
Three review findings, all of them about the lazy build: - The representation is now chosen by `new` and never changes, so a cached entry cannot grow after its weight is fixed. The lazy upgrade was solving a case that does not exist: wherever the merged map reads faster it is also the one `new` builds, and where it does not, probing wins on both build and lookup. - An unsorted `Array` segment gets a sorted lookup table, built with the entry and charged with it, so a probe binary-searches instead of scanning. `build_chunk_from_pairs` sorts its pairs for the same reason, which also makes a merged chunk searchable. - A probe visits every candidate instead of stopping at the first hit, so a row id live in two fragments resolves the same way through `get` and `get_many`, and trips an assertion in a debug build.
…agments The probe path visits every candidate fragment, so the duplicate check is free; it now returns the same corrupt-index error the merged build raises, instead of a debug assertion. get and get_many are fallible and every production caller propagates the error. Co-Authored-By: Claude Opus 5 <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Contributor
There was a problem hiding this comment.
✅ Gate recommendation: approve.
This revision documents the fallible lookup contract with explicit error sections and leaves the verified probe behavior unchanged: both lookup APIs still fail closed when a requested stable ID is live in multiple fragments.
Please mark this PR with the breaking-change label.
Xuanwo
pushed a commit
that referenced
this pull request
Aug 28, 2026
### Problem `Bitmap::count_ones` walks the bitmap one byte at a time. A row id sequence asks for that count on the hot paths: - `U64Segment::len` counts the whole bitmap of a `RangeWithBitmap` segment, and `RowIdIndex::new` calls `len` on every segment of every fragment. - `U64Segment::position` counts the bits up to the wanted offset, once per lookup. On a 15.43B row / 17,601 fragment dataset whose sequences hold 3.36 GB of bitmaps, that byte-at-a-time count is the whole cost of opening the index. ### Change Count a `u64` at a time, and keep the byte loop for the trailing bytes and for the two partial bytes at the ends of a slice. ### Measurement Taking one row id from that dataset, release build, 96-core Linux x86-64. The index here is the per-fragment index from #8624, which calls `len` per segment: | | before | after | |---|---|---| | first `_take_rows`, 1 row id | 1.92 s | 1.41 s | | second call, same dataset object | 1.10 s | 0.61 s | `cargo test -p lance-table --lib rowids`: 98 passed.
Xuanwo
added a commit
that referenced
this pull request
Sep 1, 2026
) Supersedes #8624 by @pengw0048, which no longer merges cleanly into `main`. This PR carries that branch's commits unchanged (every review finding on #8624 was addressed there, and the gate recommendation was approve), merges current `main`, and resolves the one conflict: `main` extracted `TakeStream::resolve_row_addrs` while #8624 made `RowIdIndex::get` fallible, so the helper now takes a fallible closure and both resolution paths propagate the lookup error. ### Problem `RowIdIndex::new` reads every row id of every fragment whose sequence is not a plain `Range`. `decompose_sequence` has a constant-time path for `U64Segment::Range` without deletions; every other encoding, and every fragment that carries a deletion file, materializes one `(row_id, address)` pair per row, sorts them, and re-encodes two segments. `get_row_id_index` builds the index for the whole dataset, so a lookup of one row id pays for the whole table. A delete puts a table on that path and keeps it there. While the deletion files exist, the build checks the deletion vector row by row. After a compaction materializes those deletions, the ids inside each fragment are no longer contiguous, so the build decodes and re-encodes every row id instead. The cost repeats: the index weighs about as much as the sequences it copies, so on a large table it does not fit `DEFAULT_METADATA_CACHE_SIZE`, and the next lookup builds it again. ### Change `new` picks one of two representations and never changes it. - The **merged map** is what it builds today, and it stays the default: a `Range`-only sequence decomposes in constant time, and a small table is cheap to read whatever its encoding. - A **probe** answers from one entry per fragment — the `Arc<RowIdSequence>`, the deletion vector, and each segment's row id range plus its physical start offset. `new` reads those bounds instead of every row id. A lookup binary- searches the fragments by their lowest row id, descends a max-`end` heap so a fragment out of reach of the id costs nothing, and asks the covering segment for `position`. `new` probes only when both hold: the merged build would read more than `MERGE_ROWS_BUDGET` row ids, and no more than `MAX_PROBE_DEPTH` fragments cover any one id. So wherever the merged map reads faster, it is also the one `new` builds. An unsorted `U64Segment::Array` gets a sorted lookup table, built with the entry and charged with it, because its own `position` scans. `build_chunk_from_pairs` sorts its pairs for the same reason, which makes a merged chunk searchable too. ### The integrity boundary `new` no longer materializes ids on the probe path, so it cannot compare id sets the way `merge_overlapping_chunks` does. The check moved to the lookup, where it is free: a probe already visits every candidate fragment rather than stopping at the first hit, and a second live match returns the same corrupt-index error the merged build raises. `get` and `get_many` are fallible for this, and every production caller propagates the error. `validate_stable_row_ids` remains the complete offline check. Checking at construction instead is possible but not cheap on the shape this PR is for: proving overlapping id sets disjoint without reading them means intersecting the sequences bit by bit, on the order of 10^10 word operations at depth 46 over that table's id space, paid again on every process that opens the dataset. The fallible lookup keeps the boundary without that cost. ### Microbenchmarks (from #8624) Release build, 96-core Linux x86-64. `build` is `RowIdIndex::new`; the lookup columns are 100,000 random live ids. | shape | build | `get` | `get_many` | | --- | --- | --- | --- | | 1,000 fragments, 20M sparse ids, 2 fragments per id | **0.22 ms** vs 485 ms | **236 ns** vs 23 µs | **175 ns** vs 24 µs | | 4,000 fragments, 4M ids, every fragment covers every id | 104.7 ms vs 101.5 ms | 14 ns vs 13 ns | 21 ns vs 18 ns | | 1,000 fragments, 20M contiguous ids, disjoint | 0.23 ms vs 0.19 ms | 36 ns vs 36 ns | 16 ns vs 14 ns | | 1 fragment, 2M descending ids (unsorted `Array`) | 7.6 ms vs 8.9 ms | **203 ns** vs 2 ms | **55 ns** vs 2 ms | Row 1 is the shape a compacted table has, and the merged map is slower to build *and* slower to read there: merging the overlap produces one wide sparse segment whose `position` counts bits up to the offset. ### On a real table Verified on a production dataset of 17,375,589,419 rows in 19,960 fragments on S3, with stable row ids and a compaction history. Both sides are release wheels built from this repository — `before` is current `main` (324cedd), `after` is this branch. `_take_rows` of one column; each "first call" is a fresh process, "second call" is the same process again. Dataset open (~69 s for this manifest) is excluded. | | before (`main`) | after (this PR) | |---|---|---| | 1 row id, first call | 88.8 s | **2.20 s** | | 1 row id, second call | 70.9 s | **1.31 s** | | 200 scattered row ids, first call | 94.3 s | **10.9 s** | | 200 scattered row ids, second call | 72.5 s | **8.63 s** | On `main` the second call pays almost the full price again: the merged index outweighs the metadata cache and is rebuilt per lookup, which is the repeating cost described above. Closes #8621 Note for maintainers: the gate review on #8624 asked for the `breaking-change` label (`RowIdIndex::get`/`get_many` became fallible); I cannot set labels on this repository. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Peng Wang <[email protected]> Co-authored-by: Peng Wang <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Xuanwo <[email protected]>
Member
|
replaced by #8883 |
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.
Problem
RowIdIndex::newreads every row id of every fragment whose sequence is not aplain
Range.decompose_sequencehas a constant-time path forU64Segment::Rangewithout deletions; every other encoding, and every fragmentthat carries a deletion file, materializes one
(row_id, address)pair per row,sorts them, and re-encodes two segments.
get_row_id_indexbuilds the index forthe whole dataset, so a lookup of one row id pays for the whole table.
A delete puts a table on that path and keeps it there. While the deletion files
exist, the build checks the deletion vector row by row. After a compaction
materializes those deletions, the ids inside each fragment are no longer
contiguous, so the build decodes and re-encodes every row id instead.
The cost repeats: the index weighs about as much as the sequences it copies, so
on a large table it does not fit
DEFAULT_METADATA_CACHE_SIZE, and the nextlookup builds it again.
Change
newpicks one of two representations and never changes it.Range-only sequence decomposes in constant time, and a small table is cheapto read whatever its encoding.
Arc<RowIdSequence>,the deletion vector, and each segment's row id range plus its physical start
offset.
newreads those bounds instead of every row id. A lookup binary-searches the fragments by their lowest row id, descends a max-
endheap so afragment out of reach of the id costs nothing, and asks the covering segment
for
position.newprobes only when both hold: the merged build would read more thanMERGE_ROWS_BUDGETrow ids, and no more thanMAX_PROBE_DEPTHfragments coverany one id. So wherever the merged map reads faster, it is also the one
newbuilds.
An unsorted
U64Segment::Arraygets a sorted lookup table, built with the entryand charged with it, because its own
positionscans.build_chunk_from_pairssorts its pairs for the same reason, which makes a merged chunk searchable too.
Measurements
Release build, 96-core Linux x86-64.
buildisRowIdIndex::new; the lookupcolumns are 100,000 random live ids.
getget_manyArray)Row 1 is the shape a compacted table has, and the merged map is slower to build
and slower to read there: merging the overlap produces one wide sparse segment
whose
positioncounts bits up to the offset.Row 2 is where the merged map earns its build, and
newbuilds it, so bothcolumns match.
Row 4 is the finding about unsorted arrays, in both representations.
On a real table
A dataset of 15,431,187,521 rows in 17,601 fragments, holding 3.36 GB of row id
sequences. Half of the segments are
RangeWithBitmaporRangeWithHoles, whichis what a compaction leaves behind once it materializes a long run of deletes.
46 fragments cover the most crowded row id.
_take_rowsof one column, in afresh process:
(Measured on the earlier revision of this PR; the representation it picks for
this table is the same one, and #8642 takes the 1.10 s to 0.61 s.)
The integrity boundary
newno longer materializes ids on the probe path, so it cannot compare id setsthe way
merge_overlapping_chunksdoes. The check moved to the lookup, where itis free: a probe already visits every candidate fragment rather than stopping at
the first hit, and a second live match returns the same corrupt-index error the
merged build raises.
getandget_manyare fallible for this, and everyproduction caller propagates the error.
validate_stable_row_idsremains thecomplete offline check.
Checking at construction instead is possible but not cheap on the shape this PR
is for: proving overlapping id sets disjoint without reading them means
intersecting the sequences bit by bit, on the order of 10^10 word operations at
depth 46 over that table's id space, paid again on every process that opens the
dataset. The fallible lookup keeps the boundary without that cost.
Closes #8621