Skip to content

feat: compute min/max zone statistics for fixed-size binary columns - #11387

Merged
wjones127 merged 4 commits into
lance-format:mainfrom
LuQQiu:lu/fixed-size-binary-zone-stats
Dec 2, 2026
Merged

wjones127 merged 4 commits into
lance-format:mainfrom
LuQQiu:lu/fixed-size-binary-zone-stats

Conversation

@LuQQiu

@LuQQiu LuQQiu commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Zone statistics had no min/max for FixedSizeBinary columns (UUIDs, hashes): find_min_max_indices in arrow-stats fell through to the unsupported arm, so every zone stored null bounds.

Consequences before this change:

  • A zone map on a fixed-size binary column could only prune IS NULL; equality, range and IN filters kept every zone that held a non-null value.
  • A zone map write seed for such a column was always rejected by the index build ("holds comparable values without bounds"), although seeds are requested by default for FixedSizeBinary(n) with n > 8. The write paid for a seed that could not be used.

Change

Add a FixedSizeBinary arm that computes min/max with unsigned lexicographic byte order, the same order used for Binary and the order of the FixedSizeBinary arm of arrow_ord::ord::make_comparator. Running min/max accumulation and merging already compare through ArrowScalar and needed no change.

No other type is added. View types are stored as their base types, and dictionary columns would need a key-aware pass.

Tests

  • arrow-stats: bounds with nulls, all-null input, multi-batch update and merge (width 16).
  • Zone map: per-zone bounds on a FixedSizeBinary(16) column and pruning for equality, range, IN and IS NULL.
  • Dataset: a seed written for a FixedSizeBinary(16) column is reused by the index build and filters answer like an unindexed scan.

🤖 Generated with Claude Code

@github-actions github-actions Bot added A-index Vector index, linalg, tokenizer enhancement New feature or request labels Nov 23, 2026
The statistics module moved from the arrow-stats crate to
lance-arrow/src/stats.rs; the FixedSizeBinary arm and its tests follow it.

Co-Authored-By: Claude <[email protected]>
@LuQQiu
LuQQiu marked this pull request as ready for review November 30, 2026 22:19

@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 Nov 30, 2026

@wjones127 wjones127 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.

Thanks, this is a nice small fix: zone maps on UUID/hash columns now get real bounds, and their seeds stop being thrown away. The order matches Binary and make_comparator.

One thing blocks: FSB extrema are now persisted, so their byte order is part of the on-disk contract and should be pinned in arrow_ordering.rs (inline).

Non-blocking:

  • I'd prefer to drop the dataset-level seed test in favor of unit coverage (inline).
  • thought: FSB zone maps written before this change have null bounds on zones that hold values, like legacy Decimal zones. The handling is type-agnostic, so old indices should fall back conservatively, but the comment here only names Decimal. Maybe mention FixedSizeBinary too? Fine as a follow-up.

LargeBinary => find_extrema_bytes!(array, as_binary::<i64>),
// Unsigned lexicographic byte order, matching the FixedSizeBinary arm
// of `arrow_ord::ord::make_comparator`.
FixedSizeBinary(_) => find_extrema_bytes!(array, as_fixed_size_binary),

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.

issue(blocking): Could we add a FixedSizeBinary fixture to rust/lance/tests/arrow_ordering.rs?

Zone maps now persist extrema for this type, and pruning depends on three comparators agreeing: the extrema scan here, ArrowScalar (merge), and ScalarValue::partial_cmp (zone eval). That file is where we pin those orders so that an Arrow or DataFusion upgrade that changes one fails loudly instead of silently mis-pruning old indices. fixtures() runs every path for each type listed, so this is just a new fixture modeled on binary():

fn binary() -> Fixture {
build(
"Binary",
vec![
("[]", vec![]),
("[00]", vec![0x00]),
("[00 00]", vec![0x00, 0x00]),
("[00 01]", vec![0x00, 0x01]),
("[01]", vec![0x01]),
("[7F]", vec![0x7F]),
("[80]", vec![0x80]),
("[80] (duplicate)", vec![0x80]),
("[FF]", vec![0xFF]),
("[FF 00]", vec![0xFF, 0x00]),
],
1,
|bytes| bytes.clone(),
no_nan,
|values| Arc::new(BinaryArray::from_iter(values)),
|array, row| array.as_binary::<i32>().value(row).to_vec(),
None,
)
}

To pin unsigned order, include values that straddle 0x7F/0x80 and 0xFF in the leading byte (e.g. [00 00], [00 01], [7F FF], [80 00], a duplicate, [FF 00], [FF FF]). The zone map unit test only uses bytes below 0x80.

Done when fixtures() includes a FixedSizeBinary fixture with high-bit leading bytes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 6551a98. arrow_ordering.rs has a fixed_size_binary() fixture (width 2) registered in fixtures(): [00 00], [00 01], [7F FF], [80 00], a duplicate [80 00], [FF 00], [FF FF], plus a null, so the leading byte straddles 0x7F/0x80 and reaches 0xFF.

/// rebuilt zone map reuses them instead of rejecting them as unbounded and
/// scanning, and the index answers filters like an unindexed scan.
#[tokio::test]
async fn test_fixed_size_binary_seed_is_reused() {

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.

suggestion: Can we drop the dataset-level test here? I'd like to avoid adding tests that build an index on a dataset when we can, since they're several orders of magnitude slower than unit tests.

Seeds and training both compute bounds through ZoneMapProcessor -> StatisticsAccumulator, and validate_seed only rejected FSB seeds because their bounds were null. So the stats.rs tests plus test_fixed_size_binary_zonemap_prunes already cover the fix (and the arrow_ordering.rs fixture above pins the order). If we want explicit seed coverage, a ZoneMapSeedWriter + validate_seed unit test next to test_seed_v1_round_trip_and_validation would pin it much more cheaply.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 6551a98. The dataset-level test is removed, and test_seed_fixed_size_binary_bounds_are_reusable sits next to test_seed_v1_round_trip_and_validation: it checks that validate_seed accepts a FixedSizeBinary seed and that each record's bounds are non-null and in unsigned byte order, using values with high-bit leading bytes.

Add a FixedSizeBinary fixture to the Arrow ordering tests with leading
bytes that straddle 0x7F/0x80 and reach 0xFF, since zone maps now persist
extrema for this type. Replace the dataset-level seed test with a seed
writer and validation unit test, and name FixedSizeBinary in the comment
on legacy zones that have values but no extrema.

Co-Authored-By: Claude <[email protected]>
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Dec 1, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Dec 1, 2026
…inary-zone-stats

# Conflicts:
#	rust/lance-index/src/scalar/zonemap.rs
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Dec 1, 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.

No blocking issues found. The focused fixed-size binary seed-validation and pruning tests pass locally.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Dec 1, 2026
@LuQQiu

LuQQiu commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

@wjones127 thanks for the review. Both inline points are addressed in 6551a98. I also took the non-blocking thought: the comment on legacy zones with values but no extrema in zonemap.rs now names FixedSizeBinary alongside Decimal (the check under it is type-agnostic). The branch is merged with main again.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. and removed K-approved Latest Gatekeeper recommendation permits acceptance. labels Dec 1, 2026

@wjones127 wjones127 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.

Nice! Thanks for responding to my feedback.

@wjones127
wjones127 merged commit d66ff69 into lance-format:main Dec 2, 2026
44 checks passed
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 enhancement New feature or request K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants