Repository navigation
perf(index): skip nested value traversal when collecting zone map statistics - #9874
Conversation
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]>
84d629c to
0153c11
Compare
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]>
|
Addressed the test-coverage note: the end-to-end test now proves which update path ran.
Both cases still check Verified on the same rig: |
|
Ideally we'd be able to keep stats for both levels (parent and child). If we have an 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)? |
There was a problem hiding this comment.
✅ 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.
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,StructandMap, ZoneMap currently records whether the whole row is null, not min/max values inside the collection.For example:
NULL[][NULL, 1][NaN, 1.0]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?
ZoneMapProcessornow uses two paths: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:
null_count.minandmaxremain typed NULLs: value bounds are unavailable.nan_countremains 0; NaNs inside collections are not counted.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
StatisticsAccumulatorused 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.
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:
Seed collection alone
This measures only the seed writer's batch-observation step, not the full append or final serialization:
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 branchlu/ent2893-zonemap-seed-bench-tooland is not included in this PR.Tests
IS NULLresults and does not prune using unavailable value bounds.IS NULLandIS NOT NULLresults match an index-disabled scan.Verification
Reported local checks:
Python
test_vector_and_zonemap_on_fsl_columnwas not run locally.🤖 Generated with Claude Code