Skip to content

perf(index): skip nested value traversal when collecting zone map statistics - #9874

Merged
LuQQiu merged 2 commits into
lance-format:mainfrom
LuQQiu:lu/zonemap-nested-null-only
Oct 12, 2026
Merged

LuQQiu merged 2 commits into
lance-format:mainfrom
LuQQiu:lu/zonemap-nested-null-only

Conversation

@LuQQiu

@LuQQiu LuQQiu commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

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 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, 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, 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, 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:

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

@github-actions github-actions Bot added A-index Vector index, linalg, tokenizer performance labels Oct 10, 2026
Zone maps keep only parent-level null counts for nested columns (List,
LargeList, FixedSizeList, Struct, Map) and store typed-null bounds, yet
ZoneMapProcessor still ran the shared arrow-stats accumulator over every
chunk, which slices each list row and computes element statistics that
were then discarded. Measured on the ENT-2893 matrix this cost 3.1 us/row
for FixedSizeList<f32, 768> and 1.3 us/row for List<i32> on the write
seed path, and the same work during index training.

The processor now picks a null-only accumulator for nested types that
reads the parent validity buffer and nothing else. Index training,
incremental update and write seeds all go through this processor, so one
change covers the three paths. Statistics, seed and index formats, zone
boundaries, null position tracking, the nested nan_count of 0 and the
shared accumulator's behavior for other consumers are unchanged; the
accumulator's type-mismatch error is preserved on the new path.

Tests cover parent-only null counting across list, large list, fixed size
list, struct and map arrays with empty lists and null or NaN children,
the type guard, nested seed round trips across batch and zone boundaries,
list index training, and an end-to-end seed harvest on a vector column.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@LuQQiu
LuQQiu force-pushed the lu/zonemap-nested-null-only branch from 84d629c to 0153c11 Compare October 10, 2026 17:29
The end-to-end nested seed test only checked query results, so a silent
fallback to the column scan would still pass. Count DataFusion plan_run
events during optimize_indices: a seed harvest executes no plan, the
fallback does. Run the scenario with seeds (expect zero plan runs) and
without seeds as the control (expect at least one).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@LuQQiu

LuQQiu commented Oct 10, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the test-coverage note: the end-to-end test now proves which update path ran.

optimize_indices is wrapped in a thread-local tracing subscriber that counts plan_run events on lance::execution (emitted when a DataFusion plan finishes). A seed harvest reads the data-file global buffers and never executes a plan; the fallback rebuilds the index through load_training_data, which does. The test is now an rstest with two cases on the same data:

  • seeds(true): asserts 0 plan runs, i.e. the update was served from the seeds.
  • scan(false): the control, asserts ≥ 1 plan run, so a silent fallback in the seeds case cannot pass unnoticed.

Both cases still check IS NULL / IS NOT NULL against a scan and that the merged index's IS NULL result is exact. No production code changed in this commit.

Verified on the same rig: cargo test -p lance --lib zone_map (both cases, run 3× for flakiness), cargo clippy --all --tests --benches -- -D warnings, cargo fmt --check.

@LuQQiu
LuQQiu marked this pull request as ready for review October 10, 2026 17:47

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 10, 2026
@LuQQiu LuQQiu changed the title perf(index): skip child statistics for nested zone map columns perf(index): skip nested value traversal when collecting zone map statistics Oct 10, 2026
@westonpace

Copy link
Copy Markdown
Member

Ideally we'd be able to keep stats for both levels (parent and child). If we have an Address struct with Street, Zip, and City children I think we would want to be able to accelerate Address IS NULL, Street IS NULL, Zip IS NULL, and City IS NULL.

It sounds like we were not able to do this before? And also are not able to do this with the fix?

Do you think it is possible to have a fix that would allow us to have counts at both levels? Or am I misunderstanding (maybe we do have the capability but we were also double counting)?

@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 12, 2026

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Gate recommendation: approve.

On the parent/child statistics question, a ZoneMap on Address records only Address nulls, both before and after this change. It never persisted counts for Street, Zip, or City. Parent nulls and list-item nulls were already separate; the shared accumulator did not collect per-child Struct statistics.

The existing scalar-index training and query paths can target Address.Street, Address.Zip, and Address.City independently; scalar children retain full statistics. Automatically serving every child predicate from one parent ZoneMap would require a separate per-child statistics and query design.

Skipping discarded list-child statistics remains a useful performance fix while preserving the stored contract. The updated seed/scan coverage checks the harvest path explicitly and verifies exact null results across both fragments.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 12, 2026
@LuQQiu
LuQQiu merged commit 04feace into lance-format:main Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-index Vector index, linalg, tokenizer K-approved Latest Gatekeeper recommendation permits acceptance. performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants