Repository navigation
perf(index): record zone map seed null positions as runs - #9860
Conversation
Track null positions in zone map write seeds by scanning the validity buffer for runs and inserting ranges instead of one bitmap insert per null row, and run-optimize the bitmap before serializing it, so all-null and clustered-null columns cost almost nothing to seed. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Benchmark: before vs after this changeSame harness and rig as #9792 (
How to read it:
Raw results: |
`ZoneMapSeedWriter::record_null_runs` treated a chunk with no validity buffer as all null, which inverts Arrow's rule and the behavior of the per-row loop it replaced. The branch is unreachable from `observe_batch` today because the caller only enters on a positive physical null count, but the method is callable on its own, so return early instead and cover it in the null-runs test. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
Review fix pushed as a follow-up commit (no history rewrite).
No behavior change for any path reachable today; the format and the measurements above are unaffected. |
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The author’s follow-up corrects the helper’s no-validity-buffer case and adds direct regression coverage. The caller already excludes that case, so the measured write path is unchanged.
The null-heavy write optimization remains worthwhile and preserves exact positions across slices and zone boundaries, with the existing seed format and reader compatibility. No blocking issues found.
zhangyue19921010
left a comment
There was a problem hiding this comment.
LGTM 👍 Verified locally.
- A randomized property test covering unaligned slices, cross-container runs, and various
rows_per_zonevalues showed the seed's null bitmap read back exactly as written. - Performance is as expected: for all-null columns,
observe_batchdropped from 11.2 to 1.1 ns/row and the seed from ~518 KiB to ~6.6 KiB; columns with no nulls are essentially unchanged.
One minor, non-blocking observation: when nulls are scattered one row at a time (e.g. every other row), insert_range doesn't reduce the number of calls and costs more per call than insert, so it was slightly slower in my local run (8.56 → 11.80 ns/row). That pattern is uncommon, so this can be a follow-up.
|
Thank you @zhangyue19921010 for reviewing the PR! |
…tistics (#9874) Stacked on #9860. Until that PR merges, GitHub also shows its two commits; this PR's own change is the top commit `84d629c46`. Part of ENT-2893. ## Why this change? For nested columns such as `List`, `FixedSizeList`, `Struct` and `Map`, ZoneMap currently records **whether the whole row is null**, not min/max values inside the collection. For example: | Row value | Counts as a null row? | |---|---| | `NULL` | Yes | | `[]` | No | | `[NULL, 1]` | No | | `[NaN, 1.0]` | No | However, the old implementation still visited the elements inside lists to calculate statistics that ZoneMap then threw away. A vector with 768 elements could therefore require inspecting those elements just to record that the vector itself was not null. This unnecessary work made writing seeds very expensive for list and vector columns. ## What changes? `ZoneMapProcessor` now uses two paths: - **Scalar columns:** keep the existing min/max, null-count and NaN-count calculation. - **Nested columns:** count null rows from the parent validity buffer without visiting child values. The same processor is used when building a ZoneMap index, updating it by scanning new data, and collecting write seeds. All three paths avoid the unnecessary child traversal. For nested columns, the output stays the same: - Exact parent-level `null_count`. - `min` and `max` remain typed NULLs: value bounds are unavailable. - `nan_count` remains 0; NaNs inside collections are not counted. - Exact null-row positions are still recorded separately. **This PR does not enable seeds by default, add nested min/max support, change zone sizes, or change seed/index formats.** It also does not change the shared `StatisticsAccumulator` used by other consumers. ## Performance: before vs. after These measurements compare this PR against #9860's head, so they isolate the benefit of skipping child statistics. “Seeds on” means appending to a table whose ZoneMap index has `use_seeds = true`. ### Total append time Lower is better. Each cell is the median of five runs. Null cases have 10% random **parent** nulls. | Column | Rows appended | Seeds OFF, after change | Seeds ON, before change | Seeds ON, after change | Extra append time from seeds, after change | |---|---:|---:|---:|---:|---:| | FixedSizeList: 768 Float32 values per row | 1M | 1,468 ms | 4,574 ms | 1,506 ms | +2.6% | | List<Int32> | 4M | 209 ms | 5,602 ms | 211 ms | +0.9% | | Struct | 4M | 398 ms | 398 ms | 400 ms | +0.5% | | FixedSizeList: 768 Float32 values, 10% null rows | 1M | 1,694 ms | 4,552 ms | 1,614 ms | Within measurement noise | | List<Int32>, 10% null rows | 4M | 275 ms | 5,129 ms | 309 ms | +12.3% | The last column compares seeds ON vs. OFF **in the after-change build**. The lower time for the null-vector case is measurement variation, not evidence that seeds speed up writing. The main improvement is in List and FixedSizeList: - **1M vectors:** append with seeds falls from about **4.6 seconds to 1.5 seconds**. - **4M lists:** append with seeds falls from about **5.6 seconds to 0.21 seconds**. - **Struct:** essentially unchanged; its old statistics path was already cheap. - **Random nulls still have a cost:** exact null-position tracking and bitmap serialization remain. For the nullable list case, that is about **34 ms extra per 4M rows**. ### Seed collection alone This measures only the seed writer's batch-observation step, not the full append or final serialization: | Column | Before | After | |---|---:|---:| | FixedSizeList<Float32, 768>, no null rows | 3,073 ns/row | 0.4 ns/row | | List<Int32>, no null rows | 1,277 ns/row | 0.1 ns/row | | FixedSizeList<Float32, 768>, 10% null rows | 2,810 ns/row | 4.0 ns/row | | List<Int32>, 10% null rows | 1,170 ns/row | 3.7 ns/row | **The optimization reduces CPU work, not seed size.** All 70 seed outputs from the benchmark were byte-identical before and after, checked by SHA-256 and decoded-statistics comparisons. Measurement setup: before = `ef18a0aa8`, after = `84d629c46`; EPYC 9V65 machine with NVMe RAID0; `release-with-debug`; fresh process per case/mode/repetition; identical inputs; five repetitions. The one-off harness is on fork branch `lu/ent2893-zonemap-seed-bench-tool` and is not included in this PR. ## Tests - **Parent nulls vs. child nulls:** List, LargeList, FixedSizeList, Struct and Map count only null rows; empty collections and null/NaN children do not inflate the count. - **Validation and reset:** reject mismatched input types, accumulate across chunks, and reset between zones. - **Seed round trip:** batching and slicing across zone boundaries produce identical seed bytes, zone counts and exact null positions. - **Index training:** a List column returns exact `IS NULL` results and does not prune using unavailable value bounds. - **Append + index update:** a FixedSizeList column is indexed, appended to, and optimized; `IS NULL` and `IS NOT NULL` results match an index-disabled scan. ## Verification Reported local checks: ```text cargo fmt --all -- --check cargo clippy --all --tests --benches -- -D warnings cargo test -p lance-index --lib zonemap cargo test -p lance --lib zone_map ``` Python `test_vector_and_zonemap_on_fsl_column` was not run locally. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5.1 <[email protected]>
Why this matters
A newly added column may start with every value NULL, then be populated later by a refresh or feature-computation job. Partially populated columns can also contain long consecutive runs of NULLs. The main target of this PR is the all-null initial state: collecting write seeds should be cheap when the column does not contain real values yet.
Previously, the seed writer inserted every null row position individually, and the serialized bitmap could remain large even when every row was NULL. For 1M all-null Int64 rows, the complete seed buffer was about 518 KiB. This PR reduces it to 6.6 KiB while preserving the exact null positions. In the measured 4M-row append, time drops from 77.7 ms to 35.7 ms (54% less).
What this changes
ZoneMap write seeds record column statistics and the exact row positions of nulls while data is written. This PR makes collecting and storing consecutive null positions cheaper. It keeps the null bitmap and the existing zone design (8,192 rows in the measurements).
RoaringBitmap::optimize()so consecutive positions can use compact run containers.For example, 900 consecutive nulls previously required 900 individual inserts. They now require one range insert; serialization can represent that range compactly.
Before/after measurements
Both versions have seeds enabled. Append time measures writing 4M rows, including data-file writes and seed collection. Seed size is the complete serialized seed buffer per 1M rows, including column statistics and the null bitmap—not just the bitmap.
Medians of five repetitions per case, identical generated inputs, 8192 rows per zone, and 1M rows per data file. Measurements used an AMD EPYC 9V65 machine with local NVMe storage and
release-with-debug. Small timing differences should not be treated as guaranteed speedups.Compatibility and validation
Benchmark harness: zone_map_seeds.rs.