Skip to content

Sample mostly-null arrays and price indices in sparse scheme selectors - #12263

Open
lwwmanning wants to merge 2 commits into
developfrom
wm/fix-sparse-scheme-selectors
Open

lwwmanning wants to merge 2 commits into
developfrom
wm/fix-sparse-scheme-selectors

Conversation

@lwwmanning

@lwwmanning lwwmanning commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Sparse scheme selectors on develop count values rather than bytes for <= 90% null integers (ignoring narrowed patch-index and validity costs), skip cascading float patch values, size 65,536-row string indices as u32 without a sampling context or fixed-table amortization, and score > 90% null integer and float arrays without child compression so dense Pco beats Sparse even when Sparse is much smaller.

This change prices <= 90% null integer estimates and all-null sample fallbacks using exact element, narrowed index, and validity bytes (sparse_byte_ratio), samples > 90% null integer and float arrays on the shared compression sample while preserving the null-fill branch and full-array index width, cascades both patch values and indices on float NullDominatedSparseScheme with child exclusions, honors explicit null fills in Sparse::encode, and fixes string NullDominatedSparseScheme index sizing, sampling context, and fixed-table amortization.

Behaviour change: Sparse::encode now uses the null-fill layout for an explicit Some(Scalar::null(..)) fill whenever the array contains at least one null, rather than only above 90% null (for example, changing the layout written by the compat fixture mixed_null_and_values).

On the golden snapshots, compact__float_mostly_null shrinks from 7,837 B to 6,427 B, compact__int_mostly_null shrinks from 3,086 B to 1,661 B, regular__float_mostly_null shrinks from 8,609 B to 8,504 B, and string_fsst_structured shrinks by 1,106 B in both regular and OnPair modes.

Related to #12266. Folds #12300.

Authored with AI assistance.

@lwwmanning lwwmanning added the changelog/fix A bug fix label Nov 27, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-30T00:24:03.400365Z 027498b New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

devin-ai-integration[bot]

This comment was marked as resolved.

@vortex-roborev-bot

vortex-roborev-bot Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

roborev: Combined Review (b8490f0)

Verdict: No issues found.


Reviewers: claude-code | Synthesis: claude-code, 0s | Total: 1m49s, cost partial ~$0.80

vortex-roborev-bot[bot]

This comment was marked as resolved.

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

I checked this head against #12300. Git reports conflicts in both integer/sparse.rs and float/sparse.rs. When combining them, please preserve the float patch-values child at slot 0 and the index exclusions at slot 1 from this PR, and keep #12300’s shared-sample comparison and all-null-sample fallback. The patch-values compression test here and the all-null-sample selection tests there cover different ways the combined selector could regress.

— Codex (OpenAI)

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Noted — once #12300 lands (or when combining whichever merges second), we'll keep this PR's float patch-values child at slot 0, slot-1 index exclusions, and patch-values compression test alongside #12300's shared-sample comparison, all-null-sample fallback, and selection tests.

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

I also checked the compact snapshots across #12258, #12262, this PR and #12300. The float fixture has pairwise conflicts involving all four branches, and #12258 and #12300 also conflict on the integer fixture. Once the selector changes are combined, please regenerate the affected snapshots from the combined encoder. Each checked-in size reflects a different set of candidates.

— Codex (OpenAI)

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Understood — once any of #12258, #12262, or #12300 lands ahead of this PR, we'll regenerate the affected golden snapshots with cargo test -p vortex-btrblocks --all-features --test golden against the combined encoder rather than hand-merging snapshot diffs.

@lwwmanning lwwmanning left a comment

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.

Review by Gemini 4 Carbon on behalf of @lwwmanning.

The string::NullDominatedSparseScheme fixes (len.saturating_sub(1) index width, with_sampling(), FSST/OnPair fixed-table amortization), the child-0 patch_values + child-1 patch_indices cascade in float::NullDominatedSparseScheme, and the byte-accurate elem_bytes + idx_width + patch_validity pricing for <= 90% null integer::SparseScheme are all the right changes.

However, this PR conflicts directly with #12300 on vortex-btrblocks/src/schemes/float/sparse.rs and vortex-btrblocks/src/schemes/integer/sparse.rs, and neither PR works cleanly on its own:

  • In #12263 alone, > 90% null integer and float arrays are scored with the un-cascaded closed-form ratio uncompressed_bytes / (value_count * (elem_bytes + idx_width)). Because Pco (#12266) estimates on compressed samples, un-cascaded Sparse underestimates its ratio whenever patch values or indices compress well—losing to dense Pco on golden__compact__float_mostly_null (7,837 B) and leaving golden__compact__int_mostly_null at 3,086 B instead of 1,661 B.
  • Conversely, #12300 alone samples > 90% null arrays via estimate_with_sampling, but lacks #12263's child-0 patch_values cascade on floats (leaving patch_values uncompressed at 7,545 B, which is 1,116 B worse than dense Pco once #12258 lands) and lacks #12263's byte-accurate pricing on <= 90% null integers and ZeroBytes samples.

Please fold #12300 into #12263 (and close #12300) so the sparse selector changes land as one coherent unit.

Remediation Plan

  1. Bring #12300's sample estimation + explicit null-fill Sparse::encode into #12263:
    • Cherry-pick #12300's changes to encodings/sparse/src/lib.rs (SparseData::encode respecting explicit Some(Scalar::null(..)) + collect_null_fill_indices) and vortex-compressor/src/compressor/mod.rs (CascadingCompressor::estimate_with_sampling).
    • Keep #12263's vortex-btrblocks/src/schemes/string/sparse.rs and #12263's 2-child (values=0, indices=1) cascade + descendant_exclusions in vortex-btrblocks/src/schemes/float/sparse.rs, passing Some(Scalar::null(data.array().dtype().clone())) to Sparse::encode in float::NullDominatedSparseScheme::encode.
  2. Unify null_dominated_sparse_estimate and byte-accurate closed-form pricing in vortex-btrblocks/src/schemes/mod.rs and integer/sparse.rs:
    • Extract a shared helper sparse_byte_ratio(len: usize, elem_bytes: usize, has_nulls: bool, patch_count: usize, patch_has_validity: bool) -> EstimateVerdict in vortex-btrblocks/src/schemes/mod.rs that computes uncompressed_bytes / compressed_bytes using idx_width = PType::min_unsigned_ptype_for_value(len.saturating_sub(1) as u64).byte_width() and returns EstimateVerdict::Skip when compressed_bytes == 0 || compressed_bytes >= uncompressed_bytes.
    • In null_dominated_sparse_estimate (vortex-btrblocks/src/schemes/mod.rs), use EstimateScore::ZeroBytes => Ok(sparse_byte_ratio(len, elem_bytes, true, value_count, false)) instead of len / value_count when all valid rows miss the sample.
    • Account for full-array index narrowing on > 65,536-row arrays during sample estimation: sample.data has ~1,024 rows so encode narrows sampled patch_indices to u16 (2 B) even when full_len > 65,536 narrows full patch_indices to u32 (4 B). Adjust the sampled estimate for (full_idx_width - sample_idx_width) * sample_patch_count (or price patch_indices at full_len's index PType when compress_ctx.is_sample()) so test_float_sparse_prices_indices_against_uncompressed_bytes (100,000 f32 rows) still prefers FloatDict/ALP over Sparse.
    • Fix the sample-vs-full fill-value invariant in vortex-btrblocks/src/schemes/integer/sparse.rs: when null_dominated_sparse_estimate samples a > 90% null integer array whose sampled slice happens to have sample_null_count <= sample_most_frequent_count, ensure sample estimation still encodes with Scalar::null fill so it prices the same layout that full compression writes.
    • In integer::SparseScheme::expected_compression_ratio (<= 90% null branch), combine #12300's stats.null_count() > most_frequent_count null-fill check (patch_count = value_count, patch_has_validity = false) with sparse_byte_ratio (instead of #12300's len / patch_count).
  3. Regenerate golden snapshots & keep total added tests <= 20:
    • Regenerate golden__compact__int_mostly_null.snap (~1,661 B) and golden__compact__float_mostly_null.snap (~6,427 B with cascaded patch_values + patch_indices), and keep combined added test cases across encodings/sparse and vortex-btrblocks <= 20.

Price <= 90% null integer estimates and all-null sample fallbacks by exact element, narrowed index, and validity bytes, sample > 90% null integer and float arrays on the shared compression sample while preserving null-fill layout and full-array index widths, cascade float patch values with child exclusions, honor explicit null fills in SparseData::encode, and fix string sparse index width, sampling context, and fixed-table amortization.

Co-Authored-By: Antigravity <noreply@google.com>
Signed-off-by: Will Manning <will@willmanning.io>
@lwwmanning
lwwmanning force-pushed the wm/fix-sparse-scheme-selectors branch from 7924d1d to 027498b Compare November 30, 2026 00:21
@lwwmanning lwwmanning changed the title Price patch indices and fix cascading in sparse scheme selectors Sample mostly-null arrays and price indices in sparse scheme selectors Nov 30, 2026
devin-ai-integration[bot]

This comment was marked as resolved.

@lwwmanning lwwmanning left a comment

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.

Posted by Claude Opus 5.5 on Will's behalf.

I checked 027498b against #12300's last head. The fold is complete. The null-fill Sparse::encode with the !mask.all_true() guard and u64 indices is here. So are the sampled estimate with the ZeroBytes fallback and all of #12300's tests, and the snapshots match the description.

  1. test_integer_sparse_prices_index_bytes_so_bitpacking_wins_on_u8 uses crate::schemes::integer::BITPACKING_V1, which #11905 deletes. The files do not overlap, so Git shows no conflict, and whichever PR lands second will not compile. Using BitPackingScheme once #11905 lands avoids that.
  2. NullDominatedSparseSampleScheme::encode copies float::NullDominatedSparseScheme::encode except for the index cast. A shared helper that takes a minimum index PType would remove the copy. The wrapper's expected_compression_ratio and compress are unimplemented!, so please keep it private and say in its doc comment that it must never be registered. The forced null fill matters only for the integer scheme, because the float encode already always uses one.
  3. Sparse::encode is public, and it now uses the null-fill layout for an explicit null fill at any null fraction. Please name this as a behaviour change in the description, as #12300 did. It changes, for example, the layout that the compat fixture mixed_null_and_values writes.

…eme in test

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Addressed all three points in b8490f0ae and the PR description:

  1. Replaced BITPACKING_V1 in test_integer_sparse_prices_index_bytes_so_bitpacking_wins_on_u8 with BitPackingScheme::default() via a LazyLock, so it stays compatible once Retire blocked BitPacked (fastlanes.bitpacked.v2) #11905 removes BITPACKING_V1.
  2. Extracted encode_null_dominated_sparse(scheme, array, min_idx_ptype, exec_ctx) in vortex-btrblocks/src/schemes/mod.rs shared by float::NullDominatedSparseScheme::encode and NullDominatedSparseSampleScheme::encode, kept NullDominatedSparseSampleScheme private, and documented that it must never be registered and that the forced null fill is needed for integer::SparseScheme.
  3. Called out the public Sparse::encode null-fill behaviour change (including its effect on mixed_null_and_values) explicitly in the PR description.

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

I checked the combined Sparse and Pco selection changes after #12300 closed. The sample and full encode both use an explicit null fill, float patch values cascade at child 0 and indices at child 1, and the explicit-null path retains the u64 boundary fix. The compressed-patch-values and all-null-sample regression fixtures are both present. This addresses my earlier integration comment.

— Codex (OpenAI)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants